Delgine 3D Tools & Content DeleD Community Edition
Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to render DMF maps in OpenGL
Goto page 1, 2  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    DeleD Community Edition Forum Index -> DeleD Community Edition
View previous topic :: View next topic  
Author Message
GhostManZero
Member


Joined: 05 Nov 2005
Posts: 10

PostPosted: Sun Nov 06, 2005 12:43 am    Post subject: How to render DMF maps in OpenGL Reply with quote

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
View user's profile Send private message Visit poster's website MSN Messenger
Jeroen
Site Admin


Joined: 07 Aug 2004
Posts: 5332
Location: The Netherlands

PostPosted: Sun Nov 06, 2005 1:11 am    Post subject: Reply with quote

Hi there GhostmanZero, and welcome! Smile

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
View user's profile Send private message Send e-mail Visit poster's website
Daaark
DeleD PRO user


Joined: 01 Sep 2004
Posts: 2696
Location: Ottawa, Canada

PostPosted: Sun Nov 06, 2005 4:23 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
GhostManZero
Member


Joined: 05 Nov 2005
Posts: 10

PostPosted: Sun Nov 06, 2005 11:17 am    Post subject: Reply with quote

Well, i still have a problem with the rendering, i tryed polygon rendering, Line Loop rendering and Triangle Strip rendering, and none of them work well.
For you to see how it is showing up:

www.ghostdev.gamedev-pt.net/Downloads/dmfload1.jpg
www.ghostdev.gamedev-pt.net/Downloads/dmfload2.jpg
www.ghostdev.gamedev-pt.net/Downloads/dmfload3.jpg
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
GhostManZero
Member


Joined: 05 Nov 2005
Posts: 10

PostPosted: Sun Nov 06, 2005 11:21 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website MSN Messenger
Jeroen
Site Admin


Joined: 07 Aug 2004
Posts: 5332
Location: The Netherlands

PostPosted: Sun Nov 06, 2005 12:15 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Mr.Fletcher
DeleD PRO user


Joined: 07 Aug 2004
Posts: 1772
Location: Germany

PostPosted: Sun Nov 06, 2005 12:47 pm    Post subject: Reply with quote

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 Smile
DeleD on IRC
Back to top
View user's profile Send private message
GhostManZero
Member


Joined: 05 Nov 2005
Posts: 10

PostPosted: Sun Nov 06, 2005 2:42 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website MSN Messenger
Daaark
DeleD PRO user


Joined: 01 Sep 2004
Posts: 2696
Location: Ottawa, Canada

PostPosted: Sun Nov 06, 2005 2:56 pm    Post subject: Reply with quote

Did you normalize the faces? Try disabling backface culling.
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Mr.Fletcher
DeleD PRO user


Joined: 07 Aug 2004
Posts: 1772
Location: Germany

PostPosted: Sun Nov 06, 2005 3:29 pm    Post subject: Reply with quote

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 Smile
DeleD on IRC
Back to top
View user's profile Send private message
Jeroen
Site Admin


Joined: 07 Aug 2004
Posts: 5332
Location: The Netherlands

PostPosted: Sun Nov 06, 2005 4:54 pm    Post subject: Reply with quote

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 Rolling Eyes ) Wink
Back to top
View user's profile Send private message Send e-mail Visit poster's website
GhostManZero
Member


Joined: 05 Nov 2005
Posts: 10

PostPosted: Sun Nov 06, 2005 6:27 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website MSN Messenger
GhostManZero
Member


Joined: 05 Nov 2005
Posts: 10

PostPosted: Sun Nov 06, 2005 7:44 pm    Post subject: Reply with quote

Also, how should i get the texture coords?
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Mr.Fletcher
DeleD PRO user


Joined: 07 Aug 2004
Posts: 1772
Location: Germany

PostPosted: Sun Nov 06, 2005 7:57 pm    Post subject: Reply with quote

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 Smile
DeleD on IRC
Back to top
View user's profile Send private message
Daaark
DeleD PRO user


Joined: 01 Sep 2004
Posts: 2696
Location: Ottawa, Canada

PostPosted: Sun Nov 06, 2005 8:54 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    DeleD Community Edition Forum Index -> DeleD Community Edition All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum