hi all . i write and make simple program.
this program when started , load wavefront obj file(AUTO).
i Write and prepearing OPENGL and then add this code.
when compile it. 4 error riceved.
1- make new Glm.h and add to header file project (Show in Below).
#include <GL/glut.h>
#ifndef M_PI
#define M_PI 3.14159265
#endif
#define GLM_NONE (0) /* render with only vertices */
#define GLM_FLAT (1 << 0) /* render with facet normals */
#define GLM_SMOOTH (1 << 1) /* render with vertex normals */
#define GLM_TEXTURE (1 << 2) /* render with texture coords */
#define GLM_COLOR (1 << 3) /* render with colors */
#define GLM_MATERIAL (1 << 4) /* render with materials */
typedef struct _GLMmaterial
{
char* name;
GLfloat diffuse[4];
GLfloat ambient[4];
GLfloat specular[4];
GLfloat emmissive[4];
GLfloat shininess;
} GLMmaterial;
typedef struct {
GLuint vindices[3];
GLuint nindices[3];
GLuint tindices[3];
GLuint findex;
} GLMtriangle;
typedef struct _GLMgroup {
char* name;
GLuint numtriangles;
GLuint* triangles;
GLuint material;
struct _GLMgroup* next;
} GLMgroup;
typedef struct {
char* pathname;
char* mtllibname;
GLuint numvertices;
GLfloat* vertices;
GLuint numnormals;
GLfloat* normals;
GLuint numtexcoords;
GLfloat* texcoords;
GLuint numfacetnorms;
GLfloat* facetnorms;
GLuint numtriangles;
GLMtriangle* triangles;
GLuint nummaterials;
GLMmaterial* materials;
GLuint numgroups;
GLMgroup* groups;
GLfloat position[3];
} GLMmodel;
GLfloat
glmUnitize(GLMmodel* model);
GLvoid
glmDimensions(GLMmodel* model, GLfloat* dimensions);
GLvoid
glmScale(GLMmodel* model, GLfloat scale);
GLvoid
glmReverseWinding(GLMmodel* model);
GLvoid
glmFacetNormals(GLMmodel* model);
GLvoid
glmVertexNormals(GLMmodel* model, GLfloat angle);
GLvoid
glmLinearTexture(GLMmodel* model);
GLvoid
glmSpheremapTexture(GLMmodel* model);
GLvoid
glmDelete(GLMmodel* model);
GLMmodel*
glmReadOBJ(char* filename);
GLvoid
glmWriteOBJ(GLMmodel* model, char* filename, GLuint mode);
GLvoid
glmDraw(GLMmodel* model, GLuint mode);
GLuint
glmList(GLMmodel* model, GLuint mode);
GLvoid
glmWeld(GLMmodel* model, GLfloat epsilon);
2-added the following variables to represent different types of objects
GLuint m_MonitorList; / / Display
GLuint m_ChairList; / / chair
GLuint m_PotList; / / vase
GLuint m_ComputerList; / / Computer
int m_nObjectNo;
3-drawing function modified as follows:
i add this function.
void OpenGLView::RenderScene ()
{
gluLookAt(m_PosX,m_PosY,m_PosZ,m_DirX,m_DirY,m_DirZ,0.0f,1.0f,0.0f);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_Texture[3]);
glBegin(GL_POLYGON);
glColor3ub(0,255,0);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-2.0f, 0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(2.0f,0.0f, 0.0f);
glColor3ub(0,100,0);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(2.0f, 0.0f, -2.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-2.0f,0.0f, -2.0f);
glEnd();
glDisable(GL_TEXTURE_2D);
glPushMatrix();
glTranslatef(-1.0f,0.6f,-1.0f);
glRotatef(m_xRot,1.0f,0.0f,0.0f);
glRotatef(m_yRot,0.0f,1.0f,0.0f);
DrawCube(FALSE);
glPopMatrix();
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glPushMatrix();
glMultMatrixf((GLfloat *)m_ShadowMat);
glTranslatef(-1.0f,0.6f,-1.0f);
glRotatef(m_xRot,1.0f,0.0f,0.0f);
glRotatef(m_yRot,0.0f,1.0f,0.0f);
DrawCube(TRUE);
glPopMatrix();
glEnable(GL_DEPTH_TEST);
glPushMatrix();
glTranslatef(1.5f,1.5f,-1.0f);
glColor3ub(255,255,0);
glutSolidSphere(0.01f,10,10);
glPopMatrix();
glEnable(GL_LIGHTING);
}
void OpenGLView::DrawCube (BOOL bShadow)
{
if(!bShadow)
{
switch (m_nObjectNo)
{
case 0: glCallList(m_ChairList);
break;
case 1: glCallList(m_PotList);
break;
case 2: glCallList(m_ComputerList);
break;
case 3: glCallList(m_MonitorList);
break;
case 4: DrawCubeTex();
break;
}
}
else
{
glColor3ub(0,0,0);
switch (m_nObjectNo)
{
case 0: glCallList(m_ChairList);
break;
case 1: glCallList(m_PotList);
break;
case 2: glCallList(m_ComputerList);
break;
case 3: glCallList(m_MonitorList);
break;
case 4: DrawCubeNoTex();
break;
}
}
}
4-Obj file loading concrete realization of the code:
i add this Function
void OpenGLView::LoadModelsFromFiles()
{
GLfloat scalefactor = 0.0;
GLMmodel *object1;
object1 = glmReadOBJ("models/computer.obj");
if(!scalefactor)
{
scalefactor = glmUnitize(object1);
}
else
{
glmScale(object1, scalefactor);
}
glmScale(object1, 2.5);
m_ComputerList = glmList(object1, GLM_SMOOTH);
glmDelete(object1);
GLMmodel *object2;
scalefactor = 0.0;
object2 = glmReadOBJ("models/chair04.obj");
if(!scalefactor)
{
scalefactor = glmUnitize(object2);
}
else
{
glmScale(object2, scalefactor);
}
glmScale(object2, 5.0);
m_ChairList = glmList(object2, GLM_SMOOTH);
glmDelete(object2);
GLMmodel *object5;
scalefactor = 0.0;
object5 = glmReadOBJ("models/samsung.obj");
if(!scalefactor)
{
scalefactor = glmUnitize(object5);
}
else
{
glmScale(object5, scalefactor);
}
glmScale(object5, 0.5);
m_MonitorList = glmList(object5, GLM_SMOOTH);
glmDelete(object5);
GLMmodel *object6;
scalefactor = 0.0;
object6 = glmReadOBJ("models/plant2.obj");
if(!scalefactor)
{
scalefactor = glmUnitize(object6);
}
else
{
glmScale(object6, scalefactor);
}
glmScale(object6, 0.5);
m_PotList = glmList(object6, GLM_SMOOTH);
glmDelete(object6);
}
My ERROR when i compiling is Showing in below:
1-DrawCubeTex().
2-DrawCubeNoTex().
3-glutSolidSphere(0.01f,10,10)
4- and type of m_Texture.
Ohter error solved.
Please Help me to solve and compiling simple program to load obj file(AUTO)