[Résolu][OpenGl] Problème avec glLightfv

Salut salut,

je fais un exercice pour un cours d’OpenGl et je dois dire que je désespère…

J’ai fait deux cubes, un grand cube et un petit d’où la lumière est censé provenir.
Mais le problème est que la lumière n’est pas du tout au bon endroit.
Mon problème est dans le while du main().

[codebox]// Project: Template
// Goal : basis for an SDL based OpenGL program
// Author : VRLab - EPFL, 2007

//include
#include <windows.h>
#include <SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>

//lib
#pragma comment(lib, “opengl32.lib”)
#pragma comment(lib, “glu32.lib”)
#pragma comment(lib, “sdl.lib”)
#pragma comment(lib, “sdlmain.lib”)

//define
#define WINDOW_TITLE “OpenGL template”
#define WINDOW_X 640.0 //Window width
#define WINDOW_Y 480.0 //Window height
#define WINDOW_COLORDEPTH 32 //Color depth (in bits)
#define WINDOW_ZETADEPTH 24 //z-buffer depth (in bits)

// Global variables
bool done = false; //Quit application when true
//float delta = 0.0;
float deltaX = 0.0;
float deltaY = 0.0;
float ownRot = 0.0;
float buttonLeftRot = 0.0;
float cameraZoom = -10.0f;
bool keyboardSPressed = false;
bool keyboardQPressed = false;
bool keyboardAPressed = false;
bool mouseButtonLeftPressed = false;
bool mouseButtonRightPressed = false;
bool keyboardLeftPressed = false;
bool keyboardRightPressed = false;
bool keyboardUpPressed = false;
bool keyboardDownPressed = false;
bool keyboardWPressed = false;
int mode = 0;
int normal = 0;
//Store my display list identification number
unsigned int myListId = 0;

int InitSDLWithOpenGLcontext()
{
//Init SDL
if (SDL_Init(SDL_INIT_VIDEO) == -1)
{
printf(“Error: unable to init SDL!\n”);
return 1;
}

//Prepare configuration
int bitsPerColor = 8;
if (WINDOW_COLORDEPTH == 16) 
	bitsPerColor = 5;
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, bitsPerColor);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, bitsPerColor);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, bitsPerColor);	
SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, 0);     
SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, 0);   
SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, 0);
SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 0);   
if (WINDOW_COLORDEPTH == 32) 
	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
else 
	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0);   
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, WINDOW_ZETADEPTH);	
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);	

//Create surface
unsigned flags = SDL_OPENGL;		
SDL_WM_SetCaption(WINDOW_TITLE, NULL);   
if (SDL_SetVideoMode(WINDOW_X, WINDOW_Y, WINDOW_COLORDEPTH, flags) == NULL) 
{
	printf("ERROR: unsupported video configuration!\n");			
	return 1;			
}

return 0;

}

void InitOpenGL()
{

//in OpenGL Init	
//light
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);	

glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

glEnable(GL_DEPTH_TEST);
glEnable(GL_FRONT_FACE);	//CULL

// Setup a perspective view:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,					// Field of view
					WINDOW_X/WINDOW_Y,	// width/height ratio
					1.0f,						// near clipping plane
					1000.0f);				// far clipping plane


	//In init OpenGL
	//Create display list
	myListId = glGenLists(1);
	glNewList(myListId, GL_COMPILE);	
	glBegin(GL_QUADS);

	glNormal3f(0.5,0.5,0.0);
	glColor3f(0.0, 0.0, 1.0);
	glVertex3f(0.0, 1.0, 0.0);
	glVertex3f(1.0, 1.0, 0.0);
	glVertex3f(1.0, 0.0, 0.0);
	glVertex3f(0.0, 0.0, 0.0);

	glNormal3f(0.0,0.5,0.5);
	glColor3f(0.0, 1.0, 0.0);
	glVertex3f(0.0, 0.0, 0.0);
	glVertex3f(0.0, 0.0, 1.0);
	glVertex3f(0.0, 1.0, 1.0);
	glVertex3f(0.0, 1.0, 0.0);

	glNormal3f(0.5,0.0,0.5);
	glColor3f(0.0, 1.0, 1.0);
	glVertex3f(0.0, 0.0, 0.0);
	glVertex3f(1.0, 0.0, 0.0);
	glVertex3f(1.0, 0.0, 1.0);
	glVertex3f(0.0, 0.0, 1.0);

	glNormal3f(1.0,0.5,0.5);
	glColor3f(1.0, 0.0, 0.0);
	glVertex3f(1.0, 0.0, 0.0);
	glVertex3f(1.0, 0.0, 1.0);
	glVertex3f(1.0, 1.0, 1.0);
	glVertex3f(1.0, 1.0, 0.0);

	glNormal3f(0.5,1.0,0.5);
	glColor3f(1.0, 0.0, 1.0);
	glVertex3f(1.0, 1.0, 0.0);
	glVertex3f(1.0, 1.0, 1.0);
	glVertex3f(0.0, 1.0, 1.0);
	glVertex3f(0.0, 1.0, 0.0);

	glNormal3f(0.5,0.5,1.0);
	glColor3f(1.0, 1.0, 0.0);
	glVertex3f(1.0, 0.0, 1.0);
	glVertex3f(0.0, 0.0, 1.0);
	glVertex3f(0.0, 1.0, 1.0);
	glVertex3f(1.0, 1.0, 1.0);

	glEnd();
	glEndList ();

	//In the rendering part

}

void CheckEvents()
{
//events
SDL_Event _event;
while(SDL_PollEvent(&_event))
{
//Window
//quit by click on x:
if(_event.type == SDL_QUIT) { done = true; }

	//Keyboard
	if(_event.type == SDL_KEYDOWN)
	{
		//quit
		if(_event.key.keysym.sym == SDLK_ESCAPE)
		{
			done = true;
		}
	}

	if(_event.type == SDL_KEYDOWN)
	{
		if(_event.key.keysym.sym == SDLK_w)
		{
			keyboardWPressed = true;
			mode++;
			if(mode==100) mode = 0;
		}
	}
	if(_event.type == SDL_KEYUP){
	if(_event.key.keysym.sym == SDLK_w){
		keyboardWPressed = false;
	}
	}

	if(_event.type == SDL_KEYDOWN)
	{
		if(_event.key.keysym.sym == SDLK_q)
		{
			keyboardQPressed = true;
			mode++;
			if(mode==100) mode = 0;
		}
	}
	if(_event.type == SDL_KEYUP){
	if(_event.key.keysym.sym == SDLK_q){
		keyboardQPressed = false;
	}
	}

	if(_event.type == SDL_KEYDOWN)
	{
		if(_event.key.keysym.sym == SDLK_a)
		{
			keyboardAPressed = true;
			mode++;
			if(mode==100) mode = 0;
		}
	}
	if(_event.type == SDL_KEYUP){
	if(_event.key.keysym.sym == SDLK_a){
		keyboardAPressed = false;
	}
	}

	if(_event.type == SDL_KEYDOWN)
	{
		if(_event.key.keysym.sym == SDLK_s)
		{
			keyboardSPressed = true;
			mode++;
			if(mode==100) mode = 0;
		}
	}
	if(_event.type == SDL_KEYUP){
	if(_event.key.keysym.sym == SDLK_s){
		keyboardSPressed = false;
	}
	}

	//keyboard direction
	if(_event.type == SDL_KEYDOWN)
	{
	if(_event.key.keysym.sym == SDLK_LEFT){
		keyboardLeftPressed = true;
	}
	}
	if(_event.type == SDL_KEYUP){
	if(_event.key.keysym.sym ==SDLK_LEFT){
		keyboardLeftPressed = false;
	}
	}

	if(_event.type == SDL_KEYDOWN)
	{
	if(_event.key.keysym.sym == SDLK_RIGHT){
		keyboardRightPressed = true;
	}
	}
	if(_event.type == SDL_KEYUP){
	if(_event.key.keysym.sym ==SDLK_RIGHT){
		keyboardRightPressed = false;
	}
	}

	if(_event.type == SDL_KEYDOWN)
	{
	if(_event.key.keysym.sym == SDLK_UP){
		keyboardUpPressed = true;
	}
	}
	if(_event.type == SDL_KEYUP){
	if(_event.key.keysym.sym ==SDLK_UP){
		keyboardUpPressed = false;
	}
	}

	if(_event.type == SDL_KEYDOWN)
	{
	if(_event.key.keysym.sym == SDLK_DOWN){
		keyboardDownPressed = true;
	}
	}
	if(_event.type == SDL_KEYUP){
	if(_event.key.keysym.sym ==SDLK_DOWN){
		keyboardDownPressed = false;
	}
	}

	//Mouse
	if(_event.type == SDL_MOUSEBUTTONDOWN)
	{
		if(_event.button.button == SDL_BUTTON_LEFT)
		{
			mouseButtonLeftPressed = true;
		}
	}
	if(_event.type == SDL_MOUSEBUTTONUP)
	{
		if(_event.button.button == SDL_BUTTON_LEFT)
		{
			mouseButtonLeftPressed = false;
		}
	}

	if(_event.type == SDL_MOUSEBUTTONDOWN)
	{
		if(_event.button.button == SDL_BUTTON_RIGHT)
		{
			mouseButtonRightPressed = true;
			
		}
	}
	if(_event.type == SDL_MOUSEBUTTONUP)
	{
		if(_event.button.button == SDL_BUTTON_RIGHT)
		{
			mouseButtonRightPressed = false;
		}
	}
}

}

int main( int argc, char **argv )
{
InitSDLWithOpenGLcontext();

InitOpenGL();

while (!done)
{  
	//update data
	if(keyboardLeftPressed) deltaY -= 1.0f;
	if(keyboardRightPressed) deltaY +=1.0f;
	if(keyboardUpPressed)	deltaX -=1.0f;
	if(keyboardDownPressed)	deltaX +=1.0f;
	if(keyboardWPressed && mode%2==1) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	else if(keyboardWPressed && mode%2==0) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	if(mouseButtonRightPressed) ownRot +=1.0f;
	if(mouseButtonLeftPressed) buttonLeftRot++;
	if(keyboardQPressed) cameraZoom--;
	if(keyboardAPressed) cameraZoom++;
	//clear buffers
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	//place the camera
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	float lightPosition[] = {2.5, 0.5, -7.5, 1.0}; 
	glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
			
	//position the camera
	//gluLookAt(1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
	glTranslatef(0.0f, 0.0f, cameraZoom); 


	glRotatef(deltaX ,1.0f,0.0f, 0.0f);
	glRotatef(deltaY ,0.0f,1.0f, 0.0f);



	//in the rendering loop
	glPushMatrix();
	glTranslatef(lightPosition[0], lightPosition[1], lightPosition[2]);		
	glScalef(0.1f, 0.1f, 0.1f);
	
	glCallList(myListId);	
	glPopMatrix();

	//render some geometry
	glLineWidth(2.0);
	glBegin(GL_LINES);
	glColor3f(1.0, 0.0, 0.0); glVertex3f(0.0, 0.0, 0.0); glVertex3f(2.0, 0.0, 0.0);
	glColor3f(0.0, 1.0, 0.0); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 2.0, 0.0);
	glColor3f(0.0, 0.0, 1.0); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 0.0, 2.0);
	glEnd();

	//begin

	glRotatef(buttonLeftRot,1.0f,1.0f,1.0f);
	//normale
	if(keyboardSPressed){
	glBegin(GL_LINES);
	glColor3f(1.0, 1.0, 1.0); glVertex3f(0.5, 0.5, 0.0); glVertex3f(0.5, 0.5, -1.0);
	glColor3f(1.0, 1.0, 1.0); glVertex3f(0.0, 0.5, 0.5); glVertex3f(-1.0, 0.5, 0.5);
	glColor3f(1.0, 1.0, 1.0); glVertex3f(0.5, 0.0, 0.5); glVertex3f(0.5, -1.0, 0.5);
	glColor3f(1.0, 1.0, 1.0); glVertex3f(1.0, 0.5, 0.5); glVertex3f(2.0, 0.5, 0.5);
	glColor3f(1.0, 1.0, 1.0); glVertex3f(0.5, 1.0, 0.5); glVertex3f(0.5, 2.0, 0.5);
	glColor3f(1.0, 1.0, 1.0); glVertex3f(0.5, 0.5, 1.0); glVertex3f(0.5, 0.5, 2.0);
	glEnd();
	}
	glCallList(myListId);

	//end

	CheckEvents();

	SDL_GL_SwapBuffers();

	Sleep(20); //slow down the application

}

//clean OpenGL (if needed)

//Clean OpenGL
glDeleteLists(myListId, 1);

//free SDL

SDL_Quit();

return 0;
}[/codebox]

Si jamais pour les touches :
Q et A pour le zoom
S pour les normales
clic gauche pour la rotation du grand cube
et les touches de directions pour bouger la caméra

Merci à celui qui trouvera l’erreur.
B)

J’ai pas lu le code, mais ta lumière est bien dans le bon référentiel ?
(pas de gltranslate ou glloadidentity mal placé ?

[quote=“alt3, post:2, topic: 46317”]J’ai pas lu le code, mais ta lumière est bien dans le bon référentiel ?
(pas de gltranslate ou glloadidentity mal placé ?[/quote]
Je ne pense pas qu’il y ait un problème avec un gltranslate ou un glloadidentity parce que si j’enlève tout ce qui est en rapport avec l’éclairage tout fonctionne parfaitement.

Ce n’est pas incompatible avec ma remarque.

Tu connais nehe.gamedev;net ?

Non je ne connaissais pas, mais je vais regarder tout ça ce weekend. B)

Le probleme me semble assez simple tousse tousse
c’est une question d’ordre…
(et la reponse demain, si t’as pas encore trouve B) )

Je ne dois pas avoir très bien compris comment ordrer mes lignes de code parce que c’est toujours pire, soit il n’y a plus de lumière ou bien elle fait encore plus de freestyle…
B) B)

Desol’, j’ai pas eu le temps de revenir!
Le premier truc qui me choque, c’est que tu bouge le monde plutot que la camera…
et ta lumiere, elle a une position fixe…
de plus tu fait ta rotation avant ta translations ce qui est reglo, si tu es sur de ce que tu veux faire!

voila, ca devrait te permettre d’y voir un poil plus claire B)

Enfin trouvé ce qui n’allait pas, pfiou.
C’est juste les normales qui étaient totalement fausses, c’est pour ça que la lumière faisait des effets bizarres. B)

[codebox]// Project: Template
// Goal : basis for an SDL based OpenGL program
// Author : VRLab - EPFL, 2007

//include
#include <windows.h>
#include <SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>

//lib
#pragma comment(lib, “opengl32.lib”)
#pragma comment(lib, “glu32.lib”)
#pragma comment(lib, “sdl.lib”)
#pragma comment(lib, “sdlmain.lib”)

//define
#define WINDOW_TITLE “OpenGL template”
#define WINDOW_X 640.0 //Window width
#define WINDOW_Y 480.0 //Window height
#define WINDOW_COLORDEPTH 32 //Color depth (in bits)
#define WINDOW_ZETADEPTH 24 //z-buffer depth (in bits)

// Global variables
bool done = false; //Quit application when true
//float delta = 0.0;
float deltaX = 0.0;
float deltaY = 0.0;
float ownRot = 0.0;
float buttonLeftRot = 0.0;
float cameraZoom = -10.0f;
float lightRot = 0.0;
bool keyboardSPressed = false;
bool keyboardQPressed = false;
bool keyboardAPressed = false;
bool mouseButtonLeftPressed = false;
bool mouseButtonRightPressed = false;
bool keyboardLeftPressed = false;
bool keyboardRightPressed = false;
bool keyboardUpPressed = false;
bool keyboardDownPressed = false;
bool keyboardWPressed = false;
bool keyboardRPressed = false;
bool keyboardCPressed = false;
int mode = 0;
int modeC = 0;
int normal = 0;
//Store my display list identification number
unsigned int myListId = 0;

int InitSDLWithOpenGLcontext()
{
//Init SDL
if (SDL_Init(SDL_INIT_VIDEO) == -1)
{
printf(“Error: unable to init SDL!\n”);
return 1;
}

//Prepare configuration
int bitsPerColor = 8;
if (WINDOW_COLORDEPTH == 16) 
	bitsPerColor = 5;
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, bitsPerColor);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, bitsPerColor);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, bitsPerColor);	
SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, 0);     
SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, 0);   
SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, 0);
SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 0);   
if (WINDOW_COLORDEPTH == 32) 
	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
else 
	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0);   
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, WINDOW_ZETADEPTH);	
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);	

//Create surface
unsigned flags = SDL_OPENGL;		
SDL_WM_SetCaption(WINDOW_TITLE, NULL);   
if (SDL_SetVideoMode(WINDOW_X, WINDOW_Y, WINDOW_COLORDEPTH, flags) == NULL) 
{
	printf("ERROR: unsupported video configuration!\n");			
	return 1;			
}

return 0;

}

void InitOpenGL()
{
//glEnable(GL_NORMALIZE);
//in OpenGL Init
//light
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);

glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

glEnable(GL_DEPTH_TEST);
glEnable(GL_FRONT_FACE);	//CULL

// Setup a perspective view:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,					// Field of view
					WINDOW_X/WINDOW_Y,	// width/height ratio
					1.0f,						// near clipping plane
					1000.0f);				// far clipping plane


	//In init OpenGL
	//Create display list
	myListId = glGenLists(1);
	glNewList(myListId, GL_COMPILE);	
	glBegin(GL_QUADS);

	glNormal3f(0.0,0.0,-1.0);
	glColor3f(0.0, 0.0, 1.0);
	glVertex3f(0.0, 1.0, 0.0);
	glVertex3f(1.0, 1.0, 0.0);
	glVertex3f(1.0, 0.0, 0.0);
	glVertex3f(0.0, 0.0, 0.0);

	glNormal3f(-1.0,0.0,0.0);
	glColor3f(0.0, 1.0, 0.0);
	glVertex3f(0.0, 0.0, 0.0);
	glVertex3f(0.0, 0.0, 1.0);
	glVertex3f(0.0, 1.0, 1.0);
	glVertex3f(0.0, 1.0, 0.0);

	glNormal3f(0.0,-1.0,0.0);
	glColor3f(0.0, 1.0, 1.0);
	glVertex3f(0.0, 0.0, 0.0);
	glVertex3f(1.0, 0.0, 0.0);
	glVertex3f(1.0, 0.0, 1.0);
	glVertex3f(0.0, 0.0, 1.0);

	glNormal3f(1.0,0.0,0.0);
	glColor3f(1.0, 0.0, 0.0);
	glVertex3f(1.0, 0.0, 0.0);
	glVertex3f(1.0, 0.0, 1.0);
	glVertex3f(1.0, 1.0, 1.0);
	glVertex3f(1.0, 1.0, 0.0);

	glNormal3f(0.0,1.0,0.0);
	glColor3f(1.0, 0.0, 1.0);
	glVertex3f(1.0, 1.0, 0.0);
	glVertex3f(1.0, 1.0, 1.0);
	glVertex3f(0.0, 1.0, 1.0);
	glVertex3f(0.0, 1.0, 0.0);

	glNormal3f(0.0,0.0,1.0);
	glColor3f(1.0, 1.0, 0.0);
	glVertex3f(1.0, 0.0, 1.0);
	glVertex3f(0.0, 0.0, 1.0);
	glVertex3f(0.0, 1.0, 1.0);
	glVertex3f(1.0, 1.0, 1.0);

	glEnd();
	glEndList ();

	//In the rendering part

}

void CheckEvents()
{
//events
SDL_Event _event;
while(SDL_PollEvent(&_event))
{
//Window
//quit by click on x:
if(_event.type == SDL_QUIT) { done = true; }

	//Keyboard
	if(_event.type == SDL_KEYDOWN)
	{
		//quit
		if(_event.key.keysym.sym == SDLK_ESCAPE)
		{
			done = true;
		}
	}

	if(_event.type == SDL_KEYDOWN)
	{
		if(_event.key.keysym.sym == SDLK_w)
		{
			keyboardWPressed = true;
			mode++;
			if(mode==100) mode = 0;
		}
	}
	if(_event.type == SDL_KEYUP){
	if(_event.key.keysym.sym == SDLK_w){
		keyboardWPressed = false;
	}
	}


	if(_event.type == SDL_KEYDOWN)
	{
		if(_event.key.keysym.sym == SDLK_c)
		{
			keyboardCPressed = true;
			modeC++;
			if(modeC==100) modeC = 0;
		}
	}
	if(_event.type == SDL_KEYUP){
	if(_event.key.keysym.sym == SDLK_c){
		keyboardCPressed = false;
	}
	}


	if(_event.type == SDL_KEYDOWN)
	{
		if(_event.key.keysym.sym == SDLK_q)
		{
			keyboardQPressed = true;
			mode++;
			if(mode==100) mode = 0;
		}
	}
	if(_event.type == SDL_KEYUP){
	if(_event.key.keysym.sym == SDLK_q){
		keyboardQPressed = false;
	}
	}

	if(_event.type == SDL_KEYDOWN)
	{
		if(_event.key.keysym.sym == SDLK_a)
		{
			keyboardAPressed = true;
			mode++;
			if(mode==100) mode = 0;
		}
	}
	if(_event.type == SDL_KEYUP){
	if(_event.key.keysym.sym == SDLK_a){
		keyboardAPressed = false;
	}
	}

	if(_event.type == SDL_KEYDOWN)
	{
		if(_event.key.keysym.sym == SDLK_s)
		{
			keyboardSPressed = true;
			mode++;
			if(mode==100) mode = 0;
		}
	}
	if(_event.type == SDL_KEYUP){
	if(_event.key.keysym.sym == SDLK_s){
		keyboardSPressed = false;
	}
	}

	if(_event.type == SDL_KEYDOWN)
	{
		if(_event.key.keysym.sym == SDLK_r)
		{
			keyboardRPressed = true;
		}
	}
	if(_event.type == SDL_KEYUP){
	if(_event.key.keysym.sym == SDLK_r){
		keyboardRPressed = false;
	}
	}	

	//keyboard direction
	if(_event.type == SDL_KEYDOWN)
	{
	if(_event.key.keysym.sym == SDLK_LEFT){
		keyboardLeftPressed = true;
	}
	}
	if(_event.type == SDL_KEYUP){
	if(_event.key.keysym.sym ==SDLK_LEFT){
		keyboardLeftPressed = false;
	}
	}

	if(_event.type == SDL_KEYDOWN)
	{
	if(_event.key.keysym.sym == SDLK_RIGHT){
		keyboardRightPressed = true;
	}
	}
	if(_event.type == SDL_KEYUP){
	if(_event.key.keysym.sym ==SDLK_RIGHT){
		keyboardRightPressed = false;
	}
	}

	if(_event.type == SDL_KEYDOWN)
	{
	if(_event.key.keysym.sym == SDLK_UP){
		keyboardUpPressed = true;
	}
	}
	if(_event.type == SDL_KEYUP){
	if(_event.key.keysym.sym ==SDLK_UP){
		keyboardUpPressed = false;
	}
	}

	if(_event.type == SDL_KEYDOWN)
	{
	if(_event.key.keysym.sym == SDLK_DOWN){
		keyboardDownPressed = true;
	}
	}
	if(_event.type == SDL_KEYUP){
	if(_event.key.keysym.sym ==SDLK_DOWN){
		keyboardDownPressed = false;
	}
	}

	//Mouse
	if(_event.type == SDL_MOUSEBUTTONDOWN)
	{
		if(_event.button.button == SDL_BUTTON_LEFT)
		{
			mouseButtonLeftPressed = true;
		}
	}
	if(_event.type == SDL_MOUSEBUTTONUP)
	{
		if(_event.button.button == SDL_BUTTON_LEFT)
		{
			mouseButtonLeftPressed = false;
		}
	}

	if(_event.type == SDL_MOUSEBUTTONDOWN)
	{
		if(_event.button.button == SDL_BUTTON_RIGHT)
		{
			mouseButtonRightPressed = true;
			
		}
	}
	if(_event.type == SDL_MOUSEBUTTONUP)
	{
		if(_event.button.button == SDL_BUTTON_RIGHT)
		{
			mouseButtonRightPressed = false;
		}
	}
}

}

int main( int argc, char **argv )
{
InitSDLWithOpenGLcontext();

InitOpenGL();

while (!done)
{  
	//update data
	if(keyboardLeftPressed) deltaY -= 1.0f;
	if(keyboardRightPressed) deltaY +=1.0f;
	if(keyboardUpPressed)	deltaX -=1.0f;
	if(keyboardDownPressed)	deltaX +=1.0f;
	if(keyboardWPressed && mode%2==1) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	else if(keyboardWPressed && mode%2==0) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	if(keyboardCPressed && modeC%2==1)glDisable(GL_COLOR_MATERIAL);
	else if(keyboardCPressed && modeC%2==0)glEnable(GL_COLOR_MATERIAL);
	if(mouseButtonRightPressed) ownRot +=1.0f;
	if(mouseButtonLeftPressed) buttonLeftRot++;
	if(keyboardQPressed) cameraZoom--;
	if(keyboardAPressed) cameraZoom++;
	if(keyboardRPressed) lightRot++;
	//clear buffers
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		

	//place the camera
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	
			
	//position the camera
	//gluLookAt(1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
	glTranslatef(0.0f, 0.0f, cameraZoom); 

	glRotatef(deltaX ,1.0f,0.0f, 0.0f);
	glRotatef(deltaY ,0.0f,1.0f, 0.0f);

	

	float lightPosition[] = {2.0, 2.0, 0.0, 1.0}; 
	glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
	//in the rendering loop
	glPushMatrix();
	//glRotatef(lightRot,1.0f,1.0f, 1.0f);
	glTranslatef(lightPosition[0], lightPosition[1], lightPosition[2]);		
	glScalef(0.1f, 0.1f, 0.1f);
	//glDisable(GL_LIGHT0);
	glCallList(myListId);
	//glEnable(GL_LIGHT0);
	glPopMatrix();

	

	
	

	
	//begin

	//render some geometry
	//AXIS
	glLineWidth(2.0);
	glBegin(GL_LINES);
	glColor3f(1.0, 0.0, 0.0); glVertex3f(0.0, 0.0, 0.0); glVertex3f(2.0, 0.0, 0.0);
	glColor3f(0.0, 1.0, 0.0); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 2.0, 0.0);
	glColor3f(0.0, 0.0, 1.0); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 0.0, 2.0);
	glEnd();

	glRotatef(buttonLeftRot,1.0f,1.0f,1.0f);

	//NORMALE
	if(keyboardSPressed){
	glBegin(GL_LINES);
	glColor3f(1.0, 1.0, 1.0); glVertex3f(0.5, 0.5, 0.0); glVertex3f(0.5, 0.5, -1.0);
	glColor3f(1.0, 1.0, 1.0); glVertex3f(0.0, 0.5, 0.5); glVertex3f(-1.0, 0.5, 0.5);
	glColor3f(1.0, 1.0, 1.0); glVertex3f(0.5, 0.0, 0.5); glVertex3f(0.5, -1.0, 0.5);
	glColor3f(1.0, 1.0, 1.0); glVertex3f(1.0, 0.5, 0.5); glVertex3f(2.0, 0.5, 0.5);
	glColor3f(1.0, 1.0, 1.0); glVertex3f(0.5, 1.0, 0.5); glVertex3f(0.5, 2.0, 0.5);
	glColor3f(1.0, 1.0, 1.0); glVertex3f(0.5, 0.5, 1.0); glVertex3f(0.5, 0.5, 2.0);
	glEnd();
	}
	glCallList(myListId);


	//end

	CheckEvents();

	SDL_GL_SwapBuffers();

	Sleep(20); //slow down the application

}

//clean OpenGL (if needed)

//Clean OpenGL
glDeleteLists(myListId, 1);

//free SDL

SDL_Quit();

return 0;
}[/codebox]

Merci pour tout.
B)

Ha oui, pas faux… j’y avais pas pense aux normals…