Home > Software engineering >  MFC opengl drawing geometry, the screen coordinate with opengl coordinate relations.
MFC opengl drawing geometry, the screen coordinate with opengl coordinate relations.

Time:05-22

I according to the online example, drew a graph, the diagram below:

The corresponding OpenGL function is like this:
GlTranslatef (0.0 f, f, 0.0-6.0 f);//moving objects to the display area
GlPolygonMode (GL_FRONT_AND_BACK GL_LINE);//to draw a triangle side way
//draw 3 the three vertices of the triangle
glBegin(GL_TRIANGLES);
GlVertex3f (0.0 0.6 f, f, 0.0 f);
GlVertex3f (0.6 f, f, 0.0 0.0 f);
GlVertex3f (0.0 f, f, 0.15 0.6 f);

GlVertex3f (0.0 0.6 f, f, 0.0 f);
GlVertex3f (0.0 f, f, 0.15 0.6 f);
GlVertex3f (0.0 f, f, 0.9 0.6 f);

GlVertex3f (0.0 f, f, 0.9 0.6 f);
GlVertex3f (0.0 f, f, 0.15 0.6 f);
GlVertex3f (0.6 f, f, 0.0 0.0 f);
glEnd();
The key is glVertex3f (x, y, z);
The numerical relationship with screen coordinates of the screen, want to ask the friend,
I'm on top of the triangle mouse click here, to obtain the coordinates of the values are: as shown in the figure below:

I wanted to know, now I think the mouse arbitrary line drawing, this determines the coordinates, how to convert the coordinates of opengl, including coordinate values of the model,

CodePudding user response:

//target: test OpenGL window viewport coordinates
//the result: glutInitWindowSize (640, 480); Specifies the concept of Windows in Windows (visible, portable,
//maximize, minimize, etc) size, in pixels.
//in the OpenGL window and viewport is the concept of logic, which draw window range is specified when the vertex coordinates are the coordinates used,
//the viewport range is Windows mapping into the scope of the concept of the actual window

# define GLUT_DISABLE_ATEXIT_HACK

Void myInit (void)
{
GlClearColor (1.0, 1.0, 1.0, 0.0);//set the background color to white
GlColor3f (0.0 0.0 f, 0.0 f, f);//drawing color is black
GlPointSize (4.0);//set the point size to 4 x4 pixels

//1. If you don't do any processing, OpenGL range at the default coordinates x=y=[1, 1] [1, 1]
//2. The only world window coordinates range specified, the default viewport window coordinates range from the rest of the world, according to the world window drawing can
/* glMatrixMode (GL_PROJECTION);
GlLoadIdentity ();
GluOrtho2D (0.0, 500, 0.0, 100); */
//3. Coordinates specify the window and viewport range at the same time, the coordinate transformation from the world window will happen as the viewport coordinates, according to the world window drawing can
GlMatrixMode (GL_PROJECTION);
GlLoadIdentity ();
GluOrtho2D (2, 2, 1, 1);
GlViewport (73-250, 11, 100);
}

CodePudding user response:

reference 1st floor schlafenhamster response:
//target: test OpenGL window viewport coordinates
//the result: glutInitWindowSize (640, 480); Specifies the concept of Windows in Windows (visible, portable,
//maximize, minimize, etc) size, in pixels.
//in the OpenGL window and viewport is the concept of logic, which draw window range is specified when the vertex coordinates are the coordinates used,
//the viewport range is Windows mapping into the scope of the concept of the actual window

# define GLUT_DISABLE_ATEXIT_HACK

Void myInit (void)
{
GlClearColor (1.0, 1.0, 1.0, 0.0);//set the background color to white
GlColor3f (0.0 0.0 f, 0.0 f, f);//drawing color is black
GlPointSize (4.0);//set the point size to 4 x4 pixels

//1. If you don't do any processing, OpenGL range at the default coordinates x=y=[1, 1] [1, 1]
//2. The only world window coordinates range specified, the default viewport window coordinates range from the rest of the world, according to the world window drawing can
/* glMatrixMode (GL_PROJECTION);
GlLoadIdentity ();
GluOrtho2D (0.0, 500, 0.0, 100); */
//3. Coordinates specify the window and viewport range at the same time, the coordinate transformation from the world window will happen as the viewport coordinates, according to the world window drawing can
GlMatrixMode (GL_PROJECTION);
GlLoadIdentity ();
GluOrtho2D (2, 2, 1, 1);
GlViewport (73-250, 11, 100);
}

Could you convert? Give a hint,
  • Related