# OpenGL c# and OpenGL

## Recommended Posts

Im looking for a tutorial on implimenting openGL into c#. I DONT want to use all the precompiled dlls and libs im finding like CsGL and TAO and such. Im looking for an understanding of doing it myself. If anyone can shed some light on this i would appriciate it.

##### Share on other sites
You can import DLL functions in C#, which is how you would access OpenGL without a 3rd party library.

##### Share on other sites
I don't use tao either, as it's enormous. I prefer to just create bindings to opengl functions as I need them. It's easy:

public enum DrawMode : int{    Points = 0x00000000,    Lines = 0x00000001,    LineStrip = 0x00000003,    LineLoop = 0x00000002,    Triangles = 0x00000004,    TriangleStrip = 0x00000005,    TriangleFan = 0x00000006,    Quads = 0x00000007,    QuadStrip = 0x00000008,    Polygon = 0x00000009}public sealed class gl{    private const string GLLIB = "OpenGL32.dll";    [DllImport( GLLIB, EntryPoint = "glBegin" ), SuppressUnmanagedCodeSecurity]    public static extern void Begin( DrawMode drawMode );}

##### Share on other sites
what about setting up the pixel format. And you would have to import every single function you will be using? Does anyone have an example app. somewhere on the net i could browse?

##### Share on other sites
You may have to import all of the functions related to GDI/DCs from the Windows DLLs that they are stored in. However, if you can somehow get a context from a form window by using some .NET method, then that would save a bit of work.

Yes, you have to import every function that you plan to use.

CsGL's source code is available from their sourceforge page, including the part where one sets up the window format. Of course, if you model your source after theirs, it would only be proper to credit them for that.

gl.h and glext.h have all of the enums listed, like shown in gharen2's post for the basic primitive types.

I admire you for your bravery. This is the very reason why I "wimped out" and went with TAO when using C#. :)

##### Share on other sites
Yes you'll have to import every function, but once you've done it a few times it's easy, and you only have to do it once per function. Creates a nice little growing library of imports you can reuse elsewhere.

If you want to speed up the process a bit, don't do it the way I did. Just setup constants instead of pretty c# enums. I only made them enums because a) it's prettier [smile] and b) it prevents you from using the wrong constant in a function (for example, GL_LINES versus GL_LINE).

As taby said, all you'd have to do is look at the source of gl.h and import each function as I did. There's some that are trickier, such as glGetStrings: the .net framework isn't smart enough to convert the returned value to a string, so you have to do it yourself.

Window initialisation is trickier, you can either setup imports for the appropriate win32 functions, which you can find in many opengl samples online. Or you can use SDL to do it for you.

And yes, you can use opengl in a windows form or control. All opengl needs is a handle to a window, which the Form.Handle property supplies you.

Oh, and you can use Marshal.GetDelegateForFunctionPointer to setup opengl extensions.

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627654
• Total Posts
2978450
• ### Similar Content

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange(), which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.
• By cebugdev
hi guys,
are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic
let me know if you guys have recommendations.
• By dud3
How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below?
Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.

References:
Code: https://pastebin.com/Hcshj3FQ
The video shows the difference between blender and my rotation:

• By Defend
I've had a Google around for this but haven't yet found some solid advice. There is a lot of "it depends", but I'm not sure on what.
My question is what's a good rule of thumb to follow when it comes to creating/using VBOs & VAOs? As in, when should I use multiple or when should I not? My understanding so far is that if I need a new VBO, then I need a new VAO. So when it comes to rendering multiple objects I can either:
* make lots of VAO/VBO pairs and flip through them to render different objects, or
* make one big VBO and jump around its memory to render different objects.
I also understand that if I need to render objects with different vertex attributes, then a new VAO is necessary in this case.
If that "it depends" really is quite variable, what's best for a beginner with OpenGL, assuming that better approaches can be learnt later with better understanding?

• 10
• 12
• 22
• 13
• 33