How to draw a single pixel in OpenGL?

Can someone tell me how to draw a single white pixel in a coordinate, say (100,200)?

I use GLUT and still figured out how to open a blank window. Once I figure out how to draw pixels, I will use this to implement the Bresenham line drawing algorithm . (Yes, I know that OpenGL can draw lines. I have to implement this myself).

#include <stdio.h> #include <GL/glut.h> static int win(0); int main(int argc, char* argv[]){ glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGBA|GLUT_SINGLE); glutInitWindowSize(500,500); glutInitWindowPosition(100,100); //step 2. Open a window named "GLUT DEMO" win = glutCreateWindow("GLUT DEMO"); glClearColor(0.0,0.0,0.0,0.0); //set background glClear(GL_COLOR_BUFFER_BIT); glFlush(); glutMainLoop(); } 
+6
source share
2 answers

This is a magical line of code that spent an entire day reading stackoverflow and looking at youtube tutorials:

glVertex2i(x,y);

Here is the context that should work:

 glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowPosition(80, 80); glutInitWindowSize(500,500); glutCreateWindow("A Simple OpenGL Program"); glClear(GL_COLOR_BUFFER_BIT); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluOrtho2D( 0.0, 500.0, 500.0,0.0 ); glBegin(GL_POINTS); glColor3f(1,1,1); glVertex2i(100,100); glEnd(); 
+7
source

This can be done easily by setting the rectangle with scissors and then cleaning, which will allow you to clean only the specified area in the rectangle of scissors. For instance:

 glEnable(GL_SCISSOR_TEST); glScissor(100, 200, 1, 1); glClearColor(1,1,1,1); glClear(GL_COLOR_BUFFER_BIT); // Remember to disable scissor test, or, perhaps reset the scissor rectangle: glEnable(GL_SCISSOR_TEST); 
0
source

Source: https://habr.com/ru/post/1015200/


All Articles