public void draw() { glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, vbo); glVertexAttribPointer(0, 3, GL_FLOAT, false, Vertex.SIZE * 4, 0); glDrawArrays(GL_TRIANGLES, 0, size); glDisableVertexAttribArray(0); }
private static void render() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); camera.applyTranslations(); glUseProgram(currentShaderProgram); glLight( GL_LIGHT0, GL_POSITION, BufferTools.asFlippedFloatBuffer(camera.x(), camera.y(), camera.z(), 1)); glDrawArrays(GL_TRIANGLES, 0, model.faces.size() * 3); }
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(); }
private void renderGL() { glClear(GL_COLOR_BUFFER_BIT); // draw slices if (!syncGLtoCL) { glWaitSync(glFenceFromCLEvent, 0, 0); glDeleteSync(glFenceFromCLEvent); glFenceFromCLEvent = NULL; int errcode = clReleaseEvent(clEvent); clEvent = NULL; checkCLError(errcode); } glBindTexture(GL_TEXTURE_2D, glTexture); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); }
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); }
/** @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); }
public void draw() { if (ibo > 0) glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_BYTE, 0); else glDrawArrays(GL_TRIANGLES, 0, count); }