Filling a rectangle

Started by
5 comments, last by Erondial 18 years ago
void glFillRect(RECTANGLE* rc, ColourData* colour)
{
	glLoadIdentity();
	glTranslated(rc->x,rc->y,0);
	glColor4d(colour->r,colour->g,colour->b,colour->a);
	glBegin(GL_QUADS);
		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?
Advertisement
Your second and fourth vertices are the same. That's probably your problem.

It probably should've been
glVertex2d(0, rc->y);
*blinks*
...
*smacks head*

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);
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?
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();}
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

This topic is closed to new replies.

Advertisement