VBO c# tao framework

Started by
1 comment, last by Fiddler 14 years ago
At first sorry for my english :) I tried to write program, where I use the VBO. I've got: public void SetData() { state_ = true; vertex_ = new float[12]; texture_ = new float[8]; vertex_[0] = -5f; vertex_[1] = 0f; vertex_[2] = 0f; vertex_[3] = 5f; vertex_[4] = 0f; vertex_[5] = 0f; vertex_[6] = 5f; vertex_[7] = 5f; vertex_[8] = 0f; vertex_[9] = -5f; vertex_[10] = 5f; vertex_[11] = 0f; texture_[0] = 0f; texture_[1] = 0f; texture_[2] = 1f; texture_[3] = 0f; texture_[4] = 1f; texture_[5] = 1f; texture_[6] = 0f; texture_[7] = 1f; Gl.ReloadFunctions(); id = new int[1]; Gl.glGenBuffersARB(1, id); Gl.glBindBufferARB(Gl.GL_ARRAY_BUFFER_ARB, id[0]); Gl.glBufferDataARB(Gl.GL_ARRAY_BUFFER_ARB, (IntPtr)(12 * sizeof(float)), vertex_, Gl.GL_STATIC_DRAW_ARB); id1 = new int[1]; Gl.glGenBuffersARB(1, id1); Gl.glBindBufferARB(Gl.GL_ARRAY_BUFFER_ARB, id1[0]); Gl.glBufferDataARB(Gl.GL_ARRAY_BUFFER_ARB, (IntPtr)(8 * sizeof(float)), texture_, Gl.GL_STATIC_DRAW_ARB); vertex_ = null; texture_ = null; } and function: internal void Redraw() { Gl.glMatrixMode(Gl.GL_PROJECTION); Gl.glLoadIdentity(); Gl.glOrtho(-10.0f, 10.0f, -10.0f, 10.0f, -1.0f, 1.0f); Gl.glMatrixMode(Gl.GL_MODELVIEW); Gl.glLoadIdentity(); Gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT); if (state_) { Gl.glBindTexture(Gl.GL_TEXTURE_2D, t_); Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_TEXTURE_ENV_MODE, Gl.GL_MODULATE); Gl.glEnable(Gl.GL_TEXTURE_2D); Gl.glBindBufferARB(Gl.GL_ARRAY_BUFFER_ARB, id[0]); Gl.glBindBufferARB(Gl.GL_ARRAY_BUFFER_ARB, id1[0]); Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY); Gl.glEnableClientState(Gl.GL_TEXTURE_COORD_ARRAY); Gl.glVertexPointer(3, Gl.GL_FLOAT, 0, 0); Gl.glTexCoordPointer(2, Gl.GL_FLOAT, 0, 0); Gl.glDrawArrays(Gl.GL_QUADS, 0, 4); Gl.glBindBufferARB(Gl.GL_ARRAY_BUFFER_ARB, 0); Gl.glDisableClientState(Gl.GL_VERTEX_ARRAY); Gl.glDisableClientState(Gl.GL_TEXTURE_COORD_ARRAY); Gl.glDisable(Gl.GL_TEXTURE_2D); } Gl.glFlush(); } and after function Redraw I call this.simpleOpenGlControl1.SwapBuffers(); And I've got black screen. Why? Any idea what I'm doing wrong? That is my first program where I use VBO. I use c# and tao framework to write this program.
Advertisement
Your operations are out of order.

Instead of this:
Gl.glBindBufferARB(Gl.GL_ARRAY_BUFFER_ARB, id[0]);Gl.glBindBufferARB(Gl.GL_ARRAY_BUFFER_ARB, id1[0]);Gl.glVertexPointer(3, Gl.GL_FLOAT, 0, 0);Gl.glTexCoordPointer(2, Gl.GL_FLOAT, 0, 0);


You need this:
Gl.glBindBufferARB(Gl.GL_ARRAY_BUFFER_ARB, id[0]);Gl.glVertexPointer(3, Gl.GL_FLOAT, 0, 0);Gl.glBindBufferARB(Gl.GL_ARRAY_BUFFER_ARB, id1[0]);Gl.glTexCoordPointer(2, Gl.GL_FLOAT, 0, 0);


glPointer generates a pointer into the currently bound ARRAY_BUFFER, so when you call glVertexPointer, your vertex buffer must be bound.

In your code opengl is reading its vertices from your texture coordinates buffer, which obviously won't work.

[Edited by - karwosts on April 1, 2010 5:50:16 PM]
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Gl.glVertexPointer(3, Gl.GL_FLOAT, 0, 0);Gl.glTexCoordPointer(2, Gl.GL_FLOAT, 0, 0);


Additionally, you need to change the last paramatere from 0 to IntPtr.Zero, otherwise Tao will crash hard.

[OpenTK: C# OpenGL 4.4, OpenGL ES 3.0 and OpenAL 1.1. Now with Linux/KMS support!]

This topic is closed to new replies.

Advertisement