croman102's picture

OpenGL doesn't show anything

I am slowly moving my project from tao to opentk. I was using Gl.gldrawArrays (Gl.GL_TRIANGLES, 0, size), and that worked with tao. When I switched to opentk, that won't work. I tried to change all of tao calls to opentk ( GL.DrawArrays(BeginMode.Triangles, 0, size ); ...), but it won't work. It just draws empty background (clear) color. I had two scenes in my program, in the first one, there was about 500FPS (FRAPS), and in the other about 160FPS. I was switching between those scenes with a keyboard. When I start my program fps is about 550 (maybe because opentk is faster than tao?), and when i switch the 2nd scene it is about 200, so it is taking some time to render more complicated 2nd scene. I have tried few texture loading snippets that i found here, I think that loading textures works. Please help.

Thank you.


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

It is difficult to guess what might be wrong without more information, but check these:

  1. GL.Color(1, 1, 1) will map to GL.glColor3i(1, 1, 1) and will draw in black, not white! Use floating-point parameters explicitly GL.Color(1.0f, 1.0f, 1.0f) or use predefined colors GL.Color(Color.White). This is a very common issue when porting from Tao.
  2. Call GL.GetError() to see that you are not generating any OpenGL errors. If you get something back, compile a debug version of OpenTK.dll and link that into your application - this will give you an exception as soon as an OpenGL errors occurs, which is immensely helpful when debugging.

The difference in framerate might be caused by using a different windowing library (OpenTK.GameWindow vs Tao.Sdl or Tao.Glfw) or by better tuned OpenGL bindings (generics vs 'object' overloads).

croman102's picture

Thank you
Gl.geterror returns error 1280

if i change background color to any other, it just show that color

Thank you again

croman102's picture

This is output when I try to run my program with opentk debug version.

A first chance exception of type 'System.DllNotFoundException' occurred in OpenTK.dll
A first chance exception of type 'System.TypeInitializationException' occurred in OpenTK.dll
'program.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'program.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Detected configuration: Windows / .Net
A first chance exception of type 'System.DllNotFoundException' occurred in OpenTK.dll
DisplayDevice 1 (primary) supports 204 resolutions.
Creating default GraphicsMode (32, 16, 0, 0, 0, 2, False).

Creating GraphicsContext.
Creating GraphicsContext.
Device context: 889264165
Selecting pixel format...
GraphicsMode: Index: 2, Color: 32 (8888), Depth: 24, Stencil: 8, Samples: 0, Accum: 0 (0000), Buffers: 2, Stereo: False
IWindowInfo: Windows.WindowInfo: Handle 133118, Parent (Windows.WindowInfo: Handle 133120, Parent (null))
GraphicsContextFlags: Default
Requested version: 1.0
Loaded opengl32.dll: 422969344
OpenGL will be bound to handle: 133118
Setting pixel format... 2
Creating temporary context for wgl extensions.
Load extensions for OpenTK.Platform.Windows.Wgl... 60 extensions loaded in 8 ms.
Load extensions for OpenTK.Platform.Windows.Wgl... 60 extensions loaded in 0 ms.
Using WGL_ARB_create_context... success!
success! (id: 131072)
Selecting pixel format (ARB)... success!
Disposing context 131072.
Destroying window: Windows.WindowInfo: Handle 133120, Parent (null)
GraphicsMode: Index: 2, Color: 32 (8888), Depth: 24, Stencil: 8, Samples: 0, Accum: 0 (0000), Buffers: 2, Stereo: False
IWindowInfo: Windows.WindowInfo: Handle 133122, Parent (null)
GraphicsContextFlags: Default
Requested version: 1.0
OpenGL will be bound to handle: 133122
Setting pixel format... 2
Using WGL_ARB_create_context... success!
success! (id: 196608)
Load extensions for OpenTK.Platform.Windows.Wgl... 60 extensions loaded in 0 ms.
Loading extensions for OpenTK.Graphics.OpenGL.GL... 1900 extensions loaded in 178.8357 ms.

It is still just background color.
There is no 1280 error anymore.

Thank you!

Seven's picture

Seven

Hey, it sounds like you're just needing an example of how to use DrawArrays() correctly (with all the buffers set). I am working on a project called "SevenEngine" and my DrawArrays() function is correctly drawing to the screen. Don't judge my code, I just started writing it last week, but check our the ----SUBMODEL---- functions in "Submodel.cs" and "Renderer.cs" if you wish. Code is on github, username 53V3N1X project SevenEngine. Hope it helps good luck.

croman102's picture

Thank you

I have just completely disabled my game code, my model and texture loading part and tried to use code from examples (Immediate mode, spinning cube) and it still doesn't show anything. The simplest GL.Begin(BeginMode.Quads); doesn't work. Could it be problem with swapping buffers (there is option under simpleOpengGlControl (tao) to do that automatically, maybe it doesn't work in opentk).

Thank you all again, sorry for my poor English.

ddnohn's picture

thanks all

Obat Herbal

emacinnes's picture

If you're using glControl, you need to manually swap buffers, there's no automated one for that, because the glControl doens't work off a timer, and Swapbuffers may be an inappropriate action under certain circumstances. This is assuming you are using the glControl for this, have overridden the OnPaint event, and also call control.Invalidate() so that Windows.Forms causes a redraw.

Cheers,

Euan

Icarus Scene Engine 3.1. OpenTK-based 3D simulation & games solution, for Win, Linux, Mac, iOS, Droid:
http://icarus.pointscape.com.sg

See Icarus videos on Youtube

croman102's picture

Is there something wrong with this code, it works with TAO.

private void SetupGraphic(double width, double height)
        {
            double halfWidth = width / 2;
            double halfHeight = height / 2;
            Gl.glMatrixMode(Gl.GL_PROJECTION);
            Gl.glLoadIdentity();
            Glu.gluPerspective(60, (width / height), 1, 100000);
            //Gl.glOrtho(-halfWidth, halfWidth, -halfHeight, halfHeight, -100, 100);
            Gl.glMatrixMode(Gl.GL_MODELVIEW);
            Gl.glLoadIdentity();
        }

I cannot draw a simple triangle

This is looping part of the code

GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.ClearColor(System.Drawing.Color.Red);
            Matrix4 lookat = Matrix4.LookAt(0, 5, 5, 0, 0, 0, 0, 1, 0);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadMatrix(ref lookat);
 
            angle += rotation_speed * (float)elapsedTime;
            GL.Rotate(angle, 0.0f, 1.0f, 0.0f);
 
            GL.Begin(BeginMode.Quads);
 
            GL.Color3(1, 1, 1);
            GL.Vertex3(-1.0f, -1.0f, -1.0f);
            GL.Vertex3(-1.0f, 1.0f, -1.0f);
            GL.Vertex3(1.0f, 1.0f, -1.0f);
            GL.Vertex3(1.0f, -1.0f, -1.0f);
 
 
 
            GL.Color3(1, 1, 1);
            GL.Vertex3(-1.0f, -1.0f, -1.0f);
            GL.Vertex3(1.0f, -1.0f, -1.0f);
            GL.Vertex3(1.0f, -1.0f, 1.0f);
            GL.Vertex3(-1.0f, -1.0f, 1.0f);
 
 
 
            GL.Color3(1, 1, 1);
 
            GL.Vertex3(-1.0f, -1.0f, -1.0f);
            GL.Vertex3(-1.0f, -1.0f, 1.0f);
            GL.Vertex3(-1.0f, 1.0f, 1.0f);
            GL.Vertex3(-1.0f, 1.0f, -1.0f);
 
 
 
            GL.Color3(1, 1, 1);
            GL.Vertex3(-1.0f, -1.0f, 1.0f);
            GL.Vertex3(1.0f, -1.0f, 1.0f);
            GL.Vertex3(1.0f, 1.0f, 1.0f);
            GL.Vertex3(-1.0f, 1.0f, 1.0f);
 
 
 
            GL.Color3(1, 1, 1);
            GL.Vertex3(-1.0f, 1.0f, -1.0f);
            GL.Vertex3(-1.0f, 1.0f, 1.0f);
            GL.Vertex3(1.0f, 1.0f, 1.0f);
            GL.Vertex3(1.0f, 1.0f, -1.0f);
 
 
 
            GL.Color3(1, 1, 1);
            GL.Vertex3(1.0f, -1.0f, -1.0f);
            GL.Vertex3(1.0f, 1.0f, -1.0f);
            GL.Vertex3(1.0f, 1.0f, 1.0f);
            GL.Vertex3(1.0f, -1.0f, 1.0f);
 
            GL.End();
 
            GlControl1.Refresh;
            Glcontrol1.SwapBuffers;

Thank you

emacinnes's picture

Do you have the Invalidate() call? You need to call myGLControl.Invalidate() every ~330 ms if you want 30FPS. Without that, Windows does not invalidate the control, does not repaint it and your drawing routine never gets called. It would be more helpful if you could post your entire unit code so I can see the relevant stucture. I use glControl for my own engine, it does work, but it must be used correctly, it was a little more fiddly than the Tao one.

Cheers,

Euan

Icarus Scene Engine. OpenTK-based 3D simulation & games solution, for Win, Linux, Mac, iOS, Droid:
http://icarus.pointscape.com.sg

See Icarus videos on

croman102's picture

Ok, this is simplified view on my program.

public Form1()
      {
          InitializeComponent();
          //renderer.InitializeContexts();              ----- this line works with TAO
 
 
          Il.ilInit();
          Ilu.iluInit();
          Ilut.ilutInit();
          Ilut.ilutRenderer(Ilut.ILUT_OPENGL);
 
 
 
          SetupGraphic(ClientSize.Width, ClientSize.Height); // see my previous post
          if (_fullscreen)
          {
              FormBorderStyle = FormBorderStyle.None;
              WindowState = FormWindowState.Maximized;
          }
          else
          {
              ClientSize = new Size(1280, 720);
          }
 
 
      }

And then here is my looping part:

void Loop(double time)
      {
          // GLControl.Invalidate();  --- didn't help here
          Update(time); //updates code from my previous post
          GlControl.Refresh();
          GLControl.SwapBuffers();
          // GLControl.Invalidate();  --- or here
      }

Thank you for help

p.s. you Icarus Scene Engine is really nice, I like it