Hello Guest

not rendering color lwjgl voxel engine

  • 2 Replies
  • 2641 Views
not rendering color lwjgl voxel engine
« on: August 26, 2015, 14:53:09 »
i am writing a opengl based voxel engine voxel engine using java and lwjgl. i have followed this tutorial and tried to update it's rendering method to modern opengl so i can use shaders. when i turned glVertexPointer into glVertexAttribPointer it displayed all the vertices correctly but when i did it for glTexCoordPointer the color stopped displaying.

here are the two rendering methods of the chunks (from the updated one and the old one)

Code: [Select]
public void Render() { //updated render method
        GL30.glBindVertexArray(VAOHandle);
        GL20.glEnableVertexAttribArray(0);
        GL20.glEnableVertexAttribArray(1);
        GL11.glDrawArrays(GL11.GL_QUADS, 0, CHUNK_SIZE * CHUNK_SIZE
                    * CHUNK_SIZE * 24);
        GL20.glDisableVertexAttribArray(1);
        GL20.glDisableVertexAttribArray(0);
        GL30.glBindVertexArray(0);
}

public void Render() {  //old render method
        GL11.glPushMatrix();
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBOVertexHandle);
        GL11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0L);
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBOColorHandle);
        GL11.glColorPointer(3, GL11.GL_FLOAT, 0, 0L);
        GL11.glDrawArrays(GL11.GL_QUADS, 0, CHUNK_SIZE * CHUNK_SIZE
                * CHUNK_SIZE * 24);

        GL11.glPopMatrix();
}

and here is the part where the date is loaded to the VAO/VBOs (the data is the same in both cases so i don't think i need to add it, but if needed i will):

Code: [Select]
// updated method
VAOHandle =  GL30.glGenVertexArrays();
GL30.glBindVertexArray(vaoID);
VBOColorHandle = GL15.glGenBuffers();
VBOVertexHandle = GL15.glGenBuffers();

GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBOVertexHandle);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, VertexPositionData,
                GL15.GL_STATIC_DRAW);
GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 0, 0);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBOColorHandle);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, VertexColorData, GL15.GL_STATIC_DRAW);
GL20.glVertexAttribPointer(1, 3, GL11.GL_FLOAT, false, 0, 0);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
GL30.glBindVertexArray(0);

// old method
VBOColorHandle = GL15.glGenBuffers();
VBOVertexHandle = GL15.glGenBuffers();

GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBOVertexHandle);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, VertexPositionData,
        GL15.GL_STATIC_DRAW);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBOColorHandle);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, VertexColorData,
        GL15.GL_STATIC_DRAW);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

if anyone can figure out why the vertices are rendered but no color is applied i would be greatful, thanks in advance

*

Offline quew8

  • *****
  • 569
  • Because Square Eyes Look More Real
Re: not rendering color lwjgl voxel engine
« Reply #1 on: August 26, 2015, 15:31:47 »
Before I comment on your problem, let me highlight two more for you. 1) enabled vertex attrib arrays are part of the vao state so you can move the glEnableVertexAttribArray() calls to the setup and not bother enabling or disabling them again. 2) Generally if you are going to post code to a Java orientated forum, make sure it uses Java styling conventions (camelCase variable names) - more people will read it and they are more likely to spot mistakes.

Now I couldn't spot anything wrong with the code you posted. Presumably you are using the same data as in the old version so the problem won't be there so it is probably somewhere in your shader code. Can we have a gander? (Also make sure you are calling glGetError() somewhere and checking the result. Always but especially when looking for a bug).

Re: not rendering color lwjgl voxel engine
« Reply #2 on: August 26, 2015, 15:55:47 »
Before I comment on your problem, let me highlight two more for you. 1) enabled vertex attrib arrays are part of the vao state so you can move the glEnableVertexAttribArray() calls to the setup and not bother enabling or disabling them again. 2) Generally if you are going to post code to a Java orientated forum, make sure it uses Java styling conventions (camelCase variable names) - more people will read it and they are more likely to spot mistakes.

Now I couldn't spot anything wrong with the code you posted. Presumably you are using the same data as in the old version so the problem won't be there so it is probably somewhere in your shader code. Can we have a gander? (Also make sure you are calling glGetError() somewhere and checking the result. Always but especially when looking for a bug).

never mind, found the error anyway (something stupid in the vertex shader) but thanks for the tips anyway ;)