OK. I have a problem, and I need help. I don’t seem to understand how to write OpenGL code. Here’s what I did (using lwJGL):
a) implemented an interface which offers a storeTexture and a drawSprite method (storeTexture copies a colormap and a normalmap to VRAM in my LWJGL class)
b) write shaders (that part is fun and I think I got it right - except for my previous question, but that’s low priority)
c) I think the storeTexture part is good. But I have problems with the drawSprite method.
Currently this method does the following:
Use my cool shader:
GL20.glUseProgram(BumpmapProgram);
Pump the sampler2d uniforms to the fragment shader:
GL20.glUniform1i(maTextureHandle, spriteTexture[0]);
GL20.glUniform1i(maNormalsHandle, spriteTexture[1]);
Make one Quad into a buffer:
IntBuffer vert=makeBuffer(new int[]{0,0,0,0,spriteDimensions[1],0,spriteDimensions[0],spriteDimensions[1],0,spriteDimensions[0],0,0});
Pump the buffer to VRAM
GL20.glVertexAttribPointer(maPositionHandle, 4, false, false, 3INT_SIZE_BYTES, vert);
Let the shader know that he can count on the vertices:
GL20.glEnableVertexAttribArray(maPositionHandle);
Pump the texture UV thingies to the shader:
GL20.glVertexAttribPointer(maTexturePosHandle, 4, false, false, 3INT_SIZE_BYTES, vert);
Let the shader know that he can count on the UV coords:
GL20.glEnableVertexAttribArray(maTexturePosHandle);
Now, up to here I think that I’ve got things right. Now I need to pump the index buffers to VRAM. Let’s first reserve a buffer ID:
int primitiveID=GL15.glGenBuffers();
Now create the buffer in normal RAM:
IntBuffer Primitives=makeBuffer(new int[]{0,1,2,3});
Tell my ol’ NVidia to point to that buffer:
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, primitiveID);
…and upload the index data to VRAM:
GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, Primitives, GL15.GL_STREAM_DRAW);
Again, let the GPU know which buffer to work with:
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, primitiveID);
and tell it to draw elements:
GL11.glDrawElements(GL11.GL_QUADS, 4, GL11.GL_INT, 0);
I can explain every line of my code, but still I think it’s amazingly wrong. Assistance would be appreciated a lot!
Cheers, J