public void render(int mode) {
    if (vertices != null) glEnableClientState(GL_VERTEX_ARRAY);
    if (normals != null) glEnableClientState(GL_NORMAL_ARRAY);
    if (colors != null) glEnableClientState(GL_COLOR_ARRAY);
    if (texCoords != null) glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    bindVBO();

    if (vertices != null) glVertexPointer(sizeV, GL_FLOAT, stride * 4, offV * 4);
    if (normals != null) glNormalPointer(GL_FLOAT, stride * 4, offN * 4);
    if (colors != null) glColorPointer(sizeC, GL_FLOAT, stride * 4, offC * 4);
    if (texCoords != null) glTexCoordPointer(sizeT, GL_FLOAT, stride * 4, offT * 4);

    if (indices != null) {
      bindIND();
      glDrawRangeElements(mode, 0, indices.length, indices.length, GL_UNSIGNED_INT, 0);
    } else {
      glDrawArrays(mode, 0, vertices.length);
    }

    if (vertices != null) glDisableClientState(GL_VERTEX_ARRAY);
    if (normals != null) glDisableClientState(GL_NORMAL_ARRAY);
    if (colors != null) glDisableClientState(GL_COLOR_ARRAY);
    if (texCoords != null) glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  }
Exemplo n.º 2
0
  public void render() {
    if (((ViewerContainer3D) v.getContainer()).getPbuffer() != currentPbuffer) {
      for (int i = 0; i < vbo.length; i++) {
        vbo[i] = -1;
        selectedVbo[i] = -1;
      }
      currentPbuffer = ((ViewerContainer3D) v.getContainer()).getPbuffer();
    }

    for (int i = 0; i < tubes.length; i++) {
      if (hidden[i]) continue;

      int vbo;
      if (!selected[i]) {
        if (this.vbo[i] == -1) {
          Color c = colors[i];
          GL15.glDeleteBuffers(this.vbo[i]);
          this.vbo[i] = createTubeVbo(i, colors[i]);
        }
        vbo = this.vbo[i];
      } else {
        if (this.selectedVbo[i] == -1) {
          Color c = selectedColors[i];
          GL15.glDeleteBuffers(this.selectedVbo[i]);
          this.selectedVbo[i] = createTubeVbo(i, selectedColors[i]);
        }
        vbo = this.selectedVbo[i];
      }

      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);

      GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
      GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
      GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);

      GL11.glColorMaterial(GL11.GL_FRONT_AND_BACK, GL11.GL_AMBIENT_AND_DIFFUSE);
      GL11.glEnable(GL11.GL_COLOR_MATERIAL);

      GL11.glColorPointer(3, GL11.GL_FLOAT, vertexStride, colorPointer);
      GL11.glVertexPointer(3, GL11.GL_FLOAT, vertexStride, vertexPointer);
      GL11.glNormalPointer(GL11.GL_FLOAT, vertexStride, normalPointer);

      GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, totalNumVerts[i]);

      GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
      GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);
      GL11.glDisableClientState(GL11.GL_NORMAL_ARRAY);
      GL11.glDisable(GL11.GL_COLOR_MATERIAL);

      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    }
  }
Exemplo n.º 3
0
  public static void main(String[] args) {
    Window window = new Window(1024, 768, false);

    window.setTitle("Hello OpenGL!");

    window.setVisible(true);

    int vertexCount = 3;
    int floatSize = 4;

    FloatBuffer buffer = createFloatBuffer(vertexCount * 3 + vertexCount * 4);
    buffer.put(0).put(0.5f).put(0);
    buffer.put(1).put(0).put(0).put(1);

    buffer.put(-0.5f).put(-0.5f).put(0);
    buffer.put(0).put(1).put(0).put(1);

    buffer.put(0.5f).put(-0.5f).put(0);
    buffer.put(0).put(0).put(1).put(1);
    buffer.flip();

    /*IntBuffer indices = ByteBuffer.allocateDirect(3 * 4).order(ByteOrder.nativeOrder()).asIntBuffer();
    indices.put(0).put(1).put(2);
    indices.flip();*/

    int vbo = glGenBuffers();

    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);

    while (!window.isCloseRequested()) {
      window.pollEvents();

      glEnableClientState(GL_VERTEX_ARRAY);
      glEnableClientState(GL_COLOR_ARRAY);

      glBindBuffer(GL_ARRAY_BUFFER, vbo);

      glVertexPointer(3, GL_FLOAT, 7 * floatSize, 0);
      glColorPointer(4, GL_FLOAT, 7 * floatSize, 3 * floatSize);

      glDrawArrays(GL_TRIANGLES, 0, 3);

      window.swap();
      window.sleep(16);
    }

    window.destroy();
  }
Exemplo n.º 4
0
  /** R_DrawParticles */
  void R_DrawParticles() {

    if (gl_ext_pointparameters.value != 0.0f && qglPointParameterfEXT) {

      // GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
      GL11.glVertexPointer(3, 0, particle_t.vertexArray);
      GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
      GL11.glColorPointer(4, true, 0, particle_t.getColorAsByteBuffer());

      GL11.glDepthMask(false);
      GL11.glEnable(GL11.GL_BLEND);
      GL11.glDisable(GL11.GL_TEXTURE_2D);
      GL11.glPointSize(gl_particle_size.value);

      GL11.glDrawArrays(GL11.GL_POINTS, 0, r_newrefdef.num_particles);

      GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);
      // GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);

      GL11.glDisable(GL11.GL_BLEND);
      GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
      GL11.glDepthMask(true);
      GL11.glEnable(GL11.GL_TEXTURE_2D);

    } else {
      GL_DrawParticles(r_newrefdef.num_particles);
    }
  }
Exemplo n.º 5
0
  public void render() {
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glNormalPointer(0, normals);
    glVertexPointer(3, 0, vertices);
    glTexCoordPointer(2, 0, texCoords);
    // glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    glDrawElements(GL_TRIANGLES, indices);

    // glDrawElements(GL_TRIANGLES, indices);
    // indices.flip();
    glDisableClientState(GL_NORMAL_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);
  }
Exemplo n.º 6
0
  private void renderVbo(int id) {
    if (lock.tryLock()) {
      try {
        if (vertexBuffers[id] <= 0 || disposed) {
          return;
        }

        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
        glEnableClientState(GL_COLOR_ARRAY);
        glEnableClientState(GL_NORMAL_ARRAY);

        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, idxBuffers[id]);
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertexBuffers[id]);

        glVertexPointer(SIZE_VERTEX, GL11.GL_FLOAT, STRIDE, OFFSET_VERTEX);

        GL13.glClientActiveTexture(GL13.GL_TEXTURE0);
        glTexCoordPointer(SIZE_TEX0, GL11.GL_FLOAT, STRIDE, OFFSET_TEX_0);

        GL13.glClientActiveTexture(GL13.GL_TEXTURE1);
        glTexCoordPointer(SIZE_TEX1, GL11.GL_FLOAT, STRIDE, OFFSET_TEX_1);

        glColorPointer(SIZE_COLOR * 4, GL11.GL_UNSIGNED_BYTE, STRIDE, OFFSET_COLOR);

        glNormalPointer(GL11.GL_FLOAT, STRIDE, OFFSET_NORMAL);

        GL11.glDrawElements(GL11.GL_TRIANGLES, vertexCount[id], GL11.GL_UNSIGNED_INT, 0);

        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);

        glDisableClientState(GL_NORMAL_ARRAY);
        glDisableClientState(GL_COLOR_ARRAY);
        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
        glDisableClientState(GL_VERTEX_ARRAY);

      } finally {
        lock.unlock();
      }
    }
  }
Exemplo n.º 7
0
  @Override
  public void render() {

    GL11.glPushMatrix();

    GL11.glTranslatef(transform[0], transform[1], 0.0f);
    GL11.glRotatef((float) Math.toDegrees(transform[2]), 0, 0, 1);

    GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
    ARBBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, verticesBufferID);
    GL11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0);

    GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);
    ARBBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, normalsBufferID);
    GL11.glNormalPointer(GL11.GL_FLOAT, 0, 0);

    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, triangleCount * 3);

    GL11.glPopMatrix();
  }
Exemplo n.º 8
0
 private static void render() {
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glLoadIdentity();
   cam.applyTranslations();
   glUseProgram(shaderProgram);
   glLight(GL_LIGHT0, GL_POSITION, asFloatBuffer(cam.x(), cam.y(), cam.z(), 1));
   glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
   glVertexPointer(3, GL_FLOAT, 0, 0L);
   glBindBuffer(GL_ARRAY_BUFFER, vboNormalHandle);
   glNormalPointer(GL_FLOAT, 0, 0L);
   glEnableClientState(GL_VERTEX_ARRAY);
   glEnableClientState(GL_NORMAL_ARRAY);
   glColor3f(0.4f, 0.27f, 0.17f);
   glMaterialf(GL_FRONT, GL_SHININESS, 10f);
   glDrawArrays(GL_TRIANGLES, 0, model.faces.size() * 3);
   glDisableClientState(GL_VERTEX_ARRAY);
   glDisableClientState(GL_NORMAL_ARRAY);
   glBindBuffer(GL_ARRAY_BUFFER, 0);
   glUseProgram(0);
 }
Exemplo n.º 9
0
 public void draw() {
   if (vertexVBO != null) {
     GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
   }
   if (colourVBO != null) {
     GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
   }
   if (textureVBO != null) {
     GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
   }
   GL11.glDrawArrays(GL11.GL_QUADS, 0, getNumElements());
   if (vertexVBO != null) {
     GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
   }
   if (colourVBO != null) {
     GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);
   }
   if (textureVBO != null) {
     GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
   }
 }
Exemplo n.º 10
0
  /** @Info fait le rendu du vbo */
  public void renderVBO() {
    glBindBuffer(GL_ARRAY_BUFFER, vboID);

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);

    glVertexPointer(3, GL_FLOAT, (3 + 4) * FLOAT_SIZE, 0);
    glColorPointer(4, GL_FLOAT, (3 + 4) * FLOAT_SIZE, 3 * FLOAT_SIZE);

    // x,y,z,r,g,b,a,nx,ny,nz
    // glVertexPointer(3, GL_FLOAT, (3 + 4 + 3) * FLOAT_SIZE, 0);
    // glColorPointer(4, GL_FLOAT, (3 + 4 + 3) * FLOAT_SIZE, 3 * FLOAT_SIZE);
    // glNormalPointer(4, GL_FLOAT, (3 + 4 + 3) * FLOAT_SIZE, (3 + 4) * FLOAT_SIZE);

    //		glVertexAttribPointer(0,3,GL_FLOAT,false,7 * 4,0);
    //		glVertexAttribPointer(1,4,GL_FLOAT,false,7 * 4,12);

    glDrawArrays(GL_QUADS, 0, bufferSize);

    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);
  }
 private static void setUpVBOs() {
   int[] vbos;
   try {
     model = OBJLoader.loadModel(new File(MODEL_LOCATION));
     vbos = OBJLoader.createVBO(model);
     vboVertexHandle = vbos[0];
     vboNormalHandle = vbos[1];
   } catch (FileNotFoundException e) {
     e.printStackTrace();
     cleanUp();
     System.exit(1);
   } catch (IOException e) {
     e.printStackTrace();
     cleanUp();
     System.exit(1);
   }
   glEnableClientState(GL_VERTEX_ARRAY);
   glEnableClientState(GL_NORMAL_ARRAY);
   glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
   glVertexPointer(3, GL_FLOAT, 0, 0L);
   glBindBuffer(GL_ARRAY_BUFFER, vboNormalHandle);
   glNormalPointer(GL_FLOAT, 0, 0L);
 }
Exemplo n.º 12
0
  @Override
  public void setup() {
    // Viewport
    glViewport(0, 0, width, height);

    // Enable something else
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    // Enable three-dee
    glEnable(GL_DEPTH_TEST);

    // Enable textures
    glEnable(GL_TEXTURE_2D);

    // Blue sky
    glClearColor(93f / 255f, 155f / 255f, 217 / 255f, 0.0f);

    // Enable culling
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);

    // Allow alpha texturing (Does not enable it yet)
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    // Enable vertex buffer objects
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    TextureLib.loadDebugTexture();

    camera.setup();

    simpleSetup();
  }
Exemplo n.º 13
0
  public void renderBuffer(OpenGLBuffer buffer, ITextureObject texture) {
    GL13.glActiveTexture(GL13.GL_TEXTURE0 + 0);
    texture.bind();
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableVertexAttribArray(0);
    glEnableVertexAttribArray(1);
    glEnableVertexAttribArray(2);

    glBindBuffer(GL_ARRAY_BUFFER, buffer.getVboID());
    glVertexAttribPointer(0, 3, GL_FLOAT, false, Vertex.SIZE_IN_FLOATS * 4, 0);
    glVertexAttribPointer(1, 2, GL_FLOAT, false, Vertex.SIZE_IN_FLOATS * 4, 12);
    glVertexAttribPointer(2, 3, GL_FLOAT, false, Vertex.SIZE_IN_FLOATS * 4, 20);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer.getIboID());
    glDrawElements(GL_TRIANGLES, buffer.getIndicesCount(), GL_UNSIGNED_INT, 0);

    glDisableVertexAttribArray(2);
    glDisableVertexAttribArray(1);
    glDisableVertexAttribArray(0);
  }
Exemplo n.º 14
0
  /** Draws the data set up in this tessellator and resets the state to prepare for new drawing. */
  public int draw() {
    if (!isDrawing) {
      throw new IllegalStateException("Not tesselating!");
    }

    isDrawing = false;

    if (vertexCount > 0) {
      intBuffer.clear();
      intBuffer.put(rawBuffer, 0, rawBufferIndex);
      byteBuffer.position(0);
      byteBuffer.limit(rawBufferIndex * 4);

      if (useVBO) {
        vboIndex = (vboIndex + 1) % vboCount;
        ARBVertexBufferObject.glBindBufferARB(
            ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, vertexBuffers.get(vboIndex));
        ARBVertexBufferObject.glBufferDataARB(
            ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB,
            byteBuffer,
            ARBVertexBufferObject.GL_STREAM_DRAW_ARB);
      }

      if (hasTexture) {
        if (useVBO) {
          GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 32, 12L);
        } else {
          floatBuffer.position(3);
          GL11.glTexCoordPointer(2, 32, floatBuffer);
        }

        GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
      }

      if (hasBrightness) {
        OpenGlHelper.setClientActiveTexture(OpenGlHelper.lightmapTexUnit);

        if (useVBO) {
          GL11.glTexCoordPointer(2, GL11.GL_SHORT, 32, 28L);
        } else {
          shortBuffer.position(14);
          GL11.glTexCoordPointer(2, 32, shortBuffer);
        }

        GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
        OpenGlHelper.setClientActiveTexture(OpenGlHelper.defaultTexUnit);
      }

      if (hasColor) {
        if (useVBO) {
          GL11.glColorPointer(4, GL11.GL_UNSIGNED_BYTE, 32, 20L);
        } else {
          byteBuffer.position(20);
          GL11.glColorPointer(4, true, 32, byteBuffer);
        }

        GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
      }

      if (hasNormals) {
        if (useVBO) {
          GL11.glNormalPointer(GL11.GL_UNSIGNED_BYTE, 32, 24L);
        } else {
          byteBuffer.position(24);
          GL11.glNormalPointer(32, byteBuffer);
        }

        GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);
      }

      if (useVBO) {
        GL11.glVertexPointer(3, GL11.GL_FLOAT, 32, 0L);
      } else {
        floatBuffer.position(0);
        GL11.glVertexPointer(3, 32, floatBuffer);
      }

      GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);

      if (drawMode == 7 && convertQuadsToTriangles) {
        GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, vertexCount);
      } else {
        GL11.glDrawArrays(drawMode, 0, vertexCount);
      }

      GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);

      if (hasTexture) {
        GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
      }

      if (hasBrightness) {
        OpenGlHelper.setClientActiveTexture(OpenGlHelper.lightmapTexUnit);
        GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
        OpenGlHelper.setClientActiveTexture(OpenGlHelper.defaultTexUnit);
      }

      if (hasColor) {
        GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);
      }

      if (hasNormals) {
        GL11.glDisableClientState(GL11.GL_NORMAL_ARRAY);
      }
    }

    int i = rawBufferIndex * 4;
    reset();
    return i;
  }
Exemplo n.º 15
0
  public int draw() {
    if (!this.isDrawing) {
      throw new IllegalStateException("Not tesselating!");
    } else {
      this.isDrawing = false;
      if (this.vertexCount > 0) {
        this.intBuffer.clear();
        this.intBuffer.put(this.rawBuffer, 0, this.rawBufferIndex);
        this.byteBuffer.position(0);
        this.byteBuffer.limit(this.rawBufferIndex * 4);
        if (this.useVBO) {
          this.vboIndex = (this.vboIndex + 1) % this.vboCount;
          ARBVertexBufferObject.glBindBufferARB(
              ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, this.vertexBuffers.get(this.vboIndex));
          ARBVertexBufferObject.glBufferDataARB(
              ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB,
              this.byteBuffer,
              ARBVertexBufferObject.GL_STREAM_DRAW_ARB);
        }

        if (this.hasTexture) {
          if (this.useVBO) {
            GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 32, 12L);
          } else {
            this.floatBuffer.position(3);
            GL11.glTexCoordPointer(2, 32, this.floatBuffer);
          }

          GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);

          // Spout Start
          if (textureOverride > 0) GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureOverride);
          // Spout End
        }

        if (this.hasBrightness) {
          OpenGlHelper.setClientActiveTexture(OpenGlHelper.lightmapEnabled);
          if (this.useVBO) {
            GL11.glTexCoordPointer(2, GL11.GL_SHORT, 32, 28L);
          } else {
            this.shortBuffer.position(14);
            GL11.glTexCoordPointer(2, 32, this.shortBuffer);
          }

          GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
          OpenGlHelper.setClientActiveTexture(OpenGlHelper.lightmapDisabled);
        }

        if (this.hasColor) {
          if (this.useVBO) {
            GL11.glColorPointer(4, GL11.GL_UNSIGNED_BYTE, 32, 20L);
          } else {
            this.byteBuffer.position(20);
            GL11.glColorPointer(4, true, 32, this.byteBuffer);
          }

          GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
        }

        if (this.hasNormals) {
          if (this.useVBO) {
            GL11.glNormalPointer(GL11.GL_UNSIGNED_BYTE, 32, 24L);
          } else {
            this.byteBuffer.position(24);
            GL11.glNormalPointer(32, this.byteBuffer);
          }

          GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);
        }

        if (this.useVBO) {
          GL11.glVertexPointer(3, GL11.GL_FLOAT, 32, 0L);
        } else {
          this.floatBuffer.position(0);
          GL11.glVertexPointer(3, 32, this.floatBuffer);
        }

        GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
        if (this.drawMode == 7 && convertQuadsToTriangles) {
          GL11.glDrawArrays(4, 0, this.vertexCount);
        } else {
          GL11.glDrawArrays(this.drawMode, 0, this.vertexCount);
        }

        GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
        if (this.hasTexture) {
          GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
        }

        if (this.hasBrightness) {
          OpenGlHelper.setClientActiveTexture(OpenGlHelper.lightmapEnabled);
          GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
          OpenGlHelper.setClientActiveTexture(OpenGlHelper.lightmapDisabled);
        }

        if (this.hasColor) {
          GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);
        }

        if (this.hasNormals) {
          GL11.glDisableClientState(GL11.GL_NORMAL_ARRAY);
        }
      }

      int var1 = this.rawBufferIndex * 4;
      this.reset();
      return var1;
    }
  }
Exemplo n.º 16
0
  public void setVertexAttrib(VertexBuffer vb, VertexBuffer idb) {
    if (vb.getBufferType() == VertexBuffer.Type.Color && !context.useVertexColor) {
      // Ignore vertex color buffer if vertex color is disabled.
      return;
    }

    int arrayType = convertArrayType(vb.getBufferType());
    if (arrayType == -1) {
      return; // unsupported
    }
    glEnableClientState(arrayType);
    context.boundAttribs[vb.getBufferType().ordinal()] = vb;

    if (vb.getBufferType() == Type.Normal) {
      // normalize if requested
      if (vb.isNormalized() && !context.normalizeEnabled) {
        glEnable(GL_NORMALIZE);
        context.normalizeEnabled = true;
      } else if (!vb.isNormalized() && context.normalizeEnabled) {
        glDisable(GL_NORMALIZE);
        context.normalizeEnabled = false;
      }
    }

    // NOTE: Use data from interleaved buffer if specified
    Buffer data = idb != null ? idb.getData() : vb.getData();
    int comps = vb.getNumComponents();
    int type = convertVertexFormat(vb.getFormat());

    data.rewind();

    switch (vb.getBufferType()) {
      case Position:
        if (!(data instanceof FloatBuffer)) {
          throw new UnsupportedOperationException();
        }

        glVertexPointer(comps, vb.getStride(), (FloatBuffer) data);
        break;
      case Normal:
        if (!(data instanceof FloatBuffer)) {
          throw new UnsupportedOperationException();
        }

        glNormalPointer(vb.getStride(), (FloatBuffer) data);
        break;
      case Color:
        if (data instanceof FloatBuffer) {
          glColorPointer(comps, vb.getStride(), (FloatBuffer) data);
        } else if (data instanceof ByteBuffer) {
          glColorPointer(comps, true, vb.getStride(), (ByteBuffer) data);
        } else {
          throw new UnsupportedOperationException();
        }
        break;
      case TexCoord:
        if (!(data instanceof FloatBuffer)) {
          throw new UnsupportedOperationException();
        }

        glTexCoordPointer(comps, vb.getStride(), (FloatBuffer) data);
        break;
      default:
        // Ignore, this is an unsupported attribute for OpenGL1.
        break;
    }
  }
  public void create() {
    boolean save = UniPrint.enabled;
    UniPrint.enabled = print;
    sizeV = vertices != null ? vertices[0].getBandwidth() : 0;
    sizeN = normals != null ? normals[0].getBandwidth() : 0;
    sizeC = colors != null ? colors[0].getBandwidth() : 0;
    sizeT = texCoords != null ? texCoords[0].getBandwidth() : 0;

    offV = 0;
    offN = sizeV;
    offC = sizeV + sizeN;
    offT = sizeV + sizeN + sizeC;

    stride = sizeV + sizeN + sizeC + sizeT;

    size =
        sizeV * (vertices != null ? vertices.length : 0)
            + sizeN * (normals != null ? normals.length : 0)
            + sizeC * (colors != null ? colors.length : 0)
            + sizeT * (texCoords != null ? texCoords.length : 0);

    vboID = createID();

    if (indices != null) {
      indID = createID();

      bindIND();
      IntBuffer indBuffer = arrayToBuffer(indices);
      attachIndexBuffer(indID, indBuffer);
    }

    UniPrint.printf(
        "VBO (id %d):\n"
            + " >> sizeV:  %d\n"
            + " >> sizeN:  %d\n"
            + " >> sizeC:  %d\n"
            + " >> sizeT:  %d\n"
            + " >> offV:   %d\n"
            + " >> offN:   %d\n"
            + " >> offC:   %d\n"
            + " >> offT:   %d\n"
            + " >> stride: %d\n"
            + " >> size:   %d\n",
        vboID, sizeV, sizeN, sizeC, sizeT, offV, offN, offC, offT, stride, size);

    FloatBuffer buffer = BufferUtils.createFloatBuffer(size);
    float[] fbuffer = new float[buffer.capacity()];

    int ind = 0;
    int iind = 0;

    for (int i = 0; i < vertices.length; i++) {
      ind = i * stride;
      iind = 0;
      UniPrint.printf("Vertex Group(%d):\n", i);
      if (vertices != null) {
        for (int v = 0; v < vertices[0].getBandwidth(); v++, iind++) {
          fbuffer[ind + iind] = vertices[i].get()[v];
          UniPrint.printf(
              "(fbuffer[%d + %d] = vertices[%d].get()[%d]) = %G\n",
              ind, iind, i, v, fbuffer[ind + iind]);
        }
      }
      if (normals != null) {
        for (int n = 0; n < normals[0].getBandwidth(); n++, iind++) {
          fbuffer[ind + iind] = normals[i].get()[n];
          UniPrint.printf(
              "(fbuffer[%d + %d] = normals[%d].get()[%d]) = %G\n",
              ind, iind, i, n, fbuffer[ind + iind]);
        }
      }
      if (colors != null) {
        for (int c = 0; c < colors[0].getBandwidth(); c++, iind++) {
          fbuffer[ind + iind] = colors[i].get()[c];
          UniPrint.printf(
              "(fbuffer[%d + %d] = colors[%d].get()[%d]) = %G\n",
              ind, iind, i, c, fbuffer[ind + iind]);
        }
      }
      if (texCoords != null) {
        for (int t = 0; t < texCoords[0].getBandwidth(); t++, iind++) {
          fbuffer[ind + iind] = texCoords[i].get()[t];
          UniPrint.printf(
              "(fbuffer[%d + %d] = texCoords[%d].get()[%d]) = %G\n",
              ind, iind, i, t, fbuffer[ind + iind]);
        }
      }
    }

    buffer.rewind();
    buffer.put(fbuffer);
    bindVBO();
    attachDrawBuffer(vboID, buffer);

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    if (vertices != null) glVertexPointer(sizeV, GL_FLOAT, stride * 4, offV * 4);
    if (normals != null) glNormalPointer(GL_FLOAT, stride * 4, offN * 4);
    if (colors != null) glColorPointer(sizeC, GL_FLOAT, stride * 4, offC * 4);
    if (texCoords != null) glTexCoordPointer(sizeT, GL_FLOAT, stride * 4, offT * 4);

    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    UniPrint.enabled = save;
  }
Exemplo n.º 18
0
  static void init(Arguments args) {
    // Load the specified config file
    Config config = new Config(args.get_value("config", "voxicity.properties"));

    String mode = args.get_value("mode", "client");

    if (mode.equals("server")) {
      // Start the server, it spawns its own thread
      // and takes over from here
      new Server(config).run();
    } else if (mode.equals("client")) {
      try {
        System.out.println("Intializing display");
        Display.setDisplayMode(new DisplayMode(1200, 720));
        Display.create();
        Display.setTitle("Voxicity");
        System.out.println("Display created");
      } catch (LWJGLException e) {
        System.out.println("Unable to open Display");
        e.printStackTrace();
        System.exit(1);
      }

      System.out.println("Setting up OpenGL states");
      GL11.glShadeModel(GL11.GL_SMOOTH);
      GL11.glEnable(GL11.GL_DEPTH_TEST);
      GL11.glEnable(GL11.GL_TEXTURE_2D);
      GL11.glEnable(GL11.GL_CULL_FACE);
      GL11.glEnable(GL11.GL_BLEND);
      GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
      GL11.glClearColor(126.0f / 255.0f, 169.0f / 255.0f, 254.0f / 255.0f, 1.0f);
      GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
      GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);

      System.out.println(
          "Number of texture units: " + GL11.glGetInteger(GL13.GL_MAX_TEXTURE_UNITS));
      System.out.println(
          "Number of image texture units: " + GL11.glGetInteger(GL20.GL_MAX_TEXTURE_IMAGE_UNITS));
      System.out.println(
          "Number of vertex texture units: "
              + GL11.glGetInteger(GL20.GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS));
      System.out.println(
          "Number of combined vertex/image texture units: "
              + GL11.glGetInteger(GL20.GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS));

      try {
        LWJGLRenderer gui_renderer = new LWJGLRenderer();
        LoginGUI login_gui = new LoginGUI();
        ThemeManager theme =
            ThemeManager.createThemeManager(Voxicity.class.getResource("/login.xml"), gui_renderer);
        GUI gui = new GUI(login_gui, gui_renderer);
        gui.applyTheme(theme);

        while (!login_gui.is_login_pressed()) {
          GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
          gui.update();
          Display.update();

          if (Display.isCloseRequested()) {
            Display.destroy();
            System.exit(0);
          }
        }

        Socket client_s = new Socket(login_gui.get_server_name(), 11000);
        Client client = new Client(config, new NetworkConnection(client_s));
        client.run();

        System.out.println("Destroying display");
        Display.destroy();
      }

      // Catch exceptions from the game init and main game-loop

      catch (LWJGLException e) {
        System.out.println(e);
        e.printStackTrace();
        System.exit(1);
      } catch (IOException e) {
        System.out.println(e);
        e.printStackTrace();
        System.exit(1);
      } catch (Exception e) {
        System.out.println(e);
        e.printStackTrace();
      }
    } else {
      System.out.println("Invalid mode: " + mode);
    }
  }
Exemplo n.º 19
0
  public int func_982_a() {
    if (!field_1488_w) {
      throw new IllegalStateException("Not tesselating!");
    }
    if (renderingChunk && subTessellators.length > 0) {
      boolean flag = false;
      for (int j = 0; j < subTessellators.length; j++) {
        int k = subTextures[j];
        if (k <= 0) {
          break;
        }
        Tessellator tessellator = subTessellators[j];
        if (tessellator.field_1488_w) {
          GL11.glBindTexture(3553, k);
          tessellator.func_982_a();
          flag = true;
        }
      }

      if (flag) {
        GL11.glBindTexture(3553, getTerrainTexture());
      }
    }
    field_1488_w = false;
    if (field_1505_h > 0) {
      field_1508_e.clear();
      field_1508_e.put(field_1506_g, 0, field_1498_o);
      field_1509_d.position(0);
      field_1509_d.limit(field_1498_o * 4);
      if (field_1487_x) {
        field_1485_z = (field_1485_z + 1) % field_1496_A;
        ARBVertexBufferObject.glBindBufferARB(34962, field_1486_y.get(field_1485_z));
        ARBVertexBufferObject.glBufferDataARB(34962, field_1509_d, 35040);
      }
      if (field_1500_m) {
        if (field_1487_x) {
          GL11.glTexCoordPointer(2, 5126, 32, 12L);
        } else {
          field_1507_f.position(3);
          GL11.glTexCoordPointer(2, 32, field_1507_f);
        }
        GL11.glEnableClientState(32888);
      }
      if (field_35838_p) {
        OpenGlHelper.func_40451_b(OpenGlHelper.field_40455_b);
        if (field_1487_x) {
          GL11.glTexCoordPointer(2, 5122, 32, 28L);
        } else {
          field_35836_g.position(14);
          GL11.glTexCoordPointer(2, 32, field_35836_g);
        }
        GL11.glEnableClientState(32888);
        OpenGlHelper.func_40451_b(OpenGlHelper.field_40457_a);
      }
      if (field_1501_l) {
        if (field_1487_x) {
          GL11.glColorPointer(4, 5121, 32, 20L);
        } else {
          field_1509_d.position(20);
          GL11.glColorPointer(4, true, 32, field_1509_d);
        }
        GL11.glEnableClientState(32886);
      }
      if (field_1499_n) {
        if (field_1487_x) {
          GL11.glNormalPointer(5121, 32, 24L);
        } else {
          field_1509_d.position(24);
          GL11.glNormalPointer(32, field_1509_d);
        }
        GL11.glEnableClientState(32885);
      }
      if (field_1487_x) {
        GL11.glVertexPointer(3, 5126, 32, 0L);
      } else {
        field_1507_f.position(0);
        GL11.glVertexPointer(3, 32, field_1507_f);
      }
      GL11.glEnableClientState(32884);
      if (field_1493_r == 7 && field_1511_b) {
        GL11.glDrawArrays(4, 0, field_1505_h);
      } else {
        GL11.glDrawArrays(field_1493_r, 0, field_1505_h);
      }
      GL11.glDisableClientState(32884);
      if (field_1500_m) {
        GL11.glDisableClientState(32888);
      }
      if (field_35838_p) {
        OpenGlHelper.func_40451_b(OpenGlHelper.field_40455_b);
        GL11.glDisableClientState(32888);
        OpenGlHelper.func_40451_b(OpenGlHelper.field_40457_a);
      }
      if (field_1501_l) {
        GL11.glDisableClientState(32886);
      }
      if (field_1499_n) {
        GL11.glDisableClientState(32885);
      }
    }
    int i = field_1498_o * 4;
    func_985_d();
    return i;
  }