Skip to main content
gamedev.net
🔒 Locked

2d problem

Started by win_crook Aug 13, 2006 at 11:36 AM 8 replies 1.2k views
Original Post
win_crook
win_crook
I am trying to draw a semi-transparent square to my window... Here is the code:

float r = 1, g = 0, b = 0, a = 0.5;
float x = 20, y = 20, xsize = 80, ysize = 80;
window.glEnable2D();
glColor4f(r, g, b, a);
glBegin(GL_QUADS);
glVertex2f(x, y);
glVertex2f(x, y+ysize);
glVertex2f(x+xsize, y+ysize);
glVertex2f(x+xsize, y);
glEnd();
window.glDisable2D();

And here are the enable and disable 2d commands:

void Window::glEnable2D()
{
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0, screen->w, screen->h, 0);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}

void Window::glDisable2D()
{
	glMatrixMode(GL_PROJECTION);
	glTranslatef(0, -2.0, 0);
	glLoadIdentity();
	gluPerspective(60, 1.33333333, 1, 1024);
}


Excuse the programmer art: Here is a screenshot of what is happening... it is being drawn in the right place but won't go the right colour. Any ideas to what is wrong? Cheers ~David [Edited by - win_crook on August 13, 2006 11:52:51 AM]
SiCrane
SiCrane
Did you call glEnable() with GL_BLEND? Did you set an appropriate value with glBlendFunc()?
win_crook
win_crook
No, I didn't know you had to do that but if you switch it onto glColor3f() and take away the alpha value so it isn't needed it is still the same colour when it should be red.
win_crook
win_crook
Thankyou, I forgot to disable lighting. Now how do I make the square translucent with the alpha value.

~David
win_crook
win_crook
thanks again all working now
win_crook
win_crook
I made a mistake when I said it is all working. The (supposedly)translucents square doesn't blend with textures... e.g:

When the square is over the terrain texture you cannot see the texture through it... the same with the sky. Is there another blend function I need to use or something?
win_crook
win_crook
Oh ok... I'm new to this transparancy lark, if it doesn't work after I have tried what you have said I'll post another screenshot.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.