Filling a rectangle

Recommended Posts

void glFillRect(RECTANGLE* rc, ColourData* colour)
{
glTranslated(rc->x,rc->y,0);
glColor4d(colour->r,colour->g,colour->b,colour->a);
glVertex2d(0,0);
glVertex2d(rc->w,0);
glVertex2d(rc->w,rc->y);
glVertex2d(rc->w,0);
glEnd();
}
Okay... I've put this code in here... Despite me using code very similar to display textured quads (which works), this however, doesn't. Nothing shows up... any ideas as to what might be wrong?

Share on other sites
Your second and fourth vertices are the same. That's probably your problem.

It probably should've been
glVertex2d(0, rc->y);

Share on other sites
...

Right. I don't know how I missed that :(

Thanks :)

EDIT:

Erm.. even with the changes, it still doesn't work. I'm drawing it last, so it's not behind anything, with this code:

ColourData colour = {255,255,100,255};
RECTANGLE rc = {50,50,10,10};
glFillRect(&rc,&colour);

Share on other sites
Try reversing the order of the vertices so that they are like this:

glVertex2d(0,0);
glVertex2d(0,rc->y);
glVertex2d(rc->w,rc->y);
glVertex2d(rc->w,0);

Polygons should be drawn in a counter-clockwise vertex order.

Then again, it could be a number of other things. Are you able to draw anything else to the screen?

Share on other sites
I tried to reverse it, but no luck.

And yes, I can draw quads with textures mapped onto them using this code:

void DrawImage(ImageData* structure, double x, double y, double rotation, ColourData* colour){	glBindTexture( GL_TEXTURE_2D, structure->textureid );	glLoadIdentity();	glTranslated(x+structure->w/2,y+structure->h/2,0);	glRotated(rotation,0,0,1);	glColor4ub(colour->r,colour->g,colour->b,colour->a);	glBegin(GL_QUADS);		glTexCoord2f (0.0f, 0.0f); glVertex2d(0-structure->w/2,0-structure->h/2);		glTexCoord2f (1.0f, 0.0f); glVertex2d(0+structure->w/2,0-structure->h/2);		glTexCoord2f (1.0f, 1.0f); glVertex2d(0+structure->w/2,0+structure->h/2);		glTexCoord2f (0.0f, 1.0f); glVertex2d(0-structure->w/2,0+structure->h/2);	glEnd();}

Share on other sites
Try calling glDisable(GL_TEXTURE_2D) before drawing your quad. If texturing is on, it is possible to get strange results without using texture coordinates and such.

Works! :)

Thanks :P

Create an account

Register a new account

• Forum Statistics

• Total Topics
627701
• Total Posts
2978702

• 21
• 14
• 12
• 10
• 12