In OpenGL, can I draw a pixel that exactly at the coordinates (5, 5)?

后端 未结 5 1121
陌清茗
陌清茗 2021-02-19 06:35

By (5, 5) I mean exactly the fifth row and fifth column.

I found it very hard to draw things using screen coordinates, all the coordinates in OpenGL is relative, and usu

5条回答
  •  悲哀的现实
    2021-02-19 07:05

    The simplest way is probably to set the projection to match the pixel dimensions of the rendering space via glOrtho. Then vertices can be in pixel coordinates. The downside is that resizing the window could cause problems and you're mostly wasting the accelerated transforms.

    Assuming a window that is 640x480:

    // You can reverse the 0,480 arguments depending on you Y-axis 
    // direction preference
    glOrtho(0, 640, 0, 480, -1, 1);
    

    Frame buffer objects and textures are another avenue but you'll have to create your own rasterization routines (draw line, circle, bitmap, etc). There are problaby libs for this.

提交回复
热议问题