LDraw.org Discussion Forums

Full Version: Simple renderer in .net with SharpGL (openGL)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6
Header files are just the thing that makes functions from external dll's visible/usable inside your language, so they them self need to be visual basic in your case. But when you use them they supply access to functions like 'glBegin', glDrawElemenets' etc etc . Those functions are identical no matter which language you use. So whenever an tutorial or example uses those functions you can use the same approach in any given language as long the basic OpenGL api functions are available (though language specific header files).

OpenTK seems to do just that but uses the vb function names (gl.begin instead of glBegin), but the principle remains the same, so you don't have to look for OpenTK specific tutorials, any OpenGL tutorial will do, just adjust the function names.

The intermediate mode lets you output individual points etc to make up triangles and quads etc, which is very slow / old fashioned. Modern OpenGL want's you to use buffers. When beginning with OpenGL you just as well jump right into using buffers and don't waste time understanding the old system.

As for the camera,lookat etc those are 'hidden' in the projection and modelview matrices, you can use api (glut) functions to initialize those.
Thanks for your information.

I had to leave openTK and now I am working with SharpGL (http://sharpgl.codeplex.com/) and I have my first 3D window.

Now I am trying to see something LDraw like in the window Smile

Currently I stay with the BEGIN and END structure as I understand that easily. As soon as I got that to work (my computer is fast) I'll ask for the buffers and how to use them.
It is very frustrating Sad(

I have a sample code that works, I can see a triangle and a box.

If I substitude the code for that two objects with the code for a part, I see - nothing.

At present I have no clue what I am doing wrong. Sad
Ok, i have my first - very little - success. I see now the lines. But why do i not see the triangles?
If you're sure they are inside the camera's view, it's probably because of the winding.

glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);

will enable two sided rendering for all polly's
Thanks for the tip, i'll try that.
But it was something different - stupid me. I did not draw the quads (divided into triangles) also. And at a 3005 there are many quads.

I added that, but I can not see any difference as all faces are black.

I have already set the color gl.Color(0, 100, 0) but also this results in black.

Maybe I have to make some light on?

I added also:
gl.Light(SharpGL.Enumerations.LightName.Light0, SharpGL.Enumerations.LightParameter.Ambient, 1)
gl.Light(SharpGL.Enumerations.LightName.Light1, SharpGL.Enumerations.LightParameter.Diffuse, 1)
but no change in the picture Sad

By the way, the best tutorial so far (in german language) is http://www.3dsource.de/faq/index.htm
I would suggest keeping lighting disabled until you can see proper geometry. Lighting should be disabled by default, and if it is, then things should show up in the color they're drawn in. However, I believe that glColor() only works as expected if you use glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE) and glEnable(GL_COLOR_MATERIAL).
Thanks to all for your help.

Currently I do not exactly what the reason is, but if you use glcolor I have to append a "F" at the number and then the wanted color is drawn.
I have never been aware of that possibility, but that was the only difference to other codes that seems to work.

gl.Color(100, 0, 0) -> shows only black surfaces
gl.Color(100.0F, 0.0F, 0.0F) -> shows the desired surface color

Now I know why! If I enter just a number then it is assumed to be an integer instead a single value.
I know from LDraw that we use RGB values in the range 0 to 255 and so I entered that numbers. But that seems to be wrong!

Maybe someone with more knowlage about this issue can write one or two lines here for others and me to explain why this is this way.
Also make sure you don't forget


just before you start drawing stuff (every frame).

Also if you found a tutorial source, I'm sure they offer a basic render loop example which would take care of setting defaults for camera, materials and lighting etc.
OpenGL uses 0..1 values for most stuff, The api functions have variations indicating the type of the parameters e.g. glColor3f or glColor3d . If the vb wrappers are hiding this, a mistake is made very quickly indeed.

I use this class function to get the float values for OpenGL from LDraw lines.

void init(const unsigned int rgb, const unsigned char alpha=255) {
  r=(float)((rgb & 0xFF0000) >> 16)/255.0;
  g=(float)((rgb & 0xFF00) >> 8)/255.0;
  b=(float)(rgb & 0xFF)/255;
Pages: 1 2 3 4 5 6