Two-dimensional image to two-dimensional screen display, corresponding to screen coordinates

Source: Internet
Author: User

Description

By default, the center point is in the center of the screen, the range is from [ -1,1], so the actual coordinates of the object map to the screen coordinates need a conversion process, described above to use the GLUORTHO2D function through the positive projection, the physical coordinates mapped to the screen coordinates, but the coordinates of the origin in the lower left corner, in general, The origin of the screen starts at the top left, so in all of the examples above, you need to recalculate the coordinates of the y-axis and the high minus y-axis component of the screen. Now, by re-setting the lower-left coordinate of the orthographic projection and the coordinates of the upper-right corner, the one by one corresponding relationship is established, and no conversion is required, similar to the rotation of the camera, to adjust the coordinate system.


Code

#include <gl/glut.h>

#include <Windows.h>


#define WINDOWHEIGHT 480

#define WINDOWWIDTH 800


void Myinit ()

{

Glclearcolor (1.0,1.0,1.0,0.0);

Glmatrixmode (gl_projection);

Glloadidentity ();

gluortho2d (0.0, windowwidth, 0.0, windowheight);

gluortho2d (0.0, windowwidth, windowheight, 0.0);

}


void Mydisplay (void)

{

Glclearcolor (1.0f, 1.0f, 1.0f, 0.0f);

Glclear (Gl_color_buffer_bit | Gl_depth_buffer_bit);

Glflush ();

}


void Mymouse (int button,int state,int x,int y)

{

if (State==glut_down)

{

Glpointsize (10);

Glbegin (gl_points);

glcolor3f (1.0f, 0.0f, 0.0f);

GLVERTEX2F (x, windowheight-y);

glvertex2f (x, y);

Glend ();

Glflush ();

}

}


int main (int argc, char* argv[])

{

Glutinit (&ARGC, argv);

Glutinitdisplaymode (Glut_rgba | Glut_single);

Glutinitwindowsize (WindowWidth, windowheight);

Glutinitwindowposition (100,150);

Glutcreatewindow ("OpenGL window 1");

Glutdisplayfunc (&mydisplay);

Glutmousefunc (&mymouse);

Myinit ();

Glutmainloop ();

return 0;

}






Two-dimensional image to two-dimensional screen display, corresponding to screen coordinates

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.