hi everyone
when i called the glColor4fv(v), it did not set the color to v. let me show the codes then the screen output:
hi everyone
when i called the glColor4fv(v), it did not set the color to v. let me show the codes then the screen output:
Ok, first things first.
Calling glClear(GL_COLOR_BUFFER_BIT) will clear the color buffer (ie. the screen) with the color you specify with glClearColor().
You also only need to set the clear color once, so call glClearColor() once when you initialize your program, and then, you only need to call glClear() at the start of every frame to clear the color buffer (instead of calling both everytime, like you do on your clear function).
Next, in order for transparency to work, you need to enable blending.
To do this, call
//Enable alpha blending
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
You also only need to do this once, when you initialize your program, just like glClearColor().
Now, inspecting your rendering code and your screen shot, it appear that the text's background box is not being drawn at all, and that every subsequent draw uses that first box' color (red).
Honestly I can't really see what's causing the problem.
Can you post you're entire code? If so I'll be able to test it in my computer, and I'll be able to help you more.
I don't know exactly why this doesn't work but I recall something with opengl that if you enable texturing then colours no longer function as you expect (It might be using lighting that causes the change, I am not sure). Since those are bitmap characters you are drawing they will be using texturing and this may be messing around with how your colours work. Try disabling texturing before drawing those boxes and see what happens.
void draw_box(GLint l, GLint b, GLint r, GLint t, const GLfloat c[4])
{
glDisable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
glColor4fv( c );
glBegin(GL_QUADS); // draw the foreground color box
glVertex2i(l, b);
glVertex2i(r, b);
glVertex2i(r, t);
glVertex2i(l, t);
glEnd();
}
It might be worth showing your initialisation code.
I don't know exactly why this doesn't work but I recall something with opengl that if you enable texturing then colours no longer function as you expect
Yes, i thought that too, but if i recall correctly, having texturing enabled without specifying a texture ( with an ID of 0) will prevent any non-textured objects to appear at all.
The lighting could also be a problem, but even if he had light enabled by mistake, the objects should appear black (or grey?) if he didn't specify a light color/position.
And he would also have to enable texturing and lighting, because they're disabled by default.
I might be wrong though.
It might be worth showing your initialisation code.
Yeah, or the whole code, if possible.
glBegin(GL_QUADS); // draw the foreground color box
glColor4fv( c );
glVertex2i(l, b);
glVertex2i(r, b);
glVertex2i(r, t);
glVertex2i(l, t);
glEnd();
Also, inb4 OpenGL 1.1 nonsense.
hi everyone.
here is my new codes
#include "source.h"
Ok, just by glancing at it, you have GL_TEXTURE_2D enabled.
Call glDisable(GL_TEXTURE_2D) before you draw non-textured polygons.
I could be wrong, but usually the vertex attributes are set after starting a drawing command
Both work.
You can put glColor*() calls both outside or inside glBegin() glEnd() calls.
I usually put it outside if using a single color for the whole polygon, and inside if using per vertex color (when I use old fixed function OpenGL anyway).