I'm working on a opengl graphics project using allegro 5 for school. I've been using the OpenGL superbible 5th ed as a guide, however I've run across a problem. The book uses GLTools to work with shaders for the majority of the book, but in chapter 12 it tries to explain how to load your own attributes without using GLTools. My issue is the examples are rather short and the book jumps to more advanced topics very quickly. I've copied/written code that should work, but I have no idea what my next step should be. Could someone look at my code below and point me in the right direction?
Google and OpenGL reference is your friend.
What you want is something like (this would be for the texture):
glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, starTexture); glUniform1i(m_locTexture, 0);
This is taken from the allegro_shader addon which is in the 5.1 branch of Allegro. You might want to have a look at it. Setting matrices and other uniforms is pretty easy too.
[edit]
Oops, I forgot to explain it. When you have a sampler2D in a shader it's not actually a texture number but a texture unit that it references. In the above code, you set the active texture unit to 0 (you can use more texture units for multitexturing if you want), bind the texture, then the glUniform call tells the shader that that sampler is using texture unit 0.
Didn't I already bind the texture and set its location? I'm aware that allegro 5.1 will add in shader support, and thats great, but I'm already pushing my professor's limits using Allegro for display/keyboard input.
Maybe I'm not explaining my confusion well enough. I'm pretty sure I've compiled and linked my shader code correctly. I'm also fairly certain I've set my uniforms correctly. I'm not certain I've set my attributes correctly, or how to draw using the shader(GlBegin??).
The shader addon isn't going to add any overhead.. but anyway, here's some code from it that sets an attribute:
"u" is a pointer to the first floating point texture coordinate and stride is the number of bytes between "u"s.
Thats a little helpful, I really cant use allegro shaders, but it does help a little. How would you draw that shader? Would something like this work?
No. You set up color and vertex position arrays just like the texture arrays in the sample above, then you call glDrawArrays.
Mmmm, still having some trouble. Could you let me know which lines I should change or delete or are just useless?
Didn't look at it all but stride should not be zero it should be sizeof(type)*num_components if they're tightly packed. Also passing 0 and 1 to glVertexAttribPointer is wrong, you are supposed to pass the value retrieved from getGetVertexAttribPointer (IIRC that's the name of the function but it might be something else).
Fixed the stride, but for glVertexAttrib pointer I binded 0 and 1 like so...
glBindAttribLocation(myShader, 0, "vVertex");
glBindAttribLocation(myShader, 1, "vColor");
so shouldn't 0 and 1 work for glVertexAttribPointer? Either way, still not getting my shader to appear.
I don't know about that function. I also haven't used VBOs so I can't tell if that code is right. Are you sure you want to draw just 1 pixel?
Just trying to get the hang of setting up shaders, how many points I draw is arbitrary. If you know an easier way to do it I'm certainly open to that.