I am new in texture mapping. I installed devil-1.7.8 in my system. Now I am trying to compile the following code:
#include <stdio.h>
#include <IL/il.h>
#include <IL/ilu.h>
#include <IL/ilut.h> //Used for loading the textures#include “camera.h”
#if defined(WIN32)
#include <windows.h>
#endif#if defined(WIN32) || defined(linux)
#include <GL/glut.h>
#elif defined(APPLE)
#include <GLUT/glut.h>
#endifCCamera Camera;
GLfloat XRotated = 0.0;
GLfloat YRotated = 0.0;GLuint Tex1, Tex2; // Textures
void InitTextures(void)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);// Associate a variable to a image and load it
Tex1 = ilutGLLoadImage(“tex1.bmp”);
Tex2 = ilutGLLoadImage(“tex2.bmp”);glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
}
void DrawCube(void)
{
//Draws a cube with two shaded, two one-colored and two textured faces
glBegin(GL_QUADS);
glColor3f(1.0,0.0,0.0);
//front:
glVertex3f(-0.5,-0.5,0.5);
glVertex3f(-0.5,0.5,0.5);
glVertex3f(0.5,0.5,0.5);
glVertex3f(0.5,-0.5,0.5);//back: glColor3f(0.0,0.0,1.0); glVertex3f(-0.5,-0.5,-0.5); glVertex3f(0.5,-0.5,-0.5); glVertex3f(0.5,0.5,-0.5); glVertex3f(-0.5,0.5,-0.5); //top: glColor3f(0.0,0.6,1.0); glVertex3f(-0.5,0.5,-0.5); glVertex3f(0.5,0.5,-0.5 ); glColor3f(1.0,0.6,1.0); glVertex3f(0.5,0.5,0.5); glVertex3f(-0.5,0.5,0.5); //bottom: glColor3f(0.0,0.6,0.0); glVertex3f(-0.5,-0.5,-0.5); glColor3f(0.6,0.6,0.6); glVertex3f(-0.5,-0.5,0.5); glColor3f(1.0,1.0,0.3); glVertex3f(0.5,-0.5,0.5); glColor3f(0.0,1.0,0.0); glVertex3f(0.5,-0.5,-0.5);
glEnd();
glEnable(GL_TEXTURE_2D);
glBindTexture( GL_TEXTURE_2D, Tex1);
glBegin(GL_QUADS);
//left:
glTexCoord2f(1.0,0.0);
glVertex3f(-0.5,-0.5,-0.5);
glTexCoord2f(1.0,1.0);
glVertex3f(-0.5,0.5,-0.5);
glTexCoord2f(0.0,1.0);
glVertex3f(-0.5,0.5,0.5);
glTexCoord2f(0.0,0.0);
glVertex3f(-0.5,-0.5,0.5);
glEnd();
//right:
glBindTexture( GL_TEXTURE_2D, Tex2);
glBegin(GL_QUADS);
glTexCoord2f(0.0,0.0);
glVertex3f(0.5,-0.5,-0.5);
glTexCoord2f(1.0,0.0);
glVertex3f(0.5,-0.5,0.5);
glTexCoord2f(1.0,1.0);
glVertex3f(0.5,0.5,0.5);
glTexCoord2f(0.0,1.0);
glVertex3f(0.5,0.5,-0.5);
glEnd();
glDisable(GL_TEXTURE_2D);}
void reshape(int x, int y)
{
if (y == 0 || x == 0) return;glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(40.0,(GLdouble)x/(GLdouble)y,0.5,20.0);glMatrixMode(GL_MODELVIEW);
glViewport(0,0,x,y);
}void Display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
Camera.Render();
glRotatef(YRotated,0.0,1.0,0.0);
// glRotatef(XRotated,1.0,0.0,0.0);
DrawCube();glFlush();
glutSwapBuffers();}
void KeyDown(unsigned char key, int x, int y)
{
switch (key)
{
case 27: //ESC
PostQuitMessage(0);
break;
case ‘a’:
Camera.RotateY(5.0);
Display();
break;
case ‘d’:
Camera.RotateY(-5.0);
Display();
break;
case ‘w’:
Camera.MoveForwards( -0.1 ) ;
Display();
break;
case ‘s’:
Camera.MoveForwards( 0.1 ) ;
Display();
break;
case ‘x’:
Camera.RotateX(5.0);
Display();
break;
case ‘y’:
Camera.RotateX(-5.0);
Display();
break;
case ‘c’:
Camera.StrafeRight(-0.1);
Display();
break;
case ‘v’:
Camera.StrafeRight(0.1);
Display();
break;
case ‘r’:
Camera.Move(F3dVector(0.0,0.1,0.0));
Display();
break;
case ‘f’:
Camera.Move(F3dVector(0.0,-0.1,0.0));
Display();
break;
case ‘b’:
if (glIsEnabled(GL_CULL_FACE) == GL_TRUE)
{
glDisable(GL_CULL_FACE);
glPolygonMode(GL_FRONT, GL_LINE);
glPolygonMode(GL_BACK, GL_FILL);
}
else
{
glEnable(GL_CULL_FACE);
glPolygonMode(GL_FRONT, GL_FILL);
}
Display();
break;
}
}void Idle(void)
{
YRotated += 0.4;
XRotated += 0.4;
Display();
}int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(300,300);
glutCreateWindow(“Textures and BfC”);// Handling images
ilInit();
iluInit();
ilutRenderer(ILUT_OPENGL);glFrontFace(GL_CW); //Clockwise is front in “DrawCube()”
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
Camera.Move( F3dVector(0.0, 0.0, 3.0 ));
Camera.MoveForwards( 1.0 );
InitTextures();
glutDisplayFunc(Display);
glutReshapeFunc(reshape);
glutKeyboardFunc(KeyDown);
glutIdleFunc(Idle);
glutMainLoop();
return 0;
}
but I found the following error.
1>------ Build started: Project: Texture, Configuration: Debug Win32 ------
1>Compiling…
1>Camera.cpp
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\stdlib.h(371) : error C2381: ‘exit’ : redefinition; __declspec(noreturn) differs
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\gl\glut.h(146) : see declaration of ‘exit’
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\stdlib.h(371) : warning C4985: ‘exit’: attributes not present on previous declaration.
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\gl\glut.h(146) : see declaration of ‘exit’
1>main.cpp
1>c:\users\shamima\documents\visual studio 2008\projects\project1 exture exture\main.cpp(79) : error C2664: ‘ilutGLLoadImage’ : cannot convert parameter 1 from ‘const char [9]’ to ‘wchar_t *’
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\shamima\documents\visual studio 2008\projects\project1 exture exture\main.cpp(80) : error C2664: ‘ilutGLLoadImage’ : cannot convert parameter 1 from ‘const char [9]’ to ‘wchar_t *’
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>Generating Code…
1>Build log was saved at “file://c:\Users\shamima\Documents\Visual Studio 2008\Projects\Project1\Texture\Texture\Debug\BuildLog.htm”
1>Texture - 3 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Could any one help me identify the problem. Thanks.