Hey so my problem is pretty short and simple. I’m kind of new to OpenGL and I noticed that when I call glColor3f when I’m about to draw lines or a quad, it sets all of the textures that I rendered to be that color as well. I tried using glPushMatrix() and glPopMatrix() before I called glColor3f(1, 0, 0) but it still changed all of my textures to be red and black… (I load my textures with SlickUtil btw) Any way around this? Thanks.
glPopMatrix() after the color and vertex calls.
All sets will be reset to what they were when you called glPushMatrix() when you call glPopMatrix().
Or is there any further problem?
You mean like this?
glPushMatrix();
glBegin(GL_LINES);
glColor3f(1, 0, 0);
glVertex2f(100, 100);
glVertex2f(200, 200);
glEnd();
glPopMatrix();
Because that’s what I was using before and my textures are still red and black… Maybe glClearColor would work? But how would I do that?
Really? OpenGL is state based. So when you say glColor4f(0,0,0,0) all fixed function drawing will use the current bound color which is (0,0,0,0).
If you want to “clear” the color after drawing something, just call glColor4f(1,1,1,1).
- but if you are not using transparency, just stick with glColor3f(1, 1, 1);
Whatever man. All I know is I call glColor4f(1, 1, 1, 1) before I render each texture and my textures and my lines can all get along now for some reason. But now, all my quads are all topsy turvy and won’t even render when I give them a color. Why does OpenGL have to be so confuzzling? :cranky:
I think it is the fixed function pipeline that is confusing because we are so object oriented today.
Basically, all calls to GL11 etc are state based. IE if you say glColor(1,1,1,1), everything that requires a color will pull from that state. So any time you want to change the color for something you need to change glColor. This is the same for all GL11 stuff.
I recommend creating some sort of batching using VBOs. It is not nearly as bad as it seems but you basically fill up arrays with data and send it to the GPU.
If I remember right, the last 1 in glColor4f is alpha, which means transparency here.
A value of 1 would be fully transparent. You could either change it to 0 or just use glColor3f.
Calling a color change for everything is probably not the best way though.
1 is actually full opaque and 0 is completely transparent IIRC.
Actually, Drenuis that is the best way when using fixed function.
If you want a different color for each corner of a quad, you would call glColor4f four times.
If you call color4f with (1,1,1,0) and then call color3f with (1,1,1) the alpha still is 0, so for clarity you may as well use glcolor4f.
opiop65 is right.
- just ment calling a color change even if there is none is not necessarily good. But normally it does not even make a real difference so ya…
Not true. glColor3f sets alpha to 1