Jump to content
  • Advertisement
Sign in to follow this  
lemon

OpenGL glDrawArrays() - BSoSS

This topic is 2851 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm not completely angry yet! haha... but still.

Every search I've looked for on VertexArrays (withOUT VBO's) always has some glBindBuffers... (which means VBO's) or some other madness (like searching for glDrawArray examples... which give glDrawElement examples...).

Unfortunately, a few search hits led me here, and I was still left looking for an answer. (And yes, I did read the Forum FAQ, just in case this type of question was common enough to hit the list. Alas, it was not so. I'm hoping I'm still following the rules/guidelines by posting this. If not.. please feel free to show me the err of my ways.)

So, now, I am asking for help on attempting to find an answer that allows my OpenGL screen to stop displaying the black screen of silent screams (BSoSS).

Here's what I've got (working): Immediate mode (small fry stuff, generally colors and vertices). Using simple objects, like Vertex3F and Color3F.

My next step was going to Vertex (and Color) Arrays. Moving from just a Vertex3F to a VertexFArray<Vertex3F>, and similarly for Color3F. Instead of just drawing them out with a bunch of glVertex3f() calls, I went for the kill of pointers.

Now, keep in mind, I'm using C# (2008) and no framework like OpenTK or Tao. Used a couple of DllImports, the rest through delegate magic and GetProcAddress from kernel32 (not wglGetProcAddress - it fails on trying to find glBegin).

Here's a sample declaration for the glVertexPointer() function:

Relevant portion of my 'OpenGL' static class:

private static OpenGL32 opengl;
public static void init()
{
opengl = new OpenGL32();
}
.
.
.
public static void glVertexPointer(int size, DataTypes type, int stride, IntPtr pVertices)
{
opengl.VertexPointer(size, type, stride, pVertices);
}


The loading portion of my 'OpenGL32' class (extends a DynamicLibrary class, which does the actual loading)


private delegate void glVertexPointer(int size, DataTypes type, int stride, IntPtr pVertices);
public void VertexPointer(int size, DataTypes type, int stride, IntPtr pVertices) { this["VertexPointer"].call(size, type, stride, pVertices); }

public OpenGL32()
: base("opengl32")
{
if (loaded)
{
.
.
.
load<glVertexPointer>("glVertexPointer", "VertexPointer");
.
.
.
}
}


Yes, I know. C# doesn't particularly like pointers. So I tried the unsafe option, combined with the void* pointer pointing. Turns out, the value is the same as the IntPtr anyways, and since the glVertexPointer() function loads properly (the address (accepting an IntPtr pVertices parameter) is not 0), it doesn't make any difference either way. If it did, I'd let you know, but I did try both ways.

And this is how my drawing routine works. (Background: it's an Scene object that basically calls any IPrimitive-constrained object's draw() function as part of the Scene's draw() function, plus any rotations that may need to occur):


public void draw()
{
OpenGL.glEnableClientState(ClientStates.GL_VERTEX_ARRAY);
OpenGL.glEnableClientState(ClientStates.GL_COLOR_ARRAY);

OpenGL.glColorPointer(3, DataTypes.GL_FLOAT, 0, tColors.pointer);
OpenGL.glVertexPointer(3, DataTypes.GL_FLOAT, 0, tVertices.pointer);
OpenGL.glDrawArrays(BeginModes.GL_TRIANGLES, 0, 1);

OpenGL.glDisableClientState(ClientStates.GL_VERTEX_ARRAY);
OpenGL.glDisableClientState(ClientStates.GL_COLOR_ARRAY);
}


Since the Color and Vertex components are in separate arrays (and tightly packed), I left stride at 0. And I've also tried setting the stride to sizeof(float) * 3, to no avail (same BSoSS, whining sound from graphics card).

I do have various Vertex(Count)(Type) - ie: Vertex3F and Color(Count)(Type) - ie: Color3F types, and in their respective Array objects, the data arrays (ie: float[] data) are setup accordingly.

On top of that, I've used Visual Studio's Memory viewer to verify that the pointers do indeed point to the right structures (containing the actual color and vertex values.

I've tried to use GLIntercept to create logs, but after following the directions, and updating the OpenGL32 constructor's base argument to include the Environment.CurrentDirectory statement, it actually failed to load the OpenGL32.dll supplied by the GLIntercept debugger utility. So I couldn't use that to see if anything internally was screwing up, or if the pointer I was passing to the glVertexPointer() or glColorPointer() functions were becoming corrupted.

So, I'm pretty lost at what to try to do next in order to see something besides the darkness in a window. (I did make sure to override the refresh() function of my Window class in the OpenGLWindow class to not send WM_PAINT messages, instead to let OpenGL do all the work. At the end, of course, is the obligatory(?) wglSwapBuffers() call.

If you (the reader who takes pity on my plight) have any ideas or suggestions (up to, including, and even past "ur doin it wrong!"), I'd be glad to try them out. As long as they don't include using a different language. That might have to wait until next summer.

If you, the reader who elects not to take pity, I will not dock points. I'm still newer to this stuff, and I decided a while ago not to do XNA/DirectX with C#. I went with OpenGL for the reason of learning OpenGL in the language (C#) that pays my bills at the current time. When I am free to do as I please (ie: work on game engines and get paid for it), I will have the OpenGL experience that is (generally) portable to another language/platform.

Either way, thanks for viewing! Maybe I'll tame this beast one day... ^_^

Share this post


Link to post
Share on other sites
Advertisement
The third parameter of glDrawArrays is the number of vertexes, not the number of triangles, so you should be using:
OpenGL.glDrawArrays(BeginModes.GL_TRIANGLES, 0, 3);

Admittedly, the terminology in the OpenGL documentation certainly doesn't help much here either.

Share this post


Link to post
Share on other sites
Quote:
Original post by mhagain
The third parameter of glDrawArrays is the number of vertexes, not the number of triangles, so you should be using:*** Source Snippet Removed ***
Admittedly, the terminology in the OpenGL documentation certainly doesn't help much here either.


I missed testing that part in my OP. However, I'll keep the vertexCount version, thanks!

Although, still a black screen.

Hmm. let me go play with the depth's again. I had an issue earlier playing with Immediate mode that stemmed from there.

Share this post


Link to post
Share on other sites
Quote:
Original post by lemon
Quote:
Original post by mhagain
The third parameter of glDrawArrays is the number of vertexes, not the number of triangles, so you should be using:*** Source Snippet Removed ***
Admittedly, the terminology in the OpenGL documentation certainly doesn't help much here either.


I missed testing that part in my OP. However, I'll keep the vertexCount version, thanks!

Although, still a black screen.

Hmm. let me go play with the depth's again. I had an issue earlier playing with Immediate mode that stemmed from there.


I hate myself.

It was the depths.

Thanks for your help though mhagain :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!