Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nothing being rendered at all #212

Open
burdoto opened this issue Oct 4, 2022 · 2 comments
Open

Nothing being rendered at all #212

burdoto opened this issue Oct 4, 2022 · 2 comments

Comments

@burdoto
Copy link

burdoto commented Oct 4, 2022

Hello,
I'm already sure I'm doing something stupidly wrong, but this is extremely frustrating since I cannot locate the issue.

Basically I'm trying to draw ANYTHING using this Draw() method:

public const float lim = 1000;
private void Draw(object sender, OpenGLRoutedEventArgs args)
        {
            var gl = args.OpenGL;

            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.LoadIdentity();
            gl.LineWidth(10.0f);
            gl.PointSize(2.0f);

            gl.Color(1, 1, 1);

            // y axis
            gl.Begin(BeginMode.Lines);
            gl.Vertex(-lim, 0);
            gl.Vertex(lim, 0);
            gl.End();

            // x axis
            gl.Begin(BeginMode.Lines);
            gl.Vertex(0, -lim);
            gl.Vertex(0, lim);
            gl.End();


            for (int i = 0; i < 500; i++)
            {
                gl.Begin(BeginMode.TriangleFan);
                var Segments = 50;
                var radius = 1000;
                var Position = new Vector2(i, i);
                for (var a = 0; a < Segments; a++)
                {
                    float theta = 2f * MathF.PI * a / Segments;
                    float x = radius * MathF.Sin(theta);
                    float y = radius * MathF.Cos(theta);
                    gl.Vertex(Position.X + x, Position.Y + y);
                }
                gl.End();   
            }
            
            gl.Flush();
        }

But I'm only ever getting a black screen (with the FPS counter working fine).
I've tried comparing my code to this sample, but I really cannot find the problem.

As you can see from the code, I have already made desperate, frustrated attempts to draw large cirlces ANYWHERE, with no success whatsoever.
What am I missing?

@petals-of-white
Copy link

petals-of-white commented Nov 9, 2024

I have the exact same problem. It looks like none of gl.Draw* (* <- Elements, Arrays etc) functions have any effect. I've already checked the VAOs, VBOs and textures.
Tested using WPF, TargetFramework: net8.0-windows

@petals-of-white
Copy link

I've also noticed that OpenGL generates InvalidOperation error before each draw call.
Suppose this method is called each time OpenGLDraw event is raised for OpenGLControl.

    private void DicomGLViewer_OpenGLDraw(object sender, OpenGLRoutedEventArgs args)
    {
        if (GL is not null) OpenGLHelpers.ThrowIfGLError(GL);

        //while (gl.GetErrorCode() is not ErrorCode.NoError);

        GL?.Clear(OpenGL.GL_COLOR_BUFFER_BIT);
        glState?.DrawVertices(CurrentDepth);
    }

And ThrowIfGLError looks like this:

public static class OpenGLHelpers
{
    ...
    public static void ThrowIfGLError(OpenGL gl)
    {
        var error = gl.GetErrorCode();
        switch (error)
        {
            case ErrorCode.NoError:

                break;

            case (var other):
                throw new Exception(gl.GetErrorDescription(Convert.ToUInt32(other)));
        }
    }
}

It throws with 'Invalid Operation' OpenGL error
So this error occurs before doing anything.

My opengl initialization (after OpenGLInitialized event) doesn't produce any errors, so this is quite strange.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants