1
\$\begingroup\$

i'm currently working on a game engine for a college's project. While implementing some debug tools I came across a little problem. When i'm drawing point on the ModelView Matrix the point's thickness doesn't stay at scale with the other objects.

This is how I draw a point

    public static void DrawPoint(Vector3 p1,float size,Color color)
    {
        GL.Disable(EnableCap.Texture2D);
        GL.PointSize(size);
        GL.Begin(BeginMode.Points);
        GL.Color3(color);
        GL.Vertex3(p1.X, p1.Y, p1.Z);
        GL.End();
    });

This is my drawing loop

          protected sealed override void OnRenderFrame(FrameEventArgs e)
    {
        base.OnRenderFrame(e);

        GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
        GL.MatrixMode(MatrixMode.Modelview);
        GL.LoadMatrix(ref _Camera.CameraMatrix);
        GL.PushMatrix();

        RenderGame(); //<-- Where I render world object

        GL.Clear(ClearBufferMask.DepthBufferBit);
        GL.LoadIdentity();
        GL.MatrixMode(MatrixMode.Projection);
        GL.PushMatrix();
        GL.LoadIdentity();
        GL.Ortho(0, Width, 0, Height, -1, 1);
        GL.MatrixMode(MatrixMode.Modelview);

        DrawHUD(); //<-- Where I render UI

        GL.MatrixMode(MatrixMode.Projection);
        GL.PopMatrix();
        GL.MatrixMode(MatrixMode.Modelview);

        GL.PopMatrix();
        SwapBuffers();
    }  

All points are drawn in the RenderGame method

My question is am I doing something wrong when I draw points, because it is the only shape that doesn't behave correctly. Or maybe it's just something I don't understand from openGL side. I'll put images of the problem soon.

\$\endgroup\$
1
\$\begingroup\$

The point you draw is really a spot of the size you put on the screen. It has no volume.

From opengl wiki:

Points are rasterized as screen-aligned squares of a given window-space size.

If you want to draw a point that changes size as you zoom in and out, you could

  1. Draw a point like you do but change the size as you zoom in and out (more complex because it's harder to determine the size you should have your point).
  2. Draw a sphere or a cube, this will have a volume and will change size correctly as you zoom in and zoom out.
\$\endgroup\$
  • \$\begingroup\$ The size of the point is proportional to the zoom amount, what do you mean by that its more complex? \$\endgroup\$ – Christo Mar 19 '15 at 21:17
  • \$\begingroup\$ @CodingChief I mean that you will have to decide the size of the point depending on the distance the camera is from it, and update it each frame based on that. For instance, if you're really close to it, you might want to decide to have it very big (the whole screen?), and if you're very far, you'll want to put it very small... one pixel. Now on what do you base the size of the point so that it doesn't look weird? This is where the main issue comes from (IMHO), and that's why I would just create a box, put it in place and forget about it (option 2.). \$\endgroup\$ – Alexandre Vaillancourt Mar 19 '15 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.