• Advertisement
Sign in to follow this  

how to use glVertex with screen coordinates

This topic is 1774 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement