Drawing a single pixel

i’m beginner here. i’m trying to draw a single pixel but i couldn’t.
my source code here.

#include <GL/gl.h>
#include <GL/glu.h>
//#include <GLUT/glut.h>
#include <GL/glut.h>

#include <stdlib.h>

void display(void)
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(100.0f, 100.0f, -25.0f);

void init(void)
glClearColor(0, 0, 0, 0);

int main()
//glutInit(&argc, argv);
//glInitDisplayMode(GLUT_SINGLE| GLUT_RGB);
glutInitWindowPosition (100, 100);
glutCreateWindow (“hello”);
init ();

return 0;


can any one help me please???


with your projection matrix being the identity, you can only draw points inside of [-1…1]^3, so your point at (100,100,-25) is outside of the view. Additional tip: Unless you have a very good reason to use the fixed-function pipeline, don’t waste your time on learning it, look for modern OpenGL 3.0 (or later) tutorials. glBegin/glEnd and fixed function won’t get you far.

There are multiple errors in your code - actually posting code like that is considered an error on this forum as well. Please read the forum posting guidelines before starting a new topic.

The following may sound harsh but you obviously dived into graphics programming with any theoretical foundation.

First of all, what’s your projection matrix? It’s the identity! And the identity will not alter the coordinates of your point in any way thus it will be at the same coordinates after perspective divide (because w is still 1), thus outisde the canonical volume, thusautomatically clipped and thus not rasterized at all.

After setting an incorrect perspective transformation matrix, you do not switch back to GL_MODELVIEW, which doesn’t have any effect in your case because you don’t manipulate the matrix stack in subsequent calls, but it’s generally a very bad idea which leads to confusion and unnecessary questions asked.

Also, you don’t handle resizing your window. Most of the time, resizing means two things which aren’t done automatically since the GL has no knowledge of window system events at all. You need to make sure the aspect ratio of the window is represented by your projection and you need to update the viewport if you desire to display stuff across the whole area of the window. If the viewport stays the same, there’s no need to update the projection either.

Another thing is that you don’t use the depth buffer and depth test. In your case it’s irrelevant except for 1 pixel overdraw each frame. However, you should be familiar with the depth buffer as a concept and its usage with OpenGL.

Also, why do you comment out glutInit() and glutDisplayMode()? IIRC, both are vital if you want to use GLUT. Granted, I’m a Qt guy (no pun intended) and therefore my GLUT is a little rusty.

If that didn’t make any sense to you, you should read up on the following topics:

  • the mathematics behind projections in general and especially regarding perspective projections
  • the OpenGL pipeline (which include several steps for transforming object-space coordinates to final window-space (or pixel-space, or screen-space) coordinates)
  • the OpenGL matrix stack (if you have no idea what selectors like glMatrixMode() do)
  • depth buffering (also called z-buffering - because z denotes an axis in 3D space usually interpreted as depth)

There often seems to be a misconception that graphics programming and computer graphics theory can be learned separately - but that’s not true - at all. If you don’t know the math, you’ll not get far even if you manage to understand what some code itself means on a syntactical level.

EDIT: You should also pay close attention to menzel’s suggestion which I failed to provide. However, the math stays the same - legacy OpenGL or not.

thank you for replying and for remembering rules for post.got it. :slight_smile: