Positions of VBO's with Shaders

For a while now, I have been learning VBO’s more and trying to move away from deprecated code.

My main struggle was sending the texture coordinates to the shader, I knew what I had to do, but I could never get the them to work.

I finally got the texture coordinates to the shader, but the problem now is the positioning in the VBO.

I have used SHC’s VBO Tutorial and LWJGL Wiki on Textured Quads to produce my VBO Class.

It’s probably not the best VBO class, but its good enough for my testing of drawing 2 squares on the screen currently as I am only testing before I implement it into my game.

The question is what have I done or what do I need to add to allow for sending the x, y, width and height parameters in addRectangle() for values such as 800, 600, 100, 200 etc. Currently I need to supply values in floats between -1f and 1f. Is their a way I can just send 800, 600 etc or will I need to create a method to convert 800 down to a float between -1f and 1f?

also any recommendations on improving my VBO class will be good, but this is not its final state, just its current working state.

Are you still using glOrtho? If you are, you don’t have to specify coordinates between 1 and -1, just change your glOrtho call to include the width and height of your window, and then you don’t have to use 1 to -1 coordinates.

Also, just a suggestion, switch over to triangles and when you’re done drawing your geometry, don’t recreate the vertices buffer right away, you might not use that specific buffer object again, so its just purely from a performance stand point. Don’t recreate your buffer objects, use your matrices (or glTranslatef) to move the vertices around. I don’t know if you already knew that!

Yes, I have


glOrtho(0, WIDTH, HEIGHT, 0, 1, -1);

using SHC’s VBO tutorial, it works fine with supply values of e.g. 800 and 600, but once I implemented shaders into it, i need to use -1 to 1, while I play around while I cant find out how to fix this, I have the position changed in the vertex shader and it works like SHC’s tutorial.

Can I see your shaders? That seems odd, I’ve never had an issue like that.

Shaders are in the Textured Quad:

http://lwjgl.org/wiki/index.php?title=The_Quad_textured

The problem is that [icode]glOrtho[/icode] doesn’t work with shaders. It modifies the [icode]PROJECTION[/icode] matrix which is not available in GLSL since version 1.20. You need to modify your shaders to use a lower version to access [icode]gl_ProjectionMatrix[/icode] variable or do matrices on your own.

This link may help you.