Jump to content
  • Advertisement
Sign in to follow this  
Damocles

Meshes, OGL, lib3ds, normals and nightmares...

This topic is 4174 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

::::::::SOLVED::::::::: I'm not really sure if this should go in Alternative Libraries, OpenGL, or Graphics Programming, so I'm sticking it in here :) If a mod feels it should be moved, please do so. I'm having a weird problem with my use of the lib3ds library and OpenGL. If I load in the mesh data directly into a display list, it displays fine, and the normals and UV coords all seem fine. IF I load the data into arrays and use glDrawArrays, the vertex data is fine, but I either the tex coord data or the normal data is going to hell somehow. Observe... On the left is the display list version, and on the right is the DrawArrays version. What gets me is that it's the exact same data! I've enabled all the necessary client states (texture coords pointer, normal pointer, vertex pointer). Anyway, here's some code - maybe someone can spot what I'm doing wrong... This is the display list version...
displayListID = glGenLists(1); /* assign display list */
	glNewList(displayListID, GL_COMPILE);

	glBegin(GL_TRIANGLES);
	for (mesh = file->meshes; mesh; mesh = mesh->next)
	{
		for (p = 0; p < mesh->faces; p++) // step through mesh list
		{
			f = &mesh->faceL

; // reverse screwy normals f->normal[0]*=-1; f->normal[1]*=-1; f->normal[2]*=-1; glNormal3fv(f->normal); // use normals // grab vertex data into vector for ( i = 0; i < 3; i++) { glTexCoord2f(mesh->texelL[f->points][0],mesh->texelL[f->points][1]); glVertex3fv(mesh->pointL[f->points].pos); //draw the triangle } } } glEnd(); /* end GL_TRIANGLES */ glEndList(); /* end display list */

And here's the arrays version...
	for (mesh = file->meshes; mesh; mesh = mesh->next)
	{
		for (p = 0; p < mesh->faces; p++) // step through mesh list
		{
			f = &mesh->faceL

; // reverse screwy normals f->normal[0]*=-1; f->normal[1]*=-1; f->normal[2]*=-1; normalData.push_back(f->normal[0]); normalData.push_back(f->normal[1]); normalData.push_back(f->normal[2]); // grab vertex data into vector for ( i = 0; i < 3; i++) { for (int p=0; p<3; p++) vertexData.push_back(mesh->pointL[f->points].pos

); vertexCount++; uvData.push_back(mesh->texelL[f->points][0]); uvData.push_back(mesh->texelL[f->points][1]); } } } vector<float>::iterator it; float* pos; pos = &vertexes[0]; for (it = vertexData.begin(); it<vertexData.end(); it++) { *pos = (*it); pos++; } pos = &normals[0]; for (it = normalData.begin(); it<normalData.end(); it++) { *pos = (*it); pos++; } pos = &uvcoords[0]; for (it = uvData.begin(); it<uvData.end(); it++) { *pos = (*it); pos++; }

and the drawing calls... (I'll dump them both in the one thingy)
glEnable(GL_LIGHTING);
	glDepthFunc(GL_GEQUAL);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
	glDepthRange(0,1000);

	glClear(GL_DEPTH_BUFFER_BIT);

	glTranslatef(400,400,0); // move to central screen pos - tbd use point passed in

	setColor(1,1,1,1);

	glCallList(displayListID); // display list call

	glNormalPointer(GL_FLOAT, 0, &normals[0]);
	glTexCoordPointer(2, GL_FLOAT, 0, &uvcoords[0]);
	glVertexPointer(3, GL_FLOAT, 0, &vertexes[0]);
	glDrawArrays(GL_TRIANGLES, 0, vertexCount); // draw arrays call




If anyone knows what the problem is, I'd appreciate some help. This one has me completely stumped. SOLVED EDIT: Seems I missed a very important line when reading up on lib3ds: lib3ds_mesh_calculate_normals(mesh, normalL); This function seems to convert normal data into usable formats for vertex arrays. Strange that the same data would work in display lists, but not in vertex arrays without being converted first though. [Edited by - Damocles on April 21, 2007 1:12:04 PM]

Share this post


Link to post
Share on other sites
Advertisement
// reverse screwy normals
f->normal[0]*=-1;
f->normal[1]*=-1;
f->normal[2]*=-1;


Um.....f->normal

*=-1; ?? Where do you loat f->normal[] at, thats obviously where your problem is.

Share this post


Link to post
Share on other sites
Sorry, I guess I should have included more code - the line:

f = &mesh->faceL

;

is filling the f variable with a data struct faceL, which contains 'float normal[3]' as one of its members. The normal data is most definitely in there as the same line is used to get the data for the display list, and that works perfectly.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!