PDA

View Full Version : load code after converting figure



grodslukaren
05-29-2001, 10:22 AM
Hi,

I have changed a figure I had in .x to code in .cpp, with the help of "3D Exploration Plugin: CPP Export filter." What is the best way to insert this code in my OpenGL App?

I donīt get what I wiil do with "sample_MATERIAL materials" & "face_indicies[8416][9]".

my code:
/*
This file was produced by 3D Exploration plugin: CPP Export filter.
3D Exploration, Copyright (c) 1999-2000 X Dimension Software, WWW http://www.xdsoft.com/explorer/
eMail info@xdsoft.com
*/
#include <windows.h>
#include <GL\gl.h>
#include <GL\glu.h>
struct sample_MATERIAL{
GLfloat ambient[3];
GLfloat diffuse[3];
GLfloat specular[3];
GLfloat emission[3];
GLfloat alpha;
GLfloat phExp;
int texture;
};
static sample_MATERIAL materials [1] = {
{{0.0f,0.0f,0.0f},{0.956863f,0.576471f,0.576471f}, {0.898039f,0.898039f,0.898039f},{0.0f,0.0f,0.0f},
0.25f,23.0f,-1} //Material #1
};

// 4593 Verticies
// 0 Texture Coordinates
// 4964 Normals
// 8416 Triangles

static short face_indicies[8416][9] = {
// Object #0
{333,335,334 ,0,1,2 ,0,0,0}, {336,337,333 ,3,4,0 ,0,0,0}, {338,340,339 ,5,6,7 ,0,0,0},
{341,340,342 ,8,6,9 ,0,0,0}, {343,344,342 ,10,11,9 ,0,0,0}, {345,344,346 ,12,11,13 ,0,0,0},
{346,348,347 ,13,14,15 ,0,0,0}, {349,350,348 ,16,17,14 ,0,0,0},
{351,352
...........
...........

Deiussum
05-29-2001, 10:59 AM
You'll use the stuff in materials in the glMaterial function and the indices array will tell you the indices of the vertices, normals, and texcoord arrays that you need to use for each face.

It looks like for each set of 9 numbers you probably have 3 coordinates for the vertex, 3 for the normal, then 3 more (prossibly 2 for texcoord and 1 for material index?)
*edit* Not sure what I was thinking before, those last 3 are probably all indices to texcoords, which don't exist in this case so they are all set to 0. http://www.opengl.org/discussion_boards/ubb/smile.gif *end edit*

If I'm interpretting things coorectly, for drawing face1 you should draw face0 of object0 by doing something like...

// you've only got one material so you should really only do this line once.
SetupMaterial(0);

UseNormal(0);
DrawVertex(333);

UseNormal(1);
DrawVertex(335);

UseNormal(2);
DrawVertex(334);

Hope that makes sense. http://www.opengl.org/discussion_boards/ubb/smile.gif

*added stuff*
Just thought I'd clarify the pseudocode a bit, as I'm not sure how clear it was after reading it over again today. The DrawVertex function would probably look something like this, where vertices represents a global array with all your vertex data...

void DrawVertex(int nIndex)
{
glVertex3fv(vertices[nIndex]);
}

Hope that helps.


[This message has been edited by Deiussum (edited 05-30-2001).]