Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Trying to set VBO:s in C# using TAO / OpenGL TK framework


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
14 replies to this topic

#1 JulianAssange   Members   -  Reputation: 100

Like
0Likes
Like

Posted 16 November 2010 - 06:47 AM

Hello! I'm trying to set my vertices, indices and texture points to VBO:s and the draw them with my draw method, all this in C# under TAO/OpenGL TK framework. But my screen shows only a black screen. I've tested without VBO:s, and then it works. But with my vertices, indices and texture points I can't success.

My code:

private float[] vertices;
private byte[] indices;
private float[] texture;

private int[] mVertexBuffer;
private int[] mIndicesBuffer;
private int[] mTextureBuffer;

//...Constructor start
vertices = new float[] {
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,

1.0f, -1.0f, 1.0f,
1.0f, -1.0f, -1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, -1.0f,

1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,
1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,

-1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, 1.0f,

-1.0f, -1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, 1.0f,

-1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, -1.0f,
1.0f, 1.0f, -1.0f,
};

texture = new float[] {
0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f,

0.0f, 1.0f,
1.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f,

0.0f, 1.0f,
1.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f,

0.0f, 1.0f,
1.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f,

0.0f, 1.0f,
1.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f,
};

indices = new byte[] {
0, 1, 3, 0, 3, 2, 4, 5, 7, 4, 7, 6,
8, 9, 11, 8, 11, 10,
12, 13, 15, 12, 15, 14,
16, 17, 19, 16, 19, 18,
20, 21, 23, 20, 23, 22,
};

mVertexBuffer = new int[1];
mIndicesBuffer = new int[1];
mTextureBuffer = new int[1];

//...Constructor end

public void setBuffers() {
gl.glGenBuffersARB(1, mVertexBuffer);
gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, mVertexBuffer[0]);
gl.glBufferDataARB(GL.GL_ARRAY_BUFFER_ARB,
(IntPtr)(vertices.Length * sizeof(float)),
vertices, GL.GL_STATIC_DRAW_ARB);

gl.glGenBuffersARB(1, mIndicesBuffer);
gl.glBindBufferARB(GL.GL_ELEMENT_ARRAY_BUFFER_ARB, mIndicesBuffer[0]);
gl.glBufferDataARB(GL.GL_ELEMENT_ARRAY_BUFFER_ARB,
(IntPtr)(indices.Length * sizeof(float)),
indices, GL.GL_DYNAMIC_DRAW_ARB);

gl.glGenBuffersARB(1, mTextureBuffer);
gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, mTextureBuffer[0]);
gl.glBufferDataARB(GL.GL_ARRAY_BUFFER_ARB,
(IntPtr)(texture.Length * sizeof(float)),
texture, GL.GL_STATIC_DRAW_ARB);
}

public void draw()
{
gl.glBegin(gl.GL_TRIANGLES);

gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY);

gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, mVertexBuffer[0]);
gl.glVertexPointer(3, GL.GL_FLOAT, 0, mVertexBuffer);
gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, mTextureBuffer[0]);
gl.glTexCoordPointer(2, GL.GL_FLOAT, 0, mTextureBuffer);

gl.glBindBufferARB(GL.GL_ELEMENT_ARRAY_BUFFER_ARB, mIndicesBuffer[0]);

gl.glDrawElements(GL.GL_TRIANGLES, indices.Length,
gl.GL_UNSIGNED_BYTE, mIndicesBuffer);

gl.glDisableClientState(GL.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY);
gl.glEnd();

}
The vertices/indices/texture points works in my C++ VBO enviroment, but not here. So I'm guessing I had missed something with the bind stuff.

Thanks in advance! Any help would be appreciated!

[Edited by - JulianAssange on November 19, 2010 1:39:30 PM]

Sponsor:

#2 karwosts   Members   -  Reputation: 840

Like
0Likes
Like

Posted 16 November 2010 - 07:00 AM

Your VBO code looks right to me from an OpenGL perspective (don't know anything about C# though). You've tested this on the exact same platform using immediate mode with these vertices and got it to work?

Also a minor issue but you're defining your index buffer as indices.length * sizeof(float), you probably want it to be sizeof(byte). I don't think that would cause your problem though.

#3 JulianAssange   Members   -  Reputation: 100

Like
0Likes
Like

Posted 16 November 2010 - 07:04 AM

Quote:
Original post by karwosts
Your VBO code looks right to me from an OpenGL perspective (don't know anything about C# though). You've tested this on the exact same platform using immediate mode with these vertices and got it to work?

Also a minor issue but you're defining your index buffer as indices.length * sizeof(float), you probably want it to be sizeof(byte). I don't think that would cause your problem though.


Yep, it works perfect in my mobile enviroment.

This is really confusing; I've worked on this specific problem in some days now...

Do you think that it could be any problem with the indices buffer when I'm binding it in my draw function? That was a part I added on my own.

#4 karwosts   Members   -  Reputation: 840

Like
0Likes
Like

Posted 16 November 2010 - 07:09 AM

Ideas:

Can you just draw a single triangle without indices? (glDrawArrays)
If that works, can you then draw your triangle using trivial indices (indices = {0,1,2}).

Doing that should help you narrow down your problem.


#5 JulianAssange   Members   -  Reputation: 100

Like
0Likes
Like

Posted 16 November 2010 - 07:18 AM

I'm not really sure with what you mean with trivial indices, however, now I've tried this (with changes from previous code):

...
//gl.glBindBufferARB(GL.GL_ELEMENT_ARRAY_BUFFER_ARB, mIndicesBuffer[0]);


gl.glDrawArrays(GL.GL_TRIANGLES, 0, vertices.Length);
//gl.glDrawElements(GL.GL_TRIANGLES, indices.Length, GL.GL_UNSIGNED_BYTE, mIndicesBuffer);
...

and I have also shorten down my vertices float to 3 faces like this:

-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,


#6 karwosts   Members   -  Reputation: 840

Like
0Likes
Like

Posted 16 November 2010 - 07:23 AM

I'm assuming that your single triangle is still not working?

Trivial indices I just meant keep the same triangle vertices, but instead of glDrawArrays, use glDrawElements, but assign your indices to be (0,1,2). It should be the same as glDrawArrays, but just a chance to flush out anything you had wrong with your indices array setup.

#7 karwosts   Members   -  Reputation: 840

Like
0Likes
Like

Posted 16 November 2010 - 07:24 AM

Also, are you checking for errors? (glGetError)

#8 JulianAssange   Members   -  Reputation: 100

Like
0Likes
Like

Posted 16 November 2010 - 07:25 AM

Quote:
Original post by karwosts
I'm assuming that your single triangle is still not working?

Trivial indices I just meant keep the same triangle vertices, but instead of glDrawArrays, use glDrawElements, but assign your indices to be (0,1,2). It should be the same as glDrawArrays, but just a chance to flush out anything you had wrong with your indices array setup.


Oh yes, I forgot. :) It's still not working.


#9 JulianAssange   Members   -  Reputation: 100

Like
0Likes
Like

Posted 16 November 2010 - 07:27 AM

Quote:
Original post by karwosts
Also, are you checking for errors? (glGetError)


I did this before, but not now. When I had problem to set the VBO (not drawing them) it throwed me an exception. When I got it to work (with setting the VBO, not drawing them) and got a black screen I just assumed that I've got no error and I was almost sure I've missed something between the lines.



#10 JulianAssange   Members   -  Reputation: 100

Like
0Likes
Like

Posted 16 November 2010 - 08:49 AM

Hm, I can't still figure this out. I have a feeling that it is the indices buffer of some kind that mess this up.

Really stuck here, though.

#11 Gorg   Members   -  Reputation: 248

Like
0Likes
Like

Posted 17 November 2010 - 06:32 AM

You are passing GL_UNSIGNED_BYTE to your glDrawElements call but your index buffer is byte. Maybe that's causing the problem?

EDIT: I missed the part where you used DrawArrays. So unsigned/signed cannot be your problem completely.

#12 JulianAssange   Members   -  Reputation: 100

Like
0Likes
Like

Posted 17 November 2010 - 05:23 PM

Quote:
Original post by Gorg
You are passing GL_UNSIGNED_BYTE to your glDrawElements call but your index buffer is byte. Maybe that's causing the problem?

EDIT: I missed the part where you used DrawArrays. So unsigned/signed cannot be your problem completely.


Thanks for posting, will try to change to GL_BYTE later today.

Any other ideas?



#13 JulianAssange   Members   -  Reputation: 100

Like
0Likes
Like

Posted 18 November 2010 - 08:30 AM

Nope, the change to GL_BYTE didn't solve it....

There must be something strange in all this...

#14 Gorg   Members   -  Reputation: 248

Like
1Likes
Like

Posted 18 November 2010 - 10:10 AM

I haven't used glVertexPointer in a long time, but that looks odd

gl.glVertexPointer(3, GL.GL_FLOAT, 0, mVertexBuffer);

Shouldn't that be gl.glVertexPointer(3, GL.GL_FLOAT, 0, 0)

As far as I remember since you bind buffers the last parameter should be the start index inside the bound buffer. Since your are passing mVertexBuffer, the offset will be off by whatever number your buffer is.

The same thing applies to your glTexCoordPointer call and glDrawElements.

#15 JulianAssange   Members   -  Reputation: 100

Like
0Likes
Like

Posted 18 November 2010 - 05:24 PM

Quote:
Original post by Gorg
I haven't used glVertexPointer in a long time, but that looks odd

gl.glVertexPointer(3, GL.GL_FLOAT, 0, mVertexBuffer);

Shouldn't that be gl.glVertexPointer(3, GL.GL_FLOAT, 0, 0)

As far as I remember since you bind buffers the last parameter should be the start index inside the bound buffer. Since your are passing mVertexBuffer, the offset will be off by whatever number your buffer is.

The same thing applies to your glTexCoordPointer call and glDrawElements.


Thanks, will test this soon...






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS