Hello everybody,
Short version of this question: Is there an example / tutorial that explains how to develop a LWJGL application using custom shaders and VBOs and sticks mostly to openGL 2.0 standards?
I would ask a more specific question if I could - but I’m completely lost
so help would really be appreciated a lot!
I am currently porting an AWT application to LWJGL, and I have some problems and I would be very happy for some advice.
Intro:
Earlier I played around with JOGL and was able to render some models using glBegin / glEnd “brackets”. After looking at some other code I realized that this is not the state of the art methodology.
So I would like to focus on GL 2.0 standards.
My setup & expectations:
- I developed an interface which is implemented by my “old” AWT classes. I would like to keep them as I put a lot of work and optimization into them. This interface is now to be implemented by a LWJGL context.
- The mentioned interface should ideally implement three functions: “addSprite” (to load textures etc.), “renderSpriteAt” (to prepare rendering) and “render”, which does the rendering for all sprites etc.
- I developed my own shaders - as I have very project specific requirements as to how the data I send to the graphics card is to be handled.
- I would like to use “state of the art” openGL, meaning VBOs and basically not have to transfer lots of data between RAM and VRAM unless “addSprite” is called.
addSprite: Takes a color map and a normal map, copies their contents to VRAM and keeps the ID to this data in an array, hashmap, whatsoever, for later use. The color map holds some information about effects (blinking, bumpmap strength etc.) in the alpha channel. That’s no problem I think, my fragment shader will take care of that.
renderSpriteAt: This function will be called several times during preparation of a single frame. Here’s basically my problem. See also below.
render: This function should finally render all sprites (and also some other stuff) and display the frame.
My problem:
A sprite in my context consists of a quad, two textures (IDs, color and normal map), and angle and a center (pivot point for rotation).
My renderSpriteAt function currently works like this:
GL20.glUseProgram(BumpmapProgram); // use my custom shader for this sprite
Sprite S = Sprites.get(spriteID);
if (S == null)
return;
int[] spriteDimensions = S.getSize(); // the width and height of the QUAD to render
int[] spriteTexture = S.getTexIDs(); // the IDs of the two maps in VRAM
GL20.glUniform1i(maTextureHandle, spriteTexture[0]); // let the fragment shader know which color map to use
GL20.glUniform1i(maNormalsHandle, spriteTexture[1]); // let the fragment shader know which normal map to use
IntBuffer vert=makeBuffer(new int[]{0,0,0,0,spriteDimensions[1],0,spriteDimensions[0],spriteDimensions[1],0,spriteDimensions[0],0,0}); // prepare a VBO to describe the QUADs vertices
GL20.glVertexAttribPointer(maPositionHandle, 4, false, false, 3*INT_SIZE_BYTES, vert); // load said VBO to VRAM
GL20.glEnableVertexAttribArray(maPositionHandle); // enable it... (for whatever reason...)
GL20.glVertexAttribPointer(maTexturePosHandle, 4, false, false, 3*INT_SIZE_BYTES, vert); // same VBO is used for the UV coordinates
GL20.glEnableVertexAttribArray(maTexturePosHandle); // again, enable the thingy
int primitiveID=GL15.glGenBuffers(); // now make a new buffer
IntBuffer Primitives=makeBuffer(new int[]{0,1,2,3}); // load the vertex indices to this buffer
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, primitiveID); // Bind it...
GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, Primitives, GL15.GL_STREAM_DRAW); // ...and store the data in VRAM
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, primitiveID); // Bind the index buffer again...
GL11.glDrawElements(GL11.GL_QUADS, 4, GL11.GL_INT, 0); // to draw the quads mentioned therein.
OK, now I know / believe to know that this probably does not make sense. Or does it? Please, enlighten me as to how such a method should be setup and whether it’s even possible avoiding the hideous glBegin / glEnd brackets the way I did…
I really tried to get some documentation on the combination “own texture, own shader, VBO, and GL20”… But it was hopeless.
Please enlighten me!
Thanks in advance to clarify my view…
Kind regards, J
