OpenGL Color map
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 or underlay and glut. I am using X-Windows to open the window and uses x-windows and opengl.
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();
}
thanks
nt
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();
}
thanks
nt
It's pretty hard to understand what you're actually asking, but maybe the depth buffer does what you want?
Thanks for the reply.
The question is I want to draw three squares, draw a first one, then draw a second one, the second one should be overlaping the first square, then draw a third one with black masking zone. The third one occludes the portions of first and second. But Actually I want to onclude the first one only. I want to draw the third one with masking zone, occluding the first one but I should be able to see second one. I have the co-oridnates to specify the overlaping
The second square should be transparent eventhough I have a masking zone around the third square.
In Iris gl, I could use mapcolor to create my own color map to draw it in color index mode. But OpenGL don't have an equivalent to mapcolor. In Iris gl, I could draw the hird square with black masking zone, but not occluding second one.
I don't want to use glut and overlay.
The question is I want to draw three squares, draw a first one, then draw a second one, the second one should be overlaping the first square, then draw a third one with black masking zone. The third one occludes the portions of first and second. But Actually I want to onclude the first one only. I want to draw the third one with masking zone, occluding the first one but I should be able to see second one. I have the co-oridnates to specify the overlaping
The second square should be transparent eventhough I have a masking zone around the third square.
In Iris gl, I could use mapcolor to create my own color map to draw it in color index mode. But OpenGL don't have an equivalent to mapcolor. In Iris gl, I could draw the hird square with black masking zone, but not occluding second one.
I don't want to use glut and overlay.
You could use the depth buffer to acheive your effect.
To do this, you would use a third coordinate for all your squares. This is the z-ccord and would represent the depth of the fragment.
With depth testing enabled, any time the current fragment in the framebufer has a greater z depth, then the incoming fragment is not rendered.
Thus, your second should be renedered with more depth than the third.
Good luck...
;-)
To do this, you would use a third coordinate for all your squares. This is the z-ccord and would represent the depth of the fragment.
With depth testing enabled, any time the current fragment in the framebufer has a greater z depth, then the incoming fragment is not rendered.
Thus, your second should be renedered with more depth than the third.
Good luck...
;-)
Hi DesertPenguin,
I tried to use it and I lost all the images I just added this to it
/* 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);
glEnable(GL_DEPTH_TEST);
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);
glVertex3f(-100,100,0);
glVertex3f(-100,-100,0);
glVertex3f(100,-100,0);
glVertex3f(100,-100,0);
glVertex3f(100,100,0);
glEnd();
glColor3f (1.0, 1.0, 1.0);
glLineWidth(3);
glBegin(GL_LINE_LOOP);
glVertex3f(-100,100,0);
glVertex3f(-100,-100,0);
glVertex3f(100,-100,0);
glVertex3f(100,-100,0);
glVertexf(100,100,0);
glEnd();
I am just including the part of the code to draw the first square, then I lost all squares. Do you have a sample code on how to use depth test, I am a newbie to opengl and trying to learn. Thank you for the reply and help
I tried to use it and I lost all the images I just added this to it
/* 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);
glEnable(GL_DEPTH_TEST);
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);
glVertex3f(-100,100,0);
glVertex3f(-100,-100,0);
glVertex3f(100,-100,0);
glVertex3f(100,-100,0);
glVertex3f(100,100,0);
glEnd();
glColor3f (1.0, 1.0, 1.0);
glLineWidth(3);
glBegin(GL_LINE_LOOP);
glVertex3f(-100,100,0);
glVertex3f(-100,-100,0);
glVertex3f(100,-100,0);
glVertex3f(100,-100,0);
glVertexf(100,100,0);
glEnd();
I am just including the part of the code to draw the first square, then I lost all squares. Do you have a sample code on how to use depth test, I am a newbie to opengl and trying to learn. Thank you for the reply and help
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| iPhone OpenGL color bug | agreendev | 8 | 6,067 |
Aug 12, 2010 08:20 PM Last Post: AnotherJake |
|
| ? Find color value of 'pixel' in color buffer? | Elphaba | 1 | 3,769 |
Jul 22, 2009 01:23 PM Last Post: Bachus |
|
| OpenGL Color Buffer Overwrite | Talyn | 8 | 5,310 |
Jan 4, 2009 02:44 AM Last Post: papillon68 |
|
| OpenGl color map mode | nkpkd | 0 | 2,535 |
Mar 29, 2007 07:09 PM Last Post: nkpkd |
|
| Blitting all but one color in OpenGL | Griggs | 5 | 4,220 |
Sep 10, 2002 11:59 PM Last Post: Griggs |
|

