Jump to content

  • Log In with Google      Sign In   
  • Create Account


how to use glVertex with screen coordinates


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Hachaso77   Members   -  Reputation: 231

Like
0Likes
Like

Posted 16 March 2013 - 08:30 AM

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



Sponsor:

#2 Fl00Fy   Members   -  Reputation: 188

Like
1Likes
Like

Posted 16 March 2013 - 08:54 AM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS