0

So I'm fairly new to OpenGL and texturing. I have a flat plane like primitive (2 triangles) that I'm trying to map an image on to. I've done this 2 ways. The first way I wrote a Fragment shader that uses sampler2d uniform, and calles texture2d to map the pixel of the image to the primitive, and this works fine and looks like this:

Correct

THe second approach I took i used glEnable and didn't use any shaders, and the image looked like this:

Wrong

A lot of this code is a work project so I can't post a lot of it but I'm basically rendering like this:

void draw()
{
    glColor4f(0.0, 1.0, 0.0, 1.0)

    glEnable(GL_TEXTURE_2D);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_TEX_COORD_ARRAY);

    glBindTexture(GL_TEXTURE_2D, id);

    glVertexPointer(3, GL_FLOAT, 0, vertices);
    glNormalPointer(GL_FLOAT, 0, normals);
    glTexCoordPointer(2, GL_FLOAT, 0, texCoords);

   // then draw arrays....
   // disable client states


}

I know the green is coming from my glColor call but I guess I just wanna understand what's going on behind the scenes here? I would think if I call glColor before I render that none of the image would would show up because its coloring everything green. This makes total sense from the shader standpoint but I don;t get this approach. How would I make it work using the old method without shaders as I did with the shader?

  • 1
    Have you tried setting the texture mode with `glTexEnv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);` before drawing? – Margaret Bloom Mar 12 '16 at 19:04
  • 1
    The real lesson here is that, contrary to what some people think, using OpenGL with shaders is actually easier once you got over the initial hurdle. It will just do what you implement, instead of the result depending on hundreds of state variables. So just keep using shaders, and don't look back. – Reto Koradi Mar 12 '16 at 19:12
  • Yep TexEnv is exactly what it was. Yea I agree I think shaders is much easier and much more intuitive. Problem is our code is very very old so most of it is fixed pipeline, so I learned all the modern stuff first and then saw all the older stuff. Anyways thanks for the help!!! – user3827379 Mar 12 '16 at 19:49

0 Answers0