0

I wanted to know if writing points using a for loop in the begin end batch works or not, so I read up on a sphere algorithm and produced this based on my reading. There are some problems with it as you can see below in the output screen capture. My goal is to produce a sphere procedurally and then modify it at runtime.

but I would like to set my goal on the short-term and figure out why the faces are not correct. anyone have any ideas?

I've got this code:

private void openGLControl_OpenGLDraw(object sender, RenderEventArgs e)
    {
        //  Get the OpenGL object.
        OpenGL gl = openGLControl.OpenGL;

        //  Clear the color and depth buffer.
        gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

        //  Load the identity matrix.
        gl.LoadIdentity();

        //  Rotate around the Y axis.
        gl.Rotate(rotation, 0.0f, 1.0f, 0.0f);

        //Draw a ball
        //Drawing Mode
        gl.PolygonMode(SharpGL.Enumerations.FaceMode.FrontAndBack, SharpGL.Enumerations.PolygonMode.Lines);
        //ball fields
        double radius = 4.0d;
        const double DEGREE = Math.PI/11.25;
        double x = 0;
        double y = 0;
        double z = 0;
        // ball batch
        gl.Begin(OpenGL.GL_TRIANGLE_STRIP_ADJACENCY);
        for (double j = 0.0d; j < Math.PI; j = j +DEGREE)
        {

            for (double i = 0; i < 2 * Math.PI; i = i + DEGREE)
            {

                x = radius * Math.Cos(i) * Math.Sin(j);
                y = radius * Math.Sin(j) * Math.Sin(i);
                z = radius * Math.Cos(j);
                gl.Color(Math.Abs(x + y), Math.Abs(y + z), Math.Abs(z + x));
                gl.Vertex(x, y, z);
            }

        }
        gl.End();

        //  Nudge the rotation.
        rotation += 3.0f;
    }

A screen-cap of my output

  • 1
    What output do you currently get and what are you expecting? It looks like you are trying to draw triangles but you never update x and y, only z is updated, so all of the points of your triangles are co-linear. Also if you are only using one color for all of the vertices then you can put the call to gl.Color before the loop. – user3256930 Mar 18 '14 at 06:51
  • 1
    Yes, that's perfectly valid (why wouldn't it?). But do yourself a favor and stay away from immediate mode (glBegin…glEnd). Use Vertex Arrays, which are easier to use (in the long run) and provide much better performance. – datenwolf Mar 18 '14 at 11:10
  • user3256930 Thank you for your insight, I have had to set this project down for a long time, but I can see what you're saying by the way my output looks, but I am a bit confused about where the piece of code is that applies the update to z. I'm a beginner trying to take on complex stuff because that's just how I roll. – Monte Emerson Dec 31 '17 at 21:06

0 Answers0