how to use glVertex with screen coordinates

Started by
0 comments, last by Fl00Fy 11 years, 1 month ago

Hi!

I'm trying to convert the awt.Graphics.drawLine into OpenGL.


glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(600, 300);
    (void)glutCreateWindow("GLUT Program");

How can I use glVertex2i with screen coordinates. Something like.


glVertex2i(100, 100);

Meaning that it will draw something on position x=100, y=100 on my window screen of size (600, 300)

In java one can use awt.Graphics.drawLine with window coordinates.

Please help

Advertisement

You can use gluOrtho2D() (if you want it to be 2D) to set the window coordinates to whatever you like.

gluOrtho2D (0, 600, 0, 300); for example would set the window coordinates to 0,0 at the bottom left, and 600,300 at the top right.


Could do something like this.
int width = 600;
int height = 300;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(width, height);
gluOrtho2D(0, width, 0, height);
(void)glutCreateWindow("GLUT Program");

The first parameter in gluOrtho2D is the value of the x-axis at the left, the second at the right. The third is the value of the y-axis at the bottom, the fourth at the top.

Hope that helped.

This topic is closed to new replies.

Advertisement