I'm having a little trouble understanding how to use OpenGL 2.1 with GLSL 1.2 in C++. I'm looking at code I wrote (or pasted from online together...) and I don't understand it and I can't get texturing to work. Right now, it all appears white. Yes, my shaders compile properly and my texture image is loaded correctly (I checked using immediate mode).

So it draws the box at the correct position but it's all white. Also, as you may have noticed, most of the code above is mumbo-jumbo and I don't know what I need or what I don't or the proper way to do it. All of the tutorials I see are of OpenGL 3.0, but my computer is limited to 2.1 so I want to learn how to use it with shaders so I don't need to change much when I finally upgrade. Any help is appreciated. Thanks in advance!

mobeen

12-26-2011, 06:40 PM

Hi,
I think there are two reasons for this.
1) Are you calling
glEnable(GL_TEXTURE_2D); when you first bind the texture and specify the texture data using glTexImage2D function?
2) Are you specifying the texture minification filter? If not the default minification filter is mipmaps and if you don't provide mipmaps, the texturing would not work. Make sure that when you are specifying the texture filters, you have atleast specified the texture minification filter as follows.

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR) So the whole sequence will be as follows,

And I see the texture on the screen. Man, looking at examples, OpenGL 3.0 looks a lot easier. Too bad I have to wait till I go to college till I get a new computer...
My texture is not the problem, it's my drawing function that's messed up, I don't understand how to correctly set it up.

mobeen

12-26-2011, 08:14 PM

Before adding in buffer objects, try vertex arrays and see if you get anything on screen.

Thanks, it's working now! This is what mainly helped me. I just put the newTexCoord in a vertex array and then binded that buffer.

One more question, what are indices? I could never find a definition on them. From my understanding, they allow you to reuse coordinates, useful for creating cubes and such. Is this correct?

marshats

12-27-2011, 09:38 AM

Glad that worked.

As for your second question: Yes indices allow you to reuse coordinates. Try reading these references:

* Take a look at the "Enter Index Buffers (http://openglbook.com/the-book/chapter-3-index-buffer-objects-and-primitive-types/)" section. The key to understanding indices is getting the picture straight -- notice the figure has a bunch of P^n "points". So to get say point 3 you could think in terms of C notation P[3]. Notice that P[3] is shared between four triangles in the drawing ... that is exactly what glDrawElements does it only requires here 17 unique points and references the particular triangles by index number.

* Or take a look at Section glDrawElements() (http://www.songho.ca/opengl/gl_vertexarray.html) which states "glDrawElements() draws a sequence of primitives by hopping around vertex arrays with the associated array indices."

mhagain

12-27-2011, 12:34 PM

Important to note that - as mentioned above - GL_INDEX_ARRAY is not used for drawing with indices; it's an unfortunate coincidence in terminology that confuses when first encountered, but you can get by if you just forget that you ever heard of GL_INDEX_ARRAY and glIndexPointer (these are actually used for an OpenGL context in colour index mode, as opposed to the more common RGBA mode, and are highly unlikely to be even supported on modern hardware).