Jump to content
  • Advertisement
Sign in to follow this  
orestas

OpenGL adding materials from .3ds file.

This topic is 3338 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

hello, i have bin trying to modify the code from spacesimulator.net to load multiply materials and then add them to the object using opengl. for example atm i got smth like this for diffuse color loading:
//Name       : Material name
			case 0xA000:
				i=0;
				printf("Material name: ");
				do
				{
					fread (&l_char, 1, 1, l_file);
                    p_object->mat_name=l_char;
					printf("%c",p_object->mat_name);
					i++;
                }while(l_char != '\0' && i<20);
				printf("\n");
			break;
			//Name       : Material diffuse color
			case 0xA020:
			break;
			//Name       : Rgb color (byte format)
			case 0x0011:
				fread (&p_object->colorDiffuse[0], sizeof (unsigned char), 1, l_file);
				printf("diffuse.r %u\n",p_object->colorDiffuse[0]);
				fread (&p_object->colorDiffuse[1], sizeof (unsigned char), 1, l_file);
				printf("diffuse.g %u\n",p_object->colorDiffuse[1]);
				fread (&p_object->colorDiffuse[2], sizeof (unsigned char), 1, l_file);
				printf("diffuse.b %u\n",p_object->colorDiffuse[2]);
			break;

and i get this output:
Material name: red
diffuse.r 242
diffuse.g 35
diffuse.b 35
Material name: green
diffuse.r 67
diffuse.g 245
diffuse.b 54
*****************OBJECT***************
Object name: Box01
Number of vertices: 26
Number of polygons: 12
material name: red
Number of faces assigned to this material: 6
map_face 0
map_face 1
map_face 6
map_face 7
map_face 8
map_face 9
material name: green
Number of faces assigned to this material: 6
map_face 2
map_face 3
map_face 4
map_face 5
map_face 10
map_face 11
well, imagine there is shininess specular and all other attributes that material needs also loaded. with this:
glBegin(GL_TRIANGLES);
    for (l_index=0;l_index<object.polygons_qty;l_index++)
    {
        //----------------- FIRST VERTEX -----------------
		//Normal coordinates of the first vertex
		glNormal3f( object.normal[ object.polygon[l_index].a ].x,
					object.normal[ object.polygon[l_index].a ].y,
					object.normal[ object.polygon[l_index].a ].z);
        // Texture coordinates of the first vertex
        glTexCoord2f( object.mapcoord[ object.polygon[l_index].a ].u,
                      object.mapcoord[ object.polygon[l_index].a ].v);
        // Coordinates of the first vertex
        glVertex3f( object.vertex[ object.polygon[l_index].a ].x,
                    object.vertex[ object.polygon[l_index].a ].y,
                    object.vertex[ object.polygon[l_index].a ].z);
               //( and so on with 2nd and 3rd vertex... )

i can get the base object loaded, but i have no idea how to apply that information about the materials i got from 3ds file to this object:/ if someone could help me with a peace of advice i would be really grateful. sry for the wall of text, if i forgot smth or smth is not clear please just write in here and ill try to explain it, thx. [Edited by - orestas on October 23, 2009 3:25:22 PM]

Share this post


Link to post
Share on other sites
Advertisement
You can apply those attributes through the use of materials,

glMaterialfv(GL_FRONT, GL_SPECULAR, matSpec);
glMaterialfv(GL_FRONT, GL_AMBIENT, matAmb);
glMaterialfv(GL_FRONT, GL_DIFFUSE, matDiff);
glMaterialf(GL_FRONT, GL_SHININESS, matShiny);

All those attributes are stored in a 3ds material.

Keep in mind that 3ds's shininess attribute is scaled from 0 -> 1. You'll have to multiply this by 128 to get it into opengl's range.

Share this post


Link to post
Share on other sites
Quote:
Original post by bryguy512
You can apply those attributes through the use of materials,

glMaterialfv(GL_FRONT, GL_SPECULAR, matSpec);
glMaterialfv(GL_FRONT, GL_AMBIENT, matAmb);
glMaterialfv(GL_FRONT, GL_DIFFUSE, matDiff);
glMaterialf(GL_FRONT, GL_SHININESS, matShiny);

All those attributes are stored in a 3ds material.

Keep in mind that 3ds's shininess attribute is scaled from 0 -> 1. You'll have to multiply this by 128 to get it into opengl's range.


ty for replying to this thread.

yeah, well i understand that, but what if i have for example 2 materials both with its own specular, ambient, diffuse, shininess and so on, how can i say to the gl what triangles i need apply those materials to, keep in mind the way im drawing them, its from an array of vertices that i read from 3ds file.
this might be a really easy job to do, but im kinda new to opengl:/

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!