OpenGl color map mode

nkpkd
Unregistered
 
Post: #1
I have a problem. I want to draw three squares on a window. I draw the first one, then second one and then third one with the region masked. Due to masking of the region for the third sqaure, parts of other two squares are occluded. I want to make the second square visible while making the first square occluded. Basically I need a masking zone for third square, but I should be able to see the second square not the first one. I don't want to use glut or any other tools, only want to use openGL. How can I do it, please help, any help will be appreciated. Attaching the code portion which draws the squares to any window. I don't want to use overlay and using x-windows to open the winodw

void draw(void)
{


/* clear all pixels */
glClear (GL_COLOR_BUFFER_BIT);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//gluOrtho2D(-250.0,250.0, -250.0, 250.0);
gluOrtho2D(250.0,-250.0, 250.0, -250.0);

glColor3f (1.0, 1.0, 1.0);

/* 1 Draw the first square */
glColor3f(0.0,0,0);

/* for a halo one pixel masking zone around the lines */ glLineWidth(6);
glBegin(GL_LINE_LOOP);
glVertex2f(-100,100);
glVertex2f(-100,-100);
glVertex2f(100,-100);
glVertex2f(100,-100);
glVertex2f(100,100);
glEnd();
glColor3f (1.0, 1.0, 1.0);
glLineWidth(3);
glBegin(GL_LINE_LOOP);
glVertex2f(-100,100);
glVertex2f(-100,-100);
glVertex2f(100,-100);
glVertex2f(100,-100);
glVertex2f(100,100);
glEnd();



/* 2 draw the second square*/
glColor3f (0.0, 0.0, 0.0);
glLineWidth(6);
glBegin(GL_LINE_LOOP);
glVertex2f(-175,50);
glVertex2f(-175,-150);
glVertex2f(50,-150);
glVertex2f(50,50);
glEnd();

glColor3f (1.0, 0.0, .50);
glLineWidth(2);
glBegin(GL_LINE_LOOP);
glVertex2f(-175,50);
glVertex2f(-175,-150);
glVertex2f(50,-150);
glVertex2f(50,50);
glEnd();

/* 3 Draw the third square*/
glPushMatrix();
/* mask the entire region with black color
* but makes the other two squares invisible
* Need to have this masking but I need the second
* square to be transparent, but not the first one
*/
glColor3f(0.0,0,0);
glPopMatrix();
glPushMatrix();
glLineWidth(6);
glBegin(GL_POLYGON);
glVertex2f(-150,75);
glVertex2f(-150,-125);
glVertex2f(75,-125);
glVertex2f(75,75);
glEnd();


glColor3f(1.0,1.0,0);
glLineWidth(1);
glBegin(GL_LINE_LOOP);
glVertex2f(-150,75);
glVertex2f(-150,-125);
glVertex2f(75,-125);
glVertex2f(75,75);
glEnd();
glPopMatrix();
}
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  iPhone OpenGL color bug agreendev 8 7,320 Aug 12, 2010 08:20 PM
Last Post: AnotherJake
  ? Find color value of 'pixel' in color buffer? Elphaba 1 4,494 Jul 22, 2009 01:23 PM
Last Post: Bachus
  OpenGL Color Buffer Overwrite Talyn 8 6,073 Jan 4, 2009 02:44 AM
Last Post: papillon68
  OpenGL full screen mode leaves garbage on screen when exiting app Malarkey 5 5,284 Nov 19, 2008 12:51 PM
Last Post: Malarkey
  OpenGL Color map nkpkd 4 4,069 Mar 30, 2007 10:47 AM
Last Post: nkpkd