Complex 3D-models with OpenGL

Complex 3D-models with OpenGL

Post by Ralf Schad » Tue, 24 Jun 2003 17:59:55



Hi,

I converted a complex 3D car modell from lightwave-format into the OpenGL
C-Code format with Win3D-Demoversion. Now I have a headerfile with
variable-declarations and a C-file with the various vertices. The headerfile
declare these structs:

/* Light Definitions */
typedef struct
{
 float  color[3];
 float  position[3];
 int   isSpot;
 float  direction[3];
 float  radius;
 float  falloff;

Quote:}Light_Def;

#define MAX_LIGHTS (3)

/* Material Definitions */
typedef struct
{
 float ambient[3];
 float diffuse[3];
 float specular[3];
 float emission[3];
 float alpha;
 int   texture;

Quote:}Material_Def;

#define MAX_MATERIALS (27)

/* Texture Map Definitions */
typedef struct
{
 char *name;
 int  id;

Quote:}Map_Def;

#define MAX_TEXTUREMAPS (0)

/* Object Definitions */
typedef struct
{
 char  *obj_name;
 int   *face_indicies;
 int   face_number;
 float *verticies;
 int   vertex_number;
 float *normals;
 int   normal_number;
 float *textures;
 int   texture_number;
 int   mat_ref;

Quote:}Object_Def;

#define MAX_OBJECTS (27)

My OpenGL-program use this object-struct:
    ::glNewList((GLint)LIST_GOLF, GL_COMPILE_AND_EXECUTE);
    ::glDisable(GL_LIGHTING);
    ::glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
    ::glEnable(GL_POLYGON_OFFSET_LINE);
    ::glBegin(GL_TRIANGLES);
        ::glColor4d(1.0, 1.0, 0.0, 1.0);
        for (j = 0; j < MAX_OBJECTS; j++) {
            for (i = 0; i < (::objects[j].vertex_number * 3); i += 3) {
               ::glMaterialfv(GL_FRONT, GL_AMBIENT,
materials[objects[j].mat_ref].ambient);
               ::glMaterialfv(GL_FRONT, GL_DIFFUSE,
materials[objects[j].mat_ref].diffuse);
               ::glMaterialfv(GL_FRONT, GL_EMISSION,
materials[objects[j].mat_ref].emission);
               ::glMaterialfv(GL_FRONT, GL_SPECULAR,
materials[objects[j].mat_ref].specular);
               ::glNormal3fv(&(::objects[j].normals[i]));
               ::glVertex3fv(&(::objects[j].verticies[i]));
            }
         }
        ::glEnd();
        ::glEndList();

The result is dissatisfying. Independent from polygonmode the model appears
only as wire-model, light and material-definitions have no bearing on model.
I don't know how I can use the field "faces" in the object-struct. PovRay
support "faces" directly. How can I use faces with OpenGL?
I'm a OpenGL-beginner and if you are find any mistakes on my code, please
give hints to me. Does exists online-tutorials for OpenGL and manage complex
3D models?

(Sorry for the bad english)

Ciao, Ralf

 
 
 

Complex 3D-models with OpenGL

Post by fungu » Tue, 24 Jun 2003 18:25:30



>     ::glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
>     ::glEnable(GL_POLYGON_OFFSET_LINE);
>     ::glBegin(GL_TRIANGLES);
>         ::glColor4d(1.0, 1.0, 0.0, 1.0);
>         for (j = 0; j < MAX_OBJECTS; j++) {
>             for (i = 0; i < (::objects[j].vertex_number * 3); i += 3) {
>                ::glMaterialfv(GL_FRONT, GL_AMBIENT,
> materials[objects[j].mat_ref].ambient);
>                ::glMaterialfv(GL_FRONT, GL_DIFFUSE,
> materials[objects[j].mat_ref].diffuse);
>                ::glMaterialfv(GL_FRONT, GL_EMISSION,
> materials[objects[j].mat_ref].emission);
>                ::glMaterialfv(GL_FRONT, GL_SPECULAR,
> materials[objects[j].mat_ref].specular);
>                ::glNormal3fv(&(::objects[j].normals[i]));
>                ::glVertex3fv(&(::objects[j].verticies[i]));
>             }
>          }
>         ::glEnd();
>         ::glEndList();

> The result is dissatisfying. Independent from polygonmode the model appears
> only as wire-model

That's what "glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);"
does...if you ask for it, you get it.

Quote:>, light and material-definitions have no bearing on model.

You're not allowed to change materials between
glBegin() and glEnd(). glMaterialfv() will
have no effect inside the loop.

--
<\___/>          For email, remove my socks.
/ O O \
\_____/  FTB.    Why isn't there mouse-flavored cat food?

 
 
 

Complex 3D-models with OpenGL

Post by Andrew F. Vespe » Wed, 25 Jun 2003 09:13:04



> You're not allowed to change materials between
> glBegin() and glEnd(). glMaterialfv() will
> have no effect inside the loop.

I've got to keep you honest, fungus ---

Material *is* allowed inside Begin/End.

--
Andy V (OpenGL Alpha Geek)
"In order to make progress, one must leave the door to the unknown ajar."
Richard P. Feynman, quoted by Jagdish Mehra in _The Beat of a Different Drum_.

OpenGL Technical FAQ: http://www.opengl.org/developers/faqs/technical.html

 
 
 

Complex 3D-models with OpenGL

Post by fungu » Wed, 25 Jun 2003 10:08:42



> I've got to keep you honest, fungus ---

> Material *is* allowed inside Begin/End.

Oh, yes, you're right.

At least I know you're paying attention.

--
<\___/>          For email, remove my socks.
/ O O \
\_____/  FTB.    Why isn't there mouse-flavored cat food?

 
 
 

Complex 3D-models with OpenGL

Post by Ralf Schad » Wed, 25 Jun 2003 15:28:26



> That's what "glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);"
> does...if you ask for it, you get it.

PolygonMode with GL_FILL don't work for me. I need the model-surfaces, but I
don't know, how object-faces from converter work in OpenGL.

Ciao, Ralf

 
 
 

1. Complex Models in OpenGL.

Hello,

I was wondering which software to use in order to create a 3D model, such as
a boat or even a human using Triangles only and then to export and import
this model in my OpenGL app?

Thanks for your bright answers.

2. a quicker intersection test

3. Ideas for complex models gened models?

4. News For Dec 21st

5. INFO: optimizing complex models

6. Desktop Video & Computer Symposium

7. How to build complex models

8. Shake Roof Texture?

9. Probs with modeling complex caves

10. texture mapping with a complex model.......

11. Texturing a complex subdivision model

12. Looking for really complex .iv models...

13. Complex CSG using OpenGL