So I am trying to do draw the Lesson 07 cube with the VAR extension.
I changed the code to draw a triangle-strip cube instead of the normal cube like this:
GLfloat box_vertex[24];
GLfloat box_normal[24];
GLfloat box_color[24];
GLfloat box_tex[16];
GLubyte box_indices[18];
Set up the arrays with the right data.
box_vertex[0] = -1.0f; // x
box_vertex[1] = -1.0f; // y
box_vertex[2] = 1.0f; // z
box_vertex[3] = -1.0f;
box_vertex[4] = 1.0f;
box_vertex[5] = 1.0f;
box_vertex[6] = 1.0f;
box_vertex[7] = 1.0f;
box_vertex[8] = 1.0f;
box_vertex[9] = 1.0f;
box_vertex[10] = -1.0f;
box_vertex[11] = 1.0f;
box_vertex[12] = 1.0f;
box_vertex[13] = -1.0f;
box_vertex[14] = -1.0f;
box_vertex[15] = 1.0f;
box_vertex[16] = 1.0f;
box_vertex[17] = -1.0f;
box_vertex[18] = -1.0f;
box_vertex[19] = 1.0f;
box_vertex[20] = -1.0f;
box_vertex[21] = -1.0f;
box_vertex[22] = -1.0f;
box_vertex[23] = -1.0f;
box_normal[0] = -0.71f;
box_normal[1] = 0;
box_normal[2] = 0.71f;
box_normal[3] = -0.71f;
box_normal[4] = 0;
box_normal[5] = 0.71f;
box_normal[6] = 0.71f;
box_normal[7] = 0;
box_normal[8] = 0.71f;
box_normal[9] = 0.71f;
box_normal[10] = 0;
box_normal[11] = 0.71f;
box_normal[12] = 0.71f;
box_normal[13] = 0;
box_normal[14] = -0.71f;
box_normal[15] = 0.71f;
box_normal[16] = 0;
box_normal[17] = -0.71f;
box_normal[18] = -0.71f;
box_normal[19] = 0;
box_normal[20] = -0.71f;
box_normal[21] = -0.71f;
box_normal[22] = 0;
box_normal[23] = -0.71f;
box_color[0] = 0.478f;
box_color[1] = 0.341f;
box_color[2] = 0.129f;
box_color[3] = 0.478f;
box_color[4] = 0.341f;
box_color[5] = 0.129f;
box_color[6] = 0.478f;
box_color[7] = 0.341f;
box_color[8] = 0.129f;
box_color[9] = 0.478f;
box_color[10] = 0.341f;
box_color[11] = 0.129f;
box_color[12] = 0.478f;
box_color[13] = 0.341f;
box_color[14] = 0.129f;
box_color[15] = 0.478f;
box_color[16] = 0.341f;
box_color[17] = 0.129f;
box_color[18] = 0.478f;
box_color[19] = 0.341f;
box_color[20] = 0.129f;
box_color[21] = 0.478f;
box_color[22] = 0.341f;
box_color[23] = 0.129f;
box_tex[0] = 0.0f;
box_tex[1] = 1.0f;
box_tex[2] = 0.0f;
box_tex[3] = 0.0f;
box_tex[4] = 1.0f;
box_tex[5] = 0.0f;
box_tex[6] = 1.0f;
box_tex[7] = 1.0f;
box_tex[8] = 0.0f;
box_tex[9] = 1.0f;
box_tex[10] = 0.0f;
box_tex[11] = 0.0f;
box_tex[12] = 1.0f;
box_tex[13] = 0.0f;
box_tex[14] = 1.0f;
box_tex[15] = 1.0f;
box_indices[0] = 4;
box_indices[1] = 7;
box_indices[2] = 3;
box_indices[3] = 0;
box_indices[4] = 0;
box_indices[5] = 1;
box_indices[6] = 7;
box_indices[7] = 6;
box_indices[8] = 4;
box_indices[9] = 5;
box_indices[10] = 3;
box_indices[11] = 2;
box_indices[12] = 0;
box_indices[13] = 1;
box_indices[14] = 1;
box_indices[15] = 6;
box_indices[16] = 2;
box_indices[17] = 5;
Draw vertex arrays
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glBindTexture(GL_TEXTURE_2D, texture[filter]);
glVertexPointer(3, GL_FLOAT, 0, box_vertex);
glColorPointer(3, GL_FLOAT, 0, box_color);
glTexCoordPointer(2, GL_FLOAT, 0, box_tex);
glNormalPointer(GL_FLOAT, 0, box_normal);
glDrawElements(GL_TRIANGLE_STRIP, 18, GL_UNSIGNED_BYTE, box_indices);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
Now this all works fine. Now I wanted to change the code to use VAR extension. This is the code I added modified:
PFNWGLALLOCATEMEMORYNVPROC wglAllocateMemoryNV = NULL;
PFNGLVERTEXARRAYRANGENVPROC glVertexArrayRangeNV = NULL;
I changed this:
//GLubyte box_indices[18];
GLubyte *box_indices;
and then I *think* i initialized the VAR with this:
glVertexArrayRangeNV = (PFNGLVERTEXARRAYRANGENVPROC)wglGetProcAddress("glVertexArrayRangeNV");
wglAllocateMemoryNV = (PFNWGLALLOCATEMEMORYNVPROC) wglGetProcAddress("wglAllocateMemoryNV");
box_indices = (GLubyte*)wglAllocateMemoryNV(18, 0.2f, 0.2f, 0.5f);
glVertexArrayRangeNV(18*sizeof(GLfloat), box_indices);
The code compiles with no errors or warnings, but crashes when I try to run it. What am I missing ?
Nitzan
-------------------------
www.geocities.com/nitzanw
www.scorchedearth3d.net
-------------------------