PDA

View Full Version : urgent: drawing squares over an image



Souhail
11-21-2008, 12:45 AM
I'm new to OpenGL
I loaded a ppm image and I can't figure out how to draw squares over it, then update the coordinates of these shapes. when I draw them using glBegin(GLQuads) nothing is displayed. here is the code:
void display(void)
{

glClear ( GL_COLOR_BUFFER_BIT );
glRasterPos2i(0,0);
glColor3f(1.0f, 0.7f, 0.3f);
glBegin(GL_QUADS);
glVertex3f(-0.5f, -3.5f, 3.5f);
glVertex3f(0.5f, -3.5f, 3.5f);
glVertex3f(0.5f, -3.5f, -3.5f);
glVertex3f(-0.5f, -3.5f, -3.5f);


glEnd();
glDrawPixels(n,m,GL_RGB, GL_UNSIGNED_INT, image);
glFlush ( );

}
I just loads the image. Please help me it's urgent

_NK47
11-21-2008, 02:34 AM
yeah, also post please what your PROJECTION and MODELVIEW matrices look like.

Souhail
11-21-2008, 10:24 AM
It's my first time with openGL but I tried many different code without any success.
here is the projection that I'm currently having:
void handleResize(int w, int h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (float)w / (float)h, 1.0, 200.0);
}
and in the above display function:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);

does this answer your question?

dletozeun
11-21-2008, 11:20 AM
With glDrawPixels, you draw into the framebuffer in a way that it would erase all previous data already written the the drawing area. Call glDrawPixels before drawing quads it would already helps.

Souhail
11-21-2008, 11:40 AM
I already tried that... doesn't work
the only thing I can think of is the fact I'm using double buffering (I tried single buffering too) no results.
Any OpenGL experts?

MaxH
11-21-2008, 01:38 PM
First - comment out the call to DrawPixels. Then try to draw the square. I'm guessing that it doesn't work. Your problem has nothing to do with the fact you are trying to draw a square over an image. Your problem is that you aren't drawing the square correctly. It is not being drawn perpendicular to the line of site. It is being drawn edge-on to the line of site (which is in the -Z direction). All of your Z coordinates should be the same to draw a rectangle perpendicular to the line of site. In your example all of the Y coords are the same, but the Z coords differ. Use the Vertex commands below in place of yours and the rectangle should appear. Good luck.



glVertex3f (-10, -5, -30);
glVertex3f ( 10, -5, -30);
glVertex3f ( 10, 5, -30);
glVertex3f (-10, 5, -30);