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.
emacinnes's picture

Thanks!

As a worked example, because I can't see how you link to the glcontrol in the code, let's say you have the following:

GLControl myControl;
System.Windows.Forms.Timer myTimer;

and those are declared and created etc..

Then you need to do the following:

myControl.Paint += (object sender, System.Windows.Forms.PaintEventArgs e) =>
{
    myControl.MakeCurrent();
    Render();
   myControl.SwapBuffers();
};
 
 
 myTimer.Enabled = true;
 myTimer.Interval = 33;
 myTimer.Tick += (object sender, EventArgs e) =>
{
 myControl.Invalidate();
}

You'll need to track the passage of time in the Render() function using a System.Diagnostics StopWatch, the GLControl doesn't have that.

The lambda expressions are used just to make the code shorter, you can use regular events too, just double-click on the Paint event in Visual Studio, same for the Timer's Tick.

NOTE: The MakeCurrent is crucial if you use multiple GLControls on the form, otherwise the control rendering gets mixed up and results in one will bleed into the other, or they'll corrupt each other.

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

There is only one GLControl.
Using makeCurrent() didn't help.

I guess that GLControl think is OK. If I try to use GL.ClearColor(), it show's the last color I set.

emacinnes's picture

Where is your Viewport set up?

You'll need a GL.Viewport(0,0,GlControl1.Width, GlControl1.Height);

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

I use this in ClientSizeChanged function
Gl.glViewport(0, 0, this.ClientSize.Width, this.ClientSize.Height);

Thank you

emacinnes's picture

There's two ways I can help going forward:

1) Can you post your entire test project so that it can be stepped through? It's very slow to just be seeing part of the code, and I have to then assume that the unseen parts don't contain the right stuff, or in the wrong place, there are so many things that can be wrong here. You can email it to me directly if you don't want it to be public. euan.macinnes@pointscape.com.sg, just please ensure that it compiles and runs, though it doesn't "work".

2) Wait till next week so I have time to put together some working examples for you to step through. I don't have a separate OpenTK-only example to just hand over, my Icarus-based one overrides the OpenTK control and manages the issues like frame rate and redrawing.

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 Youtube