PDA

View Full Version : okay I had it ! with this glDrawElements function!



noobscratcher
04-15-2012, 03:03 PM
I decided after a long time of trying to do a graphical user interface using just opengl graphics to go back to a gui toolkit and in the process have had to port alot of my code to win32.

But to get too the actual problem my glDrawElement function crashes when I execute the program.

This happens when I use anything but GL_INT for the 3rd parameter of the function and when I execute the program with GL_INT it doesn't render anything to the frustum.

So I was trying to figure out why and I just don't understand I thought I did everything correct but I guess not....

here is my .obj file for reference:



# Blender v2.61 (sub 0) OBJ File: ''
# www.blender.org
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -0.999999
v 0.999999 1.000000 1.000001
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
s off
f 1 2 3 4
f 5 8 7 6
f 1 5 6 2
f 2 6 7 3
f 3 7 8 4
f 5 1 4 8

I'm using a parser I created to get the faces/vertexes in my .obj file:





char modelbuffer [20000];
unsigned int face[3];
ifstream file (szFileName);

//While FileObject not equal end of file
while (!file.eof() )
{

char modelbuffer[20000];

file.getline(modelbuffer, 20000);

switch(modelbuffer[0])
{

cout << " " << endl;

case 'v' :

Point p;

sscanf(modelbuffer, "v %f %f %f", &amp;p.x, &amp;p.y, &amp;p.z);

points.push_back(p);

cout << " p.x = " << p.x << " p.y = " << p.y << " p.z = " << p.x << endl;

break;

cout << " " << endl;

case 'f':

int read_count = sscanf(modelbuffer, "f %d %d %d %d", &amp;face[0], &amp;face[1], &amp;face[2], &amp;face[3]);

cout << "face[0] = " << face[0] << " face[1] = " << face[1] << " face[2] = " << face[2] << " face[3] = " << face[3] << "\n";

if(read_count !=4)
{

cout << "bad/n";
throw std::exception();

}

faces.push_back(face[0] - 1);
faces.push_back(face[1] - 1);
faces.push_back(face[2] - 1);
faces.push_back(face[3] - 1);

cout << face[0] - 1 << face[1] - 1 << face[2] - 1 << face[3] - 1 << endl;


}

}
using this struct to store the x,y,z positions also this vector was used with Point:


vector<Point>points;


struct Point
{

float x, y, z;

};

If someone could tell me why its not working and how to fix it that would be awesome I also provide a pastebin to the full source code if you want a closer look.

http://pastebin.com/FsJ93ykj

V-man
04-15-2012, 03:55 PM
Did you try to debug your code?
Did you try glGetError()?
http://www.opengl.org/wiki/GL_Error_Codes

What about this line? glGenBuffers(0, &amp;vertexbuffer);
Is 0 valid?

Check out the docs at http://www.opengl.org/sdk/docs/man4/

Alfonse Reinheart
04-15-2012, 06:25 PM
Check out the docs at http://www.opengl.org/sdk/docs/man4/

No, they're over here on the Wiki (http://www.opengl.org/wiki/Category:Core_API_Reference).