Hello!
I found
that gitbook a few days ago, and I decided to try and understand more about lwjgl. I've read the book, which is quite amazing, followed the examples, and when i finished, i wanted more, so i told myself : "Mmmmm why not extending the example a bit and try something funny like a game?"
So my starting point was the last example from the book :
https://github.com/lwjglgamedev/lwjglbook/tree/master/chapter27/c27-p2I added a few things and deleted some and then I felt like printing some text on the screen. And all i could do is a black rectangle...
All my scene renders well, with all its elements, through its own shader program. My Hud has its own shader program too, which is much simpler, but doesn't render my text correctly.
What i do to make print some text :
- use awt to load a font and generate a texture from it (works correctly, i tried writing the texture into a png file and it's ok)
- compute quads for each character and choose what part of my texture it should be and put that into texture coordinates (works ok, i checked the values just before upload to gpu)
- draw the quads on the screen (doesn't work correctly)
I see a black rectangle where i should see text, so i used glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) to see a bit more. And in fact all my quads are drawn where they should be, so my problem comes from the color or the texture. In my fragment shader, this computes the color :
fragColor = colour * texture(texture_sampler, outTexCoord);
if i change it to
fragColor = colour;
my rectangle isn't black anymore, it's the color i wanted my text to be (colour is a vec4 uniform set by my text's material's ambient color so this makes sense ^^), my problem is probably in my texture.
So i disabled all my rendering, except the HUD, and i still see a blue rectangle ( i wanted to print blue text =) ) which leads me to this part of my fragment shader :
texture(texture_sampler, outTexCoord);
If i understand correctly, texture() computes a color from a texture sampler and texture coodinates so either my texture sampler is wrong or my coordinates are.
texture_sampler is never set, but i read that the default is GL_TEXTURE0, and my text texture is bound to the same.
OutTexCoord is passed by my vertex shader :
outTexCoord = texCoord;
and before that
layout (location=1) in vec2 texCoord;
which is my mesh's vao and the texture coordinate i put there are correct.
So i'm stuck, i don't know where to go from here, any help would be great.
Thank you for your time and sorry for the bad english ^^
(EDIT: i just realized that mybe i posted in the wrong section, maybe this would be bettre in the opengl section... apologies)