How do I draw unrounded pixels in OpenGL?

80 Views Asked by At

I'm trying to draw square pixels using GL_POINTS but the pixels are rounded. I've tried using glDisable(GL_POINT_SMOOTH) but it doesn't seem to change anything.

Here's my code:

glDisable(GL_POINT_SMOOTH);
glPointSize(8); 
glBegin(GL_POINTS); 
glVertex2i(500, 400); 
glEnd();
1

There are 1 best solutions below

4
jh100 On

The glPointSize reference page (https://registry.khronos.org/OpenGL-Refpages/gl4/html/glPointSize.xhtml) notes that if you (or any library you're using) has called glEnable(GL_PROGRAM_POINT_SIZE) then the vertex shader will control the size of the points (rather than glPointSize() being in control).

Also, some platforms may have rather severe limits on the maximum point size: It might be the case that the maximum size is 1 (!) which means that (in effect) you don't have the ability to do square pixels at all. To check your platform's capabilities:

GLint sizeRange[2];
glGetIntegerv(GL_POINT_SIZE_RANGE,sizeRange);
//sizeRange[0] is the minimum; sizeRange[1] is the maximum

[ref: https://registry.khronos.org/OpenGL-Refpages/gl4/html/glGet.xhtml]