PDA

View Full Version : Weird Problem !!!



Belgy
10-28-2002, 03:51 AM
Hi, im a newbie on OpenGL and what im trying to do is to render a square with 2 for-loops setting it pixel by pixel. The problem is that when i render it on some coordinates it works just fine but i have discovered that i get one horizontal and one vertical line going through the rectangle. I am doing this in XOR-mode and i need to keep doing that.

Pleas, please help me with this weird problem. Listed below is all my code.
--------------------
#include <GL/glut.h>
#include <windows.h>
void myinit(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glColor3f(1.0, 1.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 500.0, 0.0, 500.0);
glMatrixMode(GL_MODELVIEW);

//enable XOR'ing
glEnable(GL_COLOR_LOGIC_OP);
glLogicOp(GL_XOR);
}
void display( void )
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
for(int y = 100; y <= 300; y++)
{
for(int x = 200; x <= 400; x++)
{
glVertex2i(x, y);
}
}
glEnd();
glFlush(); /* clear buffers */
}
void main(int argc, char** argv)
{
/* Standard GLUT initialization */
glutInit(&argc,argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0); glutCreateWindow("Test");
glutDisplayFunc(display);

myinit(); /* set attributes */

glutMainLoop(); /* enter event loop */
}

blood.angel
10-28-2002, 04:39 AM
Do you need to do it GL_POINTS?

Belgy
10-28-2002, 04:50 AM
Yes I do. This is just a simpler test but i have other drawinfunctions that in time will make up 3d-renering engine. So it has to be in points when im rendering my objects.

Anyway, im starting to suspect that this problem that im having lies in my 3d-card. Im not sure yet though.

blood.angel
10-28-2002, 06:49 AM
Isnt there a GL_LINE_WIDTH eviqualent for points?
Set that to 1.0 which it already probably is.

JML
10-29-2002, 06:55 AM
Take a closer look at your glOrtho setup.
IIRC you should do a very small translation in the x and y direction ( 0.5, 0.5) or (0.375, 0.375) to make sure your OpenGL coordinates will correctly and reliably map to pixels in your window. This has to do with internal rounding errors.

HTH

Jean-Marc.