This project is read-only.

OpenGL control

Jun 23, 2014 at 9:32 AM
Dear, question:

Can i call directly the openGL, taking the gl from his control ?

OpenGL gl = (OpenGL)openGLControl.Content;

Jun 23, 2014 at 5:34 PM
Edited Jun 23, 2014 at 5:34 PM
If you use MS Visual C#.Net Express, you can open a new project and in the templates, select the ONLINE templates... From there, look in the top right and you'll see a box you can type in. Put SharpGL in that box and the middle list will populate with SharpGL. Forming a program based on that template will give you a project that includes all the necessary references and DLLs included. It will also give you a form with the SharpGL control placed on it (which the first thing I did was turn on the DisplayFPS, increased the desired frame rate to 1000 and placed the Dock style to FILL so that it would fill the form).

In the code, you'll have several functions already made...

When the form loads, it initializes the controls on it, which initializes the SharpGL control. When it's done initializing, it will call the Initialized() function, so this is where you do your initial GL setup like loading your textures, enabling your various states and getting ready to render your scene.

Once the control is running, it will load up a timer that fires at an interval based on the FrameRate setting. The control will attempt to achieve the selected FrameRate value, but I've seen where I put in 60 and get 30-40FPS consistently. Upping it to 1000 yields 64-70FPS as determined by a typical frame rate counter algorithm that is also backed up by FRAPS (which puts a frame rate counter on just about anything) with the same results as my FPS algorithm.

When you resize the control (not the form, the control itself - happens automatically on form-resize if the control is filling the form or it's container), the Resized() function is called which is where you will set up your viewport based on the size and shape of the control. When the control first initializes, it calls Resized() for the initial setup of the viewport just prior to the first call to Draw();

The basic package in C# Express worked great as a starting point. Mostly, any code written in C++ can be used in C#, the only difference being when you see a call to glBegin, glEnd, glTranslate or anything that starts with gl and a name, you simply put a "." after the gl (the base code declares a "gl" variable that is set to the control's OpenGL context which is what you'll use to draw) and any enumeration variables like GL_LINE_SMOOTH_HINT or GL_TEXTURE_2D or GL_DEPTH_TEST just have to have a "OpenGL." first so the examples I just put out there would be OpenGL.GL_LINE_SMOOTH_HINT, OpenGL.GL_TEXTURE_2D and OpenGL.GL_DEPTH_TEST.

If you're new to OpenGL, this may not be the right place to ask about how to program. There are other sites more dedicated to learning and programming in OpenGL, but the implementation of OpenGL on C# is specific to SharpGL and this is the best place to ask the person who created it and anyone else who's had experience with it how one would go about making something work in SharpGL, but by far, most C++ code is almost directly usable straight off any site you get it from after you make the "gl." or "OpenGL." modifications to the functions and parameters.