View previous topic :: View next topic |
Author |
Message |
GhostManZero Member
Joined: 05 Nov 2005 Posts: 10
|
Posted: Sun Nov 06, 2005 12:43 am Post subject: How to render DMF maps in OpenGL |
|
|
Hello, i'm trying to render a DMF map using OpenGL, i loaded a file named "map.dmf" using the CDMFParser code from the Various Products section at delgine.com, and i'd like to know how should i do to render it all.
I am currently doing something like this:
for(i = 0; i < dmf.numObjects; ++i)
{
glBegin(GL_LINE_STRIP);
for(int j=0; j < dmf.objectList[i].numVertices; j++)
{
glColor3ub(rand() % 255,rand() % 255, rand() % 255);
glVertex3f(dmf.objectList[i].vertices[j].x,dmf.objectList[i].vertices[j].y,dmf.objectList[i].vertices[j].z);
}
glEnd();
}
i know that the geometry isnt drawed correctly. What should i do to draw the geometry correctly? should i use Triangle Strips? is there something wrong with the for loops in the code? I hope someone can help me, thank you all for spending some time reading this message, thanks in advance! |
|
Back to top |
|
|
Jeroen Site Admin
Joined: 07 Aug 2004 Posts: 5332 Location: The Netherlands
|
Posted: Sun Nov 06, 2005 1:11 am Post subject: |
|
|
Hi there GhostmanZero, and welcome!
Your code looks OK to me, except for one thing: the GL_LINE_STRIP. I would use GL_POLYGON or GL_LINE_LOOP to render the polygons. Geometry in DMF files isn't stored in triangle strips but rather as a polygon soup. Hope this helps out! |
|
Back to top |
|
|
Daaark DeleD PRO user
Joined: 01 Sep 2004 Posts: 2696 Location: Ottawa, Canada
|
Posted: Sun Nov 06, 2005 4:23 am Post subject: |
|
|
While polygons are okay to just flat out render the thing, if you want to get it renering fast you are going to have to do a few more steps.
1) Triangulate the map
2) Material Sort
3) Vertex Arrays instead of immediate mode |
|
Back to top |
|
|
GhostManZero Member
Joined: 05 Nov 2005 Posts: 10
|
|
Back to top |
|
|
GhostManZero Member
Joined: 05 Nov 2005 Posts: 10
|
Posted: Sun Nov 06, 2005 11:21 am Post subject: |
|
|
Forgot to tell you how i do the loading and rendering of the whole level:
cout << "Loading DMF File...";
dmf_file_t dmf;
dmf_object_t *objPtr;
dmf_polygon_t *polyPtr;
unsigned int result;
unsigned int i, j, k, m;
result = ReadDMF(&dmf, "map.dmf", ProgressCallback, TextureLoadCallback);
if(DMF_NO_ERROR != result)
{
cout << "FAILED!" << endl;
cout << "Releasing Rendering device...";
Renderer.Release();
gluDeleteQuadric(GQO);
cout << "OK!" << endl;
cout << "Releasing Texture devices...";
if(UseTGALoader)
TGATexDevice.Release();
if(UseBMPLoader)
BMPTexDevice.Release();
cout << "OK!" << endl;
cout << "Releasing Networking device...";
WinSockNetwork.Release();
cout << "OK!" << endl;
cout << "Execution terminated." << endl;
system("PAUSE");
exit(1);
}
TranslateDMF(&dmf, 0.f, 0.f, 0.f);
RotateDMF(&dmf, 90.f, 0, 1, 0);
ReverseDMF(&dmf);
TriangulateDMF(&dmf);
if(dmf.version >= DMF_VERSION_1_1)
ScaleDMF(&dmf, 1.f, 2.f, 2.f, 1.f, -1.f);
else
ScaleDMF(&dmf, 1.f, 2.f, 2.f, 1.f, 1.f);
cout << "OK!" << endl;
cout << "Entering Main Loop" << endl;
//POSITION CAMERA
while(1)
{
//DO NECESSARY STUFF TO START RENDERING
for(i = 0; i < dmf.numObjects; ++i)
{
glBegin(GL_POLYGONS); //or GL_LINE_LOOP or GL_TRIANGLE_STRIP
for(int j=0; j < dmf.objectList[i].numVertices; j++)
{
glColor3ub(rand() % 255,rand() % 255, rand() % 255);
glVertex3f(dmf.objectList[i].vertices[j].x,dmf.objectList[i].vertices[j].y,dmf.objectList[i].vertices[j].z);
}
glEnd();
}
//OTHER STUFF
} |
|
Back to top |
|
|
Jeroen Site Admin
Joined: 07 Aug 2004 Posts: 5332 Location: The Netherlands
|
Posted: Sun Nov 06, 2005 12:15 pm Post subject: |
|
|
It seems that your render loop is just fine. Maybe the error is in the steps before rendering. I see you're performing a bunch of manipulations (like triangulation) on the DMF. You could try to do without those manipulations and see what you get? |
|
Back to top |
|
|
Mr.Fletcher DeleD PRO user
Joined: 07 Aug 2004 Posts: 1772 Location: Germany
|
Posted: Sun Nov 06, 2005 12:47 pm Post subject: |
|
|
I'm not sure about the Loader, but it seems to me that there should be a Polygon-Loop, too. With that code, you render every vertex of every object as a GL_POLYGON. Try to figure out how the loader loads the polygons. _________________ Behold! The DeleD Wiki! Please help us expanding it
DeleD on IRC |
|
Back to top |
|
|
GhostManZero Member
Joined: 05 Nov 2005 Posts: 10
|
Posted: Sun Nov 06, 2005 2:42 pm Post subject: |
|
|
The loader thinks that polygons are texcoords (?)
like:
typedef struct
{
unsigned int numVertices;
unsigned int materialIndex;
unsigned int *indices;
dmf_texcoord_t texcoords[4];
} dmf_polygon_t;
Strange huh? |
|
Back to top |
|
|
Daaark DeleD PRO user
Joined: 01 Sep 2004 Posts: 2696 Location: Ottawa, Canada
|
Posted: Sun Nov 06, 2005 2:56 pm Post subject: |
|
|
Did you normalize the faces? Try disabling backface culling. |
|
Back to top |
|
|
Mr.Fletcher DeleD PRO user
Joined: 07 Aug 2004 Posts: 1772 Location: Germany
|
Posted: Sun Nov 06, 2005 3:29 pm Post subject: |
|
|
GhostManZero wrote: |
The loader thinks that polygons are texcoords (?)
like:
typedef struct
{
unsigned int numVertices;
unsigned int materialIndex;
unsigned int *indices;
dmf_texcoord_t texcoords[4];
} dmf_polygon_t;
Strange huh? |
You have to go though each object's polygon array and then use the polygon's vertices indices for rendering. Like
glVertex3f(dmf.objectList[i].vertices[dmf.objectList[i].polygon[p].indices[k]].x, ... );
(iirc) _________________ Behold! The DeleD Wiki! Please help us expanding it
DeleD on IRC |
|
Back to top |
|
|
Jeroen Site Admin
Joined: 07 Aug 2004 Posts: 5332 Location: The Netherlands
|
Posted: Sun Nov 06, 2005 4:54 pm Post subject: |
|
|
Mr.Fletcher wrote: |
I'm not sure about the Loader, but it seems to me that there should be a Polygon-Loop, too. With that code, you render every vertex of every object as a GL_POLYGON. Try to figure out how the loader loads the polygons. |
LOL, you're quite right Mr Fletcher, I didn't even see that. I guess I shouldn't be answering questions like this when I'm away on a network-weekend (playing games and drinking beer all through the night... not good for concentration ) |
|
Back to top |
|
|
GhostManZero Member
Joined: 05 Nov 2005 Posts: 10
|
Posted: Sun Nov 06, 2005 6:27 pm Post subject: |
|
|
Tryed the last advice, using this loop:
for(i = 0; i < dmf.numObjects; ++i)
{
glBegin(GL_POLYGONS);
for(j=0; j < dmf.objectList[i].numPolygons; j++)
{
for(k = 0; k < dmf.objectList[i].polygons[j].numVertices; ++k)
{
glVertex3f(
dmf.objectList[i].vertices[dmf.objectList[i].polygons[j].indices[k]].x,
dmf.objectList[i].vertices[dmf.objectList[i].polygons[j].indices[k]].y,
dmf.objectList[i].vertices[dmf.objectList[i].polygons[j].indices[k]].z
);
}
}
}
glEnd();
It doesnt seem to be drawed ENTIRELY correctly, isthere something wrong with this? |
|
Back to top |
|
|
GhostManZero Member
Joined: 05 Nov 2005 Posts: 10
|
Posted: Sun Nov 06, 2005 7:44 pm Post subject: |
|
|
Also, how should i get the texture coords? |
|
Back to top |
|
|
Mr.Fletcher DeleD PRO user
Joined: 07 Aug 2004 Posts: 1772 Location: Germany
|
Posted: Sun Nov 06, 2005 7:57 pm Post subject: |
|
|
The glBegin(GL_POLYGONS); Command should come in your Polygons-Loop, so
Code: |
...
for(j=0; j < dmf.objectList[i].numPolygons; j++)
{
glBegin(GL_POLYGONS);
...
|
You would apply the texture coords by calling
Code: |
glTexCoord2f(
dmf.objectList[i].vertices[dmf.objectList[i].polygons[j].indices[k]].s,
dmf.objectList[i].vertices[dmf.objectList[i].polygons[j].indices[k]].t
);
glVertex3f(...);
|
Or however the coordinates are stored there. _________________ Behold! The DeleD Wiki! Please help us expanding it
DeleD on IRC |
|
Back to top |
|
|
Daaark DeleD PRO user
Joined: 01 Sep 2004 Posts: 2696 Location: Ottawa, Canada
|
Posted: Sun Nov 06, 2005 8:54 pm Post subject: |
|
|
Mr.Fletcher wrote: |
The glBegin(GL_POLYGONS); Command should come in your Polygons-Loop |
That's only going to make it even slower than it already is. |
|
Back to top |
|
|
|