Thread: Implemented vertex arrays, prob. rendering

  1. #1

    Join Date
    May 2005
    Posts
    1,042

    Implemented vertex arrays, prob. rendering

    I got interested in Shamino's perpetual plight to implement a central data format. Subsequently, I implemented a mechanism for my 'own' basic layout that can be rendered using vertex arrays.

    Now, as far as I can see I've gotten things to work, but when I render everything using glVertex/TexCoord pointer and then glDrawArrays, I can an exception in my ATI driver (accessing something it shouldn't be). When I render the data 'manually' using 'stop and start' immediate mode GL, it renders fine, meaning that the data is 'correct.' Somewhere, I'm goofing up bigtime.

    Below is the two different ways I render 'NT_MODELs'

    PHP Code:
    #if    1
                
    int    start_index mesh_ref.mStartVertIndex;
    //also tried start_index = mdl_ref.mpIndexArray[mesh_ref.mStartVertIndex]
                
    NT_GL(glVertexPointer(3,GL_FLOAT,sizeof(NT_VERTEX),&mdl_ref.mpVertices[start_index].vertex))
                
    NT_GL(glTexCoordPointer(2,GL_FLOAT,sizeof(NT_VERTEX),&mdl_ref.mpVertices[start_index].tex_coord))
                
    NT_GL(glDrawElements(GL_TRIANGLES,mesh_ref.mNumMeshVerts,GL_UNSIGNED_INT,&mdl_ref.mpIndexArray[mesh_ref.mStartVertIndex]))
    #else
                
    gpNTGLAPI->ntglBegin(GL_TRIANGLES);
                for(
    int  j 0mesh_ref.mNumMeshVerts+= 3)
                {    
                    for(
    int k 03k++)    //plot each coordinate w/texture coord
                    
    {
                        
    int    index mdl_ref.mpIndexArray[mesh_ref.mStartVertIndex];
                        
                        
    NT_VERTEX    &    vert_ref mdl_ref.mpVertices[index];
                        
    gpNTGLAPI->ntglTexCoord2f(vert_ref.tex_coord[0],vert_ref.tex_coord[1]);
                        
    gpNTGLAPI->ntglVertex3fv(vert_ref.vertex);
                    }
                    
                }
                
    gpNTGLAPI->ntglEnd();
    #endif 
    First way crashes, second renders perfectly.

    This is similar, if not ultimately identical in structure, to how I render quake3 faces (a quake3 face is ultimately a mesh, the bsp has an index array)

    PHP Code:
        i mvQuake3SingleTexturedFaces.at(k);
        
            
    gpTextureManager->BindTexture(GL_TEXTURE_2D,gpBSP->mpGLTextures[gpBSP->mpFaces[i].textureID]);
            
            
    NT_GL(glVertexPointer(3,GL_FLOAT,sizeof(tBSPVertex),&gpBSP->mpVertices[gpBSP->mpFaces[i].startVertIndex].vPosition))
            
    NT_GL(glTexCoordPointer(2GL_FLOAT,sizeof(tBSPVertex), &gpBSP->mpVertices[gpBSP->mpFaces[i].startVertIndex].vTextureCoord))

            
    //doesn't work when you pass GL_FLOAT instead of int
            
    NT_GL(glDrawElements(GL_TRIANGLESgpBSP->mpFaces[i].numMeshVertsGL_UNSIGNED_INT, &gpBSP->mpIndexArray[gpBSP->mpFaces[i].meshVertIndex])) 
    This is quite strange indeed. I'm sure I'm doing something simple wrong.
    Last edited by BobMcGee123; 07-14-2006 at 04:38 PM.
    I'm not immature, I'm refined in the opposite direction.

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Not sure since I'm OpenGL ignorant.

    You guys really should come to the dark side of 3D where vertex arrays are natively supported. You know you want to.


  3. #3
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    I can't see anything wrong with the code you've shown.

    All I can suggest is making sure you called glEnable(GL_VERTEX_ARRAY) before rendering (if not, this could perhaps create an access violation as you described?), and perhaps seeing if OpenGL returns any errors in addition to the driver exception.

    I've never bothered with vertex arrays, so I can't be of much help here.
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  4. #4
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    499
    Quote Originally Posted by Bubba
    Not sure since I'm OpenGL ignorant.

    You guys really should come to the dark side of 3D where vertex arrays are natively supported. You know you want to.

    Now Bubba, don't you start another DirectX-OpenGL war.

  5. #5

    Join Date
    May 2005
    Posts
    1,042
    I got it working, I was computing my mpIndexArray data incorrectly.

    The index array is supposed to represent the offset *from the start vertex*, not actual indexes.
    I'm not immature, I'm refined in the opposite direction.

  6. #6
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Now Bubba, don't you start another DirectX-OpenGL war.
    A war would necessitate that the other side is capable of fighting it.


    j/k

  7. #7

    Join Date
    May 2005
    Posts
    1,042
    Them be fightin' words!!!!

    I must admit that I wasted a good amount of time solving a problem that was

    a) stupid

    b) stupid

    c) already implemented in DirectX

    Oh well
    I'm not immature, I'm refined in the opposite direction.

  8. #8
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    Hey mr!

    Well, hey!

    *angry face*
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  9. #9

    Join Date
    May 2005
    Posts
    1,042
    I meant it was stupid as in the solution was obvious, and further agravated by the fact that, as bubba mentioned, this is already implemented in the dx API. I was not trying to say that this was an easy problem to solve, in general.
    I'm not immature, I'm refined in the opposite direction.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple (?) problem rendering a vertex buffer
    By Dark_Phoenix in forum Game Programming
    Replies: 4
    Last Post: 08-11-2007, 07:32 PM
  2. error help making no sense
    By tunerfreak in forum C++ Programming
    Replies: 5
    Last Post: 04-17-2007, 07:55 PM
  3. Vertex Arrays
    By Shamino in forum Game Programming
    Replies: 2
    Last Post: 01-08-2006, 01:24 AM
  4. Invisible geometry :( D3D vertex prob?
    By gazsux in forum Game Programming
    Replies: 7
    Last Post: 04-07-2003, 05:40 AM
  5. Pixel Shaders.
    By Cheeze-It in forum Game Programming
    Replies: 1
    Last Post: 05-21-2002, 01:16 AM