org.lwjgl.opengl.GL30 Java Examples
The following examples show how to use
org.lwjgl.opengl.GL30.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CurveRenderState.java From opsu with GNU General Public License v3.0 | 6 votes |
/** * Reads the first row of the slider gradient texture and upload it as * a 1D texture to OpenGL if it hasn't already been done. */ public void initGradient() { if (gradientTexture == 0) { Image slider = GameImage.SLIDER_GRADIENT.getImage().getScaledCopy(1.0f / GameImage.getUIscale()); staticState.gradientTexture = GL11.glGenTextures(); ByteBuffer buff = BufferUtils.createByteBuffer(slider.getWidth() * 4); for (int i = 0; i < slider.getWidth(); ++i) { Color col = slider.getColor(i, 0); buff.put((byte) (255 * col.r)); buff.put((byte) (255 * col.g)); buff.put((byte) (255 * col.b)); buff.put((byte) (255 * col.a)); } buff.flip(); GL11.glBindTexture(GL11.GL_TEXTURE_1D, gradientTexture); GL11.glTexImage1D(GL11.GL_TEXTURE_1D, 0, GL11.GL_RGBA, slider.getWidth(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buff); ContextCapabilities capabilities = GLContext.getCapabilities(); if (capabilities.OpenGL30) { GL30.glGenerateMipmap(GL11.GL_TEXTURE_1D); } else if (capabilities.GL_EXT_framebuffer_object) { EXTFramebufferObject.glGenerateMipmapEXT(GL11.GL_TEXTURE_1D); } else { GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL14.GL_GENERATE_MIPMAP, GL11.GL_TRUE); } } }
Example #2
Source File: GL33Helper.java From ldparteditor with MIT License | 6 votes |
public static void drawTriangleVAO_GeneralSlow(float[] vertices) { int VAO_general = GL30.glGenVertexArrays(); int VBO_general = GL15.glGenBuffers(); GL30.glBindVertexArray(VAO_general); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_general); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STREAM_DRAW); GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION); GL20.glVertexAttribPointer(POSITION_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, 12, 0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 3); GL30.glBindVertexArray(0); GL30.glDeleteVertexArrays(VAO_general); GL15.glDeleteBuffers(VBO_general); }
Example #3
Source File: GL33ModelRenderer.java From ldparteditor with MIT License | 6 votes |
public void dispose() { isRunning.set(false); GL30.glDeleteVertexArrays(vao); GL15.glDeleteBuffers(vbo); GL30.glDeleteVertexArrays(vaoVertices); GL15.glDeleteBuffers(vboVertices); GL30.glDeleteVertexArrays(vaoLines); GL15.glDeleteBuffers(vboLines); GL30.glDeleteVertexArrays(vaoTempLines); GL15.glDeleteBuffers(vboTempLines); GL30.glDeleteVertexArrays(vaoSelectionLines); GL15.glDeleteBuffers(vboSelectionLines); GL30.glDeleteVertexArrays(vaoCondlines); GL15.glDeleteBuffers(vboCondlines); GL30.glDeleteVertexArrays(vaoCSG); GL15.glDeleteBuffers(vboCSG); GL30.glDeleteVertexArrays(vaoStudLogo1); GL15.glDeleteBuffers(vboStudLogo1); GL30.glDeleteVertexArrays(vaoStudLogo2); GL15.glDeleteBuffers(vboStudLogo2); }
Example #4
Source File: vboWithIndices.java From ldparteditor with MIT License | 6 votes |
@Override public void drawScene(float mouseX, float mouseY) { final GLCanvas canvas = cp.getCanvas(); if (!canvas.isCurrent()) { canvas.setCurrent(); GL.setCapabilities(cp.getCapabilities()); } GL11.glColorMask(true, true, true, true); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT); Rectangle bounds = cp.getBounds(); GL11.glViewport(0, 0, bounds.width, bounds.height); shaderProgram.use(); GL30.glBindVertexArray(VAO); // GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION); // <-- Not necessary! GL11.glDrawElements(GL11.GL_TRIANGLES, 6, GL11.GL_UNSIGNED_INT, 0); // GL20.glDisableVertexAttribArray(POSITION_SHADER_LOCATION); // <-- Not necessary! GL30.glBindVertexArray(0); canvas.swapBuffers(); }
Example #5
Source File: vboWithRGBA.java From ldparteditor with MIT License | 6 votes |
@Override public void drawScene(float mouseX, float mouseY) { final GLCanvas canvas = cp.getCanvas(); if (!canvas.isCurrent()) { canvas.setCurrent(); GL.setCapabilities(cp.getCapabilities()); } GL11.glColorMask(true, true, true, true); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT); Rectangle bounds = cp.getBounds(); GL11.glViewport(0, 0, bounds.width, bounds.height); shaderProgram.use(); GL30.glBindVertexArray(VAO); GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 3); GL30.glBindVertexArray(0); canvas.swapBuffers(); }
Example #6
Source File: DesktopComputeJobManager.java From graphicsfuzz with Apache License 2.0 | 6 votes |
@Override public void prepareEnvironment(JsonObject environmentJson) { final JsonObject bufferJson = environmentJson.get("buffer").getAsJsonObject(); final int bufferBinding = bufferJson.get("binding").getAsInt(); final int[] bufferInput = UniformSetter.getIntArray(bufferJson.get("input").getAsJsonArray()); final IntBuffer intBufferData = BufferUtils.createIntBuffer(bufferInput.length); intBufferData.put(bufferInput); intBufferData.flip(); shaderStorageBufferObject = GL15.glGenBuffers(); checkError(); GL15.glBindBuffer(GL43.GL_SHADER_STORAGE_BUFFER, shaderStorageBufferObject); checkError(); GL15.glBufferData(GL43.GL_SHADER_STORAGE_BUFFER, intBufferData, GL15.GL_STATIC_DRAW); checkError(); GL30.glBindBufferBase(GL43.GL_SHADER_STORAGE_BUFFER, bufferBinding, shaderStorageBufferObject); checkError(); numGroups = UniformSetter.getIntArray(environmentJson.get("num_groups").getAsJsonArray()); }
Example #7
Source File: BlurPane.java From LWJGUI with MIT License | 6 votes |
private void blit(Context context) { // Source float ratio = window.getPixelRatio(); int srcfbo = GL11.glGetInteger(GL30.GL_FRAMEBUFFER_BINDING); GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, srcfbo); // Destination GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, bufferTemp.getFboId()); int destwid = bufferTemp.getWidth(); int desthei = bufferTemp.getHeight(); int sx1 = (int)(getX()*ratio); int sy1 = (int)(getY()*ratio); int sx2 = sx1 + (int) (destwid*ratio); int sy2 = sy1 + (int) (desthei*ratio); // Blit GL30.glBlitFramebuffer( sx1,sy1,sx2,sy2, 0,0, destwid,desthei, GL11.GL_COLOR_BUFFER_BIT, GL11.GL_NEAREST); // Rebind source GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER,srcfbo); }
Example #8
Source File: TexturedQuad.java From LWJGUI with MIT License | 6 votes |
public void render() { GL11.glDisable(GL11.GL_CULL_FACE); // bind stuff GL30.glBindVertexArray(vaoId); if ( texId > -1 ) { GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId); } // draw it! glBindVertexArray(vaoId); glDrawArrays(GL_TRIANGLES, 0, 6); // unbind things GL30.glBindVertexArray(0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); }
Example #9
Source File: Vao.java From OpenGL-Animation with The Unlicense | 5 votes |
public void delete() { GL30.glDeleteVertexArrays(id); for(Vbo vbo : dataVbos){ vbo.delete(); } indexVbo.delete(); }
Example #10
Source File: Mesh.java From mars-sim with GNU General Public License v3.0 | 5 votes |
public void create() { vao = GL30.glGenVertexArrays(); GL30.glBindVertexArray(vao); FloatBuffer positionBuffer = MemoryUtil.memAllocFloat(vertices.length * 3); float[] positionData = new float[vertices.length * 3]; for (int i = 0; i < vertices.length; i++) { positionData[i * 3] = vertices[i].getPosition().getX(); positionData[i * 3 + 1] = vertices[i].getPosition().getY(); positionData[i * 3 + 2] = vertices[i].getPosition().getZ(); } positionBuffer.put(positionData).flip(); pbo = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, pbo); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, positionBuffer, GL15.GL_STATIC_DRAW); GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 0, 0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); IntBuffer indicesBuffer = MemoryUtil.memAllocInt(indices.length); indicesBuffer.put(indices).flip(); ibo = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ibo); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); }
Example #11
Source File: Vao.java From OpenGL-Animation with The Unlicense | 5 votes |
public void createIntAttribute(int attribute, int[] data, int attrSize){ Vbo dataVbo = Vbo.create(GL15.GL_ARRAY_BUFFER); dataVbo.bind(); dataVbo.storeData(data); GL30.glVertexAttribIPointer(attribute, attrSize, GL11.GL_INT, attrSize * BYTES_PER_INT, 0); dataVbo.unbind(); dataVbos.add(dataVbo); }
Example #12
Source File: FramebufferBlitter.java From OpenModsLib with MIT License | 5 votes |
@Override public void blitFramebufferOp(Framebuffer in, Framebuffer out) { GL30.glBlitFramebuffer( 0, 0, in.framebufferWidth, in.framebufferHeight, 0, 0, out.framebufferWidth, out.framebufferHeight, GL11.GL_COLOR_BUFFER_BIT, GL11.GL_NEAREST); }
Example #13
Source File: Fbo.java From LowPolyWater with The Unlicense | 5 votes |
/** * @return True if this framebuffer has been correctly set up and is * complete. */ public boolean isComplete() { GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, fboId); boolean complete = GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER) == GL30.GL_FRAMEBUFFER_COMPLETE; GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0); return complete; }
Example #14
Source File: Fbo.java From LowPolyWater with The Unlicense | 5 votes |
/** * Copy the contents of a colour attachment of this FBO to the screen. * * @param colourIndex * - The index of the colour buffer that should be blitted. */ public void blitToScreen(int colourIndex) { GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, 0); GL11.glDrawBuffer(GL11.GL_BACK); GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, fboId); GL11.glReadBuffer(GL30.GL_COLOR_ATTACHMENT0 + colourIndex); GL30.glBlitFramebuffer(0, 0, width, height, 0, 0, Display.getWidth(), Display.getHeight(), GL11.GL_COLOR_BUFFER_BIT, GL11.GL_NEAREST); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0); }
Example #15
Source File: TextureAttachment.java From LowPolyWater with The Unlicense | 5 votes |
@Override public void init(int attachment, int width, int height, int samples) { int texture = GL11.glGenTextures(); super.setBufferId(texture); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture); indicateStorageType(width, height); setTextureParams(); GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, attachment, GL11.GL_TEXTURE_2D, texture, 0); }
Example #16
Source File: Fbo.java From LowPolyWater with The Unlicense | 5 votes |
/** * Copy the contents of this FBO to another FBO. This can be used to resolve * multisampled FBOs. * * @param srcColourIndex * - Index of the colour buffer in this (the source) FBO. * @param target * - The target FBO. * @param targetColourIndex * - The index of the target colour buffer in the target FBO. */ public void blitToFbo(int srcColourIndex, Fbo target, int targetColourIndex) { GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, target.fboId); GL11.glDrawBuffer(GL30.GL_COLOR_ATTACHMENT0 + targetColourIndex); GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, fboId); GL11.glReadBuffer(GL30.GL_COLOR_ATTACHMENT0 + srcColourIndex); int bufferBit = depthAttachment != null && target.depthAttachment != null ? GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT : GL11.GL_COLOR_BUFFER_BIT; GL30.glBlitFramebuffer(0, 0, width, height, 0, 0, target.width, target.height, bufferBit, GL11.GL_NEAREST); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0); }
Example #17
Source File: FboBuilder.java From LowPolyWater with The Unlicense | 5 votes |
/** * Initialises and attaches all the colour attachments for this FBO. */ private void createColourAttachments() { for (Entry<Integer, Attachment> entry : colourAttachments.entrySet()) { Attachment attachment = entry.getValue(); int attachmentId = GL30.GL_COLOR_ATTACHMENT0 + entry.getKey(); attachment.init(attachmentId, width, height, samples); } }
Example #18
Source File: Vao.java From LowPolyWater with The Unlicense | 5 votes |
public void delete(boolean deleteVbos) { GL30.glDeleteVertexArrays(id); if (deleteVbos) { for (Vbo vbo : relatedVbos) { vbo.delete(); } } }
Example #19
Source File: TextureUtils.java From OpenGL-Animation with The Unlicense | 5 votes |
protected static int loadTextureToOpenGL(TextureData data, TextureBuilder builder) { int texID = GL11.glGenTextures(); GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texID); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, data.getWidth(), data.getHeight(), 0, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, data.getBuffer()); if (builder.isMipmap()) { GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR); if (builder.isAnisotropic() && GLContext.getCapabilities().GL_EXT_texture_filter_anisotropic) { GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, 0); GL11.glTexParameterf(GL11.GL_TEXTURE_2D, EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT, 4.0f); } } else if (builder.isNearest()) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); } else { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); } if (builder.isClampEdges()) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); } else { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT); } GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); return texID; }
Example #20
Source File: ShaderUniformCache.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void apply() { if (dirty) { switch (type.getCarrier()) { //@formatter:off case INT: switch (type.getSize()) { case 1: GL20.glUniform1i(getLocation(), cache[0]); break; case 2: GL20.glUniform2i(getLocation(), cache[0], cache[1]); break; case 3: GL20.glUniform3i(getLocation(), cache[0], cache[1], cache[2]); break; case 4: GL20.glUniform4i(getLocation(), cache[0], cache[1], cache[2], cache[3]); break; default: throw new IllegalStateException("Invalid size for Int type." + type.getSize()); } break; case U_INT: switch (type.getSize()) { case 1: GL30.glUniform1ui(getLocation(), cache[0]); break; case 2: GL30.glUniform2ui(getLocation(), cache[0], cache[1]); break; case 3: GL30.glUniform3ui(getLocation(), cache[0], cache[1], cache[2]); break; case 4: GL30.glUniform4ui(getLocation(), cache[0], cache[1], cache[2], cache[3]); break; default: throw new IllegalStateException("Invalid size for Int type." + type.getSize()); } break; default: throw new IllegalStateException("Invalid type for IntUniformEntry: " + type.getCarrier()); //@formatter:on } dirty = false; } }
Example #21
Source File: Renderer.java From mars-sim with GNU General Public License v3.0 | 5 votes |
public void renderMesh(Mesh mesh) { GL30.glBindVertexArray(mesh.getVAO()); GL30.glEnableVertexAttribArray(0); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, mesh.getIBO()); GL11.glDrawElements(GL11.GL_TRIANGLES, mesh.getIndices().length, GL11.GL_UNSIGNED_INT, 0); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); GL30.glDisableVertexAttribArray(0); GL30.glBindVertexArray(0); }
Example #22
Source File: Errors.java From Visage with MIT License | 5 votes |
private static void buildMapping() { if (mapping != null) return; Multimap<Integer, String> map = HashMultimap.create(); List<Class<?>> classes = ImmutableList.of( GL11.class, GL12.class, GL13.class, GL14.class, GL15.class, GL20.class, GL21.class, GL30.class, GL31.class, GL32.class, GL33.class, GL40.class, GL41.class, GL42.class, GL43.class, GL44.class, GL45.class, GLFW.class ); for (Class<?> clazz : classes) { for (Field f : clazz.getDeclaredFields()) { if (f.getName().toUpperCase(Locale.ROOT).equals(f.getName()) && f.getType() == int.class && Modifier.isPublic(f.getModifiers()) && Modifier.isStatic(f.getModifiers())) { List<String> li = Splitter.on('_').splitToList(f.getName()); li = li.subList(1, li.size()); String clean = Joiner.on(' ').join( li.stream() .map(Errors::toTitleCase) .iterator()); try { map.put(f.getInt(null), clean); } catch (Throwable t) { t.printStackTrace(); } } } } mapping = map; }
Example #23
Source File: OpenGL3_TheQuadTextured.java From ldparteditor with MIT License | 5 votes |
private void destroyOpenGL() { // Delete the texture GL11.glDeleteTextures(texIds[0]); GL11.glDeleteTextures(texIds[1]); // Delete the shaders GL20.glUseProgram(0); GL20.glDetachShader(pId, vsId); GL20.glDetachShader(pId, fsId); GL20.glDeleteShader(vsId); GL20.glDeleteShader(fsId); GL20.glDeleteProgram(pId); // Select the VAO GL30.glBindVertexArray(vaoId); // Disable the VBO index from the VAO attributes list GL20.glDisableVertexAttribArray(0); GL20.glDisableVertexAttribArray(1); // Delete the vertex VBO GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL15.glDeleteBuffers(vboId); // Delete the index VBO GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); GL15.glDeleteBuffers(vboiId); // Delete the VAO GL30.glBindVertexArray(0); GL30.glDeleteVertexArrays(vaoId); this.exitOnGLError("destroyOpenGL"); Display.destroy(); }
Example #24
Source File: OffscreenBuffer.java From LWJGUI with MIT License | 5 votes |
public void cleanup() { GL11.glDeleteTextures(texId); if (fboId != 0) { GL30.glDeleteFramebuffers(fboId); } if (quad != null) { quad.cleanup(); } if (quadShader != null) { quadShader.cleanup(); } }
Example #25
Source File: vboWithIndices.java From ldparteditor with MIT License | 5 votes |
@Override public void dispose() { // Properly de-allocate all resources once they've outlived their purpose shaderProgram.dispose(); GL30.glDeleteVertexArrays(VAO); GL15.glDeleteBuffers(VBO); GL15.glDeleteBuffers(EBO); isRendering.set(false); }
Example #26
Source File: GL33ModelRendererLDrawStandard.java From ldparteditor with MIT License | 5 votes |
public void dispose() { isRunning.set(false); GL30.glDeleteVertexArrays(vao); GL15.glDeleteBuffers(vbo); GL30.glDeleteVertexArrays(vaoLines); GL15.glDeleteBuffers(vboLines); GL30.glDeleteVertexArrays(vaoCondlines); GL15.glDeleteBuffers(vboCondlines); GL30.glDeleteVertexArrays(vaoStudLogo1); GL15.glDeleteBuffers(vboStudLogo1); GL30.glDeleteVertexArrays(vaoStudLogo2); GL15.glDeleteBuffers(vboStudLogo2); }
Example #27
Source File: GL33Helper.java From ldparteditor with MIT License | 5 votes |
public static void drawTrianglesIndexedTextured_GeneralSlow(float[] vertices, int[] indices) { int VAO_general = GL30.glGenVertexArrays(); int VBO_general = GL15.glGenBuffers(); int EBO_general = GL15.glGenBuffers(); GL30.glBindVertexArray(VAO_general); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_general); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STATIC_DRAW); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, EBO_general); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, GL15.GL_STATIC_DRAW); GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION); GL20.glVertexAttribPointer(POSITION_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_UV_STRIDE, 0); GL20.glEnableVertexAttribArray(TEX_NORMAL_SHADER_LOCATION); GL20.glVertexAttribPointer(TEX_NORMAL_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_UV_STRIDE, 12); // 3 * 4 GL20.glEnableVertexAttribArray(TEX_COLOUR_SHADER_LOCATION); GL20.glVertexAttribPointer(TEX_COLOUR_SHADER_LOCATION, 4, GL11.GL_FLOAT, false, RGB_UV_STRIDE, 24); GL20.glEnableVertexAttribArray(UV_SHADER_LOCATION); GL20.glVertexAttribPointer(UV_SHADER_LOCATION, 2, GL11.GL_FLOAT, false, RGB_UV_STRIDE, 40); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL11.glDrawElements(GL11.GL_TRIANGLES, indices.length, GL11.GL_UNSIGNED_INT, 0); GL30.glBindVertexArray(0); GL30.glDeleteVertexArrays(VAO_general); GL15.glDeleteBuffers(VBO_general); GL15.glDeleteBuffers(EBO_general); }
Example #28
Source File: vboWithRGBA.java From ldparteditor with MIT License | 5 votes |
@Override public void dispose() { // Properly de-allocate all resources once they've outlived their purpose shaderProgram.dispose(); GL30.glDeleteVertexArrays(VAO); GL15.glDeleteBuffers(VBO); }
Example #29
Source File: LwjglRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public void updateShaderData(Shader shader) { int id = shader.getId(); boolean needRegister = false; if (id == -1) { // create program id = glCreateProgram(); if (id <= 0) { throw new RendererException("Invalid ID (" + id + ") received when trying to create shader program."); } shader.setId(id); needRegister = true; } for (ShaderSource source : shader.getSources()) { if (source.isUpdateNeeded()) { updateShaderSourceData(source, shader.getLanguage()); // shader has been compiled here } if (!source.isUsable()) { // it's useless.. just forget about everything.. shader.setUsable(false); shader.clearUpdateNeeded(); return; } glAttachShader(id, source.getId()); } if (caps.contains(Caps.OpenGL30)) { GL30.glBindFragDataLocation(id, 0, "outFragColor"); } // link shaders to program glLinkProgram(id); glGetProgram(id, GL_LINK_STATUS, intBuf1); boolean linkOK = intBuf1.get(0) == GL_TRUE; String infoLog = null; if (VALIDATE_SHADER || !linkOK) { glGetProgram(id, GL_INFO_LOG_LENGTH, intBuf1); int length = intBuf1.get(0); if (length > 3) { // get infos ByteBuffer logBuf = BufferUtils.createByteBuffer(length); glGetProgramInfoLog(id, null, logBuf); // convert to string, etc byte[] logBytes = new byte[length]; logBuf.get(logBytes, 0, length); infoLog = new String(logBytes); } } if (linkOK) { if (infoLog != null) { logger.log(Level.INFO, "shader link success. \n{0}", infoLog); } else { logger.fine("shader link success"); } } else { if (infoLog != null) { throw new RendererException("Shader link failure, shader:" + shader + " info:" + infoLog); } else { throw new RendererException("Shader link failure, shader:" + shader + " info: <not provided>"); } } shader.clearUpdateNeeded(); if (!linkOK) { // failure.. forget about everything shader.resetSources(); shader.setUsable(false); deleteShader(shader); } else { shader.setUsable(true); if (needRegister) { objManager.registerForCleanup(shader); statistics.onNewShader(); } else { // OpenGL spec: uniform locations may change after re-link resetUniformLocations(shader); } } }
Example #30
Source File: LwjglGLFboGL3.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void glFramebufferTextureLayerEXT(int param1, int param2, int param3, int param4, int param5) { GL30.glFramebufferTextureLayer(param1, param2, param3, param4, param5); }