I wish to create a cad like interface using glortho or gluortho2d, the problem is how do I make y coordinates like windows coordinates?
(this means increase downwards instead of upwards)
thanx
I wish to create a cad like interface using glortho or gluortho2d, the problem is how do I make y coordinates like windows coordinates?
(this means increase downwards instead of upwards)
thanx
You could rotate your coordinate system so that the positive y axis is downward. I don’t think this puts the origin at the top left of the screen though. I might be wrong.
Subject 4.03: How do I set up OpenGL matrix stack for rasterization-only?
Something like:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0, 0, width, height); /* viewport size in pixels */
will mean that the 3D point (0,0,0) is in the center of the viewport,
and that
(1,1,0) is the top-right corner of the viewport.
To get a 1:1 pixel mapping, with (0,0,0) in the top-left of the
viewport and (width,height,0) in the bottom-right, do this:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glScalef(2.0f / (float)width, -2.0f / (float)height, 1.0f);
glTranslatef(-((float)width / 2.0f), -((float)height / 2.0f), 0.0f);
glViewport(0, 0, width, height); /* viewport size in pixels */
its easier use glOrtho and set bottom to maxy and top to 0 so you have at the top 0 and at the bottom of the viewport maxy …
when you get your mouse position say now it is returning mousey = 10
now just do this
mousey = screen_size_y - mousey;
Originally posted by T2k:
its easier use glOrtho and set bottom to maxy and top to 0 so you have at the top 0 and at the bottom of the viewport maxy …
Thanx that worked lustfully.