vbo (vertex buffer object) werkt niet

Status
Niet open voor verdere reacties.

jopie33

Gebruiker
Lid geworden
10 apr 2010
Berichten
30
hallo allemaal. ik ben bezig mijn eigen demo's te schrijven om meer te leren over C++ en opengl. Nu ben ik bij een punt gekomen dat ik vertex buffer objects wil gaan gebruiken alleen werkt het niet.

hieronder is mijn demo, het werkt op GLFW (http://www.glfw.org/).

[CPP]
#define GL_GLEXT_PROTOTYPES
#include <GL/glfw.h>
#include "glext.h"

#define ogl_version glGetString(GL_VERSION)

#include <iostream>
#include <string>

using namespace std;

#define BUFFER_OFFSET(i) ((char *)NULL + (i))

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* CLASSES -> need to be moved to new class header file *///////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

struct Vertex
{
float x, y, z; //Vertex
float nx, ny, nz; //Normal
float s, t; //Texcoord0
};

class Model
{
public:
int vertexCount;
Vertex* pVertices;
unsigned int textureId;

// Vertex Buffer Object Names
unsigned int VBO_VertexID;
unsigned int TextureID;
};

Model * pModel = NULL;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* CLASSES -> need to be moved to new class header file *///////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

bool test = true;

//Called when the window is resized
void HandleResize(int WIDTH, int HEIGHT) {
//Tell OpenGL how to convert from coordinates to pixel values
glViewport(0, 0, WIDTH, HEIGHT);

glMatrixMode(GL_PROJECTION); //Switch to setting the camera perspective

//Set the camera perspective
glLoadIdentity(); //Reset the camera
gluPerspective(45.0, //The camera angle
(double)WIDTH / (double)HEIGHT, //The width-to-height ratio
1.0, //The near z clipping coordinate
200.0); //The far z clipping coordinate
}

void DrawUI(int WIDTH,int HEIGHT)
{

}


void DrawScene(int WIDTH,int HEIGHT)
{
///*
glBindBufferARB( GL_ARRAY_BUFFER_ARB, pModel -> VBO_VertexID );
glVertexPointer( 3, GL_FLOAT, 0, BUFFER_OFFSET(0)); // Set The Vertex Pointer

glBindBufferARB( GL_ARRAY_BUFFER_ARB, pModel -> VBO_VertexID );
glNormalPointer( GL_FLOAT, 0, BUFFER_OFFSET(12)); // Set The Normal Pointer

glBindBufferARB( GL_ARRAY_BUFFER_ARB, pModel -> VBO_VertexID );
glTexCoordPointer( 2, GL_FLOAT, 0, BUFFER_OFFSET(24)); // Set The TexCoord Pointer

glDrawArrays( GL_TRIANGLES, 0, pModel-> vertexCount );
//*/

///*
glBegin(GL_TRIANGLES); // Drawing Using Triangles
glVertex3f( 0.0f, 1.0f, 0.0f); // Top
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glEnd();
//*/ // Finished Drawing The Triangle
}

void GameLoop(int WIDTH, int HEIGHT, int vbo_supported, int multitexture_supported)
{
if(test)
{
cout << "inside GameLoop" << endl;
cout << "WIDTH = " << WIDTH << endl;
cout << "HEIGHT = " << HEIGHT << endl;
}

bool GameLoop = true;

// Zet de OpenGL viewport breedte en hoogte gelijk aan de variabelen WIDTH en HEIGHT
// en zet de camera settings goed
HandleResize(WIDTH,HEIGHT);

glEnable(GL_DEPTH_TEST); // //Makes 3D drawing work when something is in front of something else
glTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0
while(GameLoop)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

DrawScene(WIDTH,HEIGHT); // spreekt voorzich
DrawUI(WIDTH,HEIGHT); // UI = User Interface

glfwSwapBuffers();

GameLoop = !glfwGetKey( GLFW_KEY_ESC ) && glfwGetWindowParam( GLFW_OPENED );
}
}

int main(void)
{
int running = GL_TRUE;

if (glfwInit() != GL_TRUE)
{
glfwTerminate();
return 0;
}

// Dit checkt alle modes die de de computer ondersteund:
// Resolutie(Width en Height), BBP = Bits per pixel = RedBits + BlueBits + Greenbits
int nummodes;
GLFWvidmode list[ 200 ];
nummodes = glfwGetVideoModes( list, 200 );

if(test)
{
if(nummodes == 1)cout << "Only one mode supported " << endl << endl;
else cout << "Total modes supported: " << nummodes << endl << endl;

for(int i=0; i<nummodes; i++)
{
cout << "Mode " << i + 1 << endl;

cout << "Width: " << list.Width << endl;
cout << "Height: " << list.Height << endl;
cout << "Redbits: " << list.RedBits << endl;
cout << "Bluebits: " << list.GreenBits << endl;
cout << "Greenbits: " << list.BlueBits << endl;
cout << endl;
}
cout << "Max resolution is: " << list[nummodes - 1].Width << "x" << list[nummodes - 1].Height << endl;
cout << "BPP = " << list[nummodes - 1].RedBits + list[nummodes - 1].GreenBits + list[nummodes - 1].BlueBits << " -> Bestaande uit:" << endl;
cout << "Redbits: " << list[nummodes - 1].RedBits << endl;
cout << "Bluebits: " << list[nummodes - 1].GreenBits << endl;
cout << "Greenbits: " << list[nummodes - 1].BlueBits << endl;
cout << endl;
}

int WIDTH = list[nummodes - 1].Width;
int HEIGHT = list[nummodes - 1].Height;

if(test)
{
cout << "WIDTH = " << WIDTH << endl;
cout << "HEIGHT = " << HEIGHT << endl;
cout << endl;
}

//int glfwOpenWindow( int width, int height,int redbits, int greenbits,
//int bluebits,int alphabits, int depthbits, int stencilbits,int mode )
if(glfwOpenWindow(list[nummodes - 1].Width, list[nummodes - 1].Height, list[nummodes - 1].RedBits, list[nummodes - 1].GreenBits, list[nummodes - 1].BlueBits, 8, 8, 0, GLFW_FULLSCREEN) != GL_TRUE)
{
glfwTerminate();
return 0;
}

glfwSetWindowTitle( "Witte driehoek" );

// CHECK FOR EXTENSIONS !!!

//compile time check

bool multitexture_supported = 0;
bool vbo_supported = 0;


#ifdef GL_ARB_multitexture
multitexture_supported = glfwExtensionSupported( "GL_ARB_multitexture" );
#else
multitexture_supported = GL_FALSE;
#define NO_VBOS
#endif

#ifdef GL_ARB_vertex_buffer_object
vbo_supported = glfwExtensionSupported( "GL_ARB_vertex_buffer_object" );
#else
vbo_supported = GL_FALSE;
#endif

// VBO Extension Function Pointers
PFNGLGENBUFFERSARBPROC glGenBuffersARB = NULL; // VBO Name Generation Procedure
PFNGLBINDBUFFERARBPROC glBindBufferARB = NULL; // VBO Bind Procedure
PFNGLBUFFERDATAARBPROC glBufferDataARB = NULL; // VBO Data Loading Procedure
PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB = NULL; // VBO Deletion Procedure

cout << endl << "COMPILE TIME CHECK:" << endl;
cout << "GL_ARB_multitexture = " << multitexture_supported << endl;
cout << "GL_ARB_vertex_buffer_object = " << vbo_supported << endl << endl;

cout << "opengl version " << ogl_version << endl << endl;

pModel = new Model();
pModel -> vertexCount = 3;
pModel -> pVertices = new Vertex[pModel -> vertexCount];

pModel -> pVertices[0].x = 0.0;
pModel -> pVertices[0].y = 1.0;
pModel -> pVertices[0].z = 0.0;

pModel -> pVertices[1].x = -1.0;
pModel -> pVertices[1].y = -1.0;
pModel -> pVertices[1].z = 0.0;

pModel -> pVertices[2].x = 1.0;
pModel -> pVertices[2].y = -1.0;
pModel -> pVertices[2].z = 0.0;


if(vbo_supported){
glGenBuffersARB = (PFNGLGENBUFFERSARBPROC) glfwGetProcAddress("glGenBuffersARB");
glBindBufferARB = (PFNGLBINDBUFFERARBPROC) glfwGetProcAddress("glBindBufferARB");
glBufferDataARB = (PFNGLBUFFERDATAARBPROC) glfwGetProcAddress("glBufferDataARB");
glDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC) glfwGetProcAddress("glDeleteBuffersARB");
}

glGenBuffersARB( 1, &pModel -> VBO_VertexID ); // Get A Valid Name
glBindBufferARB( GL_ARRAY_BUFFER_ARB, pModel -> VBO_VertexID ); // Bind The Buffer
// Load The Data
glBufferDataARB( GL_ARRAY_BUFFER_ARB, pModel -> vertexCount*sizeof(float),pModel -> pVertices, GL_STATIC_DRAW_ARB );

// Our Copy Of The Data Is No Longer Necessary, It Is Safe In The Graphics Card
delete [] pModel -> pVertices; pModel -> pVertices = NULL;



//start de GameLoop, hier komt het eche programma in !!!
GameLoop(WIDTH, HEIGHT, vbo_supported, multitexture_supported);


glDeleteBuffersARB(1, &pModel -> VBO_VertexID);
delete [] pModel; pModel = NULL;

glfwTerminate();

return 0;
}
[/CPP]

ik krijg de volgende fouten van mijn compiler:

[Linker Error] undefined reference to `glBindBufferARB@8'
[Linker Error] undefined reference to `glBindBufferARB@8'
[Linker Error] undefined reference to `glBindBufferARB@8'
ld returned 1 exit status

als ik van het volgende stukje weg haal, verdwijnen de fouten en werkt mijn programma, maar de vbo wordt dus niet gerendered:

[CPP]
glBindBufferARB( GL_ARRAY_BUFFER_ARB, pModel -> VBO_VertexID );
glVertexPointer( 3, GL_FLOAT, 0, BUFFER_OFFSET(0)); // Set The Vertex Pointer

glBindBufferARB( GL_ARRAY_BUFFER_ARB, pModel -> VBO_VertexID );
glNormalPointer( GL_FLOAT, 0, BUFFER_OFFSET(12)); // Set The Normal Pointer

glBindBufferARB( GL_ARRAY_BUFFER_ARB, pModel -> VBO_VertexID );
glTexCoordPointer( 2, GL_FLOAT, 0, BUFFER_OFFSET(24)); // Set The TexCoord Pointer

glDrawArrays( GL_TRIANGLES, 0, pModel-> vertexCount );
[/CPP]

weet iemand misschien een oplossing? alvast bedankt :)
 
Opengl is al geinclude in glfw.h dus dat was het probleem niet. Maar het is al opgelost,de tutorial die ik volgde klopte niet, ik heb uiteindelijk een andere gevolgd waar het wel mee lukte.
 
[Linker Error] undefined reference to `<functie naam>' betekent dat je de desbetreffende library niet gelinkt hebt, vandaar dat je compiler die functie niet kan vinden en een foutmelding geeft.
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan