Jump to content
  • Advertisement
Sign in to follow this  
Erondial

Filling a rectangle

This topic is 4557 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
*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);

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!