Accueil > > > SYSTÈME SOLAIRE OPEN GL AVEC BIBLIOTHÈQUE GLUT : 5 PLANETES / LUMIÈRES / ESPACE
SYSTÈME SOLAIRE OPEN GL AVEC BIBLIOTHÈQUE GLUT : 5 PLANETES / LUMIÈRES / ESPACE
Information sur la source
Description
Voici un petit système solaire que j'ai fait en TP à l'école. C'est une représentation partielle du système solaire (le Soleil, Mercure, Vénus, la Terre et la Lune. Toutes ces planètes sont sur le même plan et gravitent autour du soleil, la Lune gravitant elle autour de la terre. J'espère qu'il vous servira. Touches : q : Quitter + : se rapprocher - : s�éloigner l : activer/désactiver les lumières
Source
- //***************************************************************************************
-
- // G@BuLe - 2008
-
- //***************************************************************************************
-
-
-
-
-
- #include <stdio.h>
-
- #include <stdlib.h>
-
-
-
- #include"glut.h"
-
- #include<GL/glu.h>
-
-
-
- bool light =true;
-
- GLubyte* data;
-
- int eyex=0,eyey=25,eyez=12;
-
- int width=800,height=800;
-
-
-
- // Initialisation des angles
-
- float angle0=0.0;
-
- float angle1=0.0;
-
- float angle2=0.0;
-
- float angle3=0.0;
-
- float angle4=0.0;
-
- float angle5=0.0;
-
- float angle6=0.0;
-
- float angle7=0.0;
-
- float angle8=0.0;
-
-
-
-
-
- GLUquadricObj *obj = gluNewQuadric();
-
- GLUquadricObj *obj_reverse = gluNewQuadric();
-
-
-
- //Texture :
-
- GLuint Nom[6];
-
-
-
- //LoadBMP : charge une image 24bpp
-
- #define EXIT {fclose(fichier);return -1;}
-
- #define CTOI(C) (*(int*)&C) //récupère en int un nombre pointé par un char*
-
-
-
- void inc_angles(){
-
- (angle0 == 360.0)? angle0=0.0 : angle0 +=3.0/15;
-
- (angle1 == 360.0)? angle1=0.0 : angle1 +=3.0;
-
- (angle2 == 0.0)? angle2=360.0 : angle2 -=3.0;
-
- (angle3 == 360.0)? angle3=0.0 : angle3 +=3;
-
- (angle4 == 360.0)? angle4=0.0 : angle4 +=1.0;
-
- (angle5 == 360.0)? angle5=0.0 : angle5 +=(0.088*4);
-
- (angle6 == 360.0)? angle6=0.0 : angle6 +=(0.224*4);
-
- (angle7 == 360.0)? angle7=0.0 : angle7 +=(3.0/365.0*40.0);
-
- (angle8 == 360.0)? angle8=0.0 : angle8 +=2.0;
-
- }
-
-
-
-
-
- int LoadBMP(char *File)
-
- {
-
- unsigned char *Data;
-
- FILE *fichier;
-
- unsigned char Header[0x36];
-
- GLuint DataPos,DataSize;
-
- GLint Components;
-
- GLsizei Width,Height;
-
- GLenum Format,Type;
-
- GLuint Name[1];
-
-
-
- //Lit le fichier et son header
-
- fichier = fopen(File,"rb");if (!fichier) return -1;
-
- if (fread(Header,1,0x36,fichier)!=0x36) EXIT;
-
- if (Header[0]!='B' || Header[1]!='M') EXIT;
-
- if (CTOI(Header[0x1E])!=0) EXIT;
-
- if (CTOI(Header[0x1C])!=24) EXIT;
-
-
-
- //Récupère les infos du fichier
-
- DataPos = CTOI(Header[0x0A]);
-
- DataSize = CTOI(Header[0x22]);
-
- //Récupère les infos de l'image
-
- Width = CTOI(Header[0x12]);
-
- Height = CTOI(Header[0x16]);
-
- Type = GL_UNSIGNED_BYTE;
-
- Format = GL_RGB;
-
- Components = 3;
-
-
-
- //!!!!
-
- if (DataSize==0) DataSize=Width*Height*Components;
-
- if (DataPos==0) DataPos=0x36;
-
-
-
- //Charge l'image
-
- fseek(fichier,DataPos,0);
-
- Data = new unsigned char[DataSize];
-
- if (!Data) EXIT;
-
-
-
- if (fread(Data,1,DataSize,fichier)!=DataSize)
-
- {
-
- delete Data;
-
- fclose(fichier);
-
- return -1;
-
- }
-
-
-
- fclose(fichier);
-
-
-
- //Inverse R et B
-
- unsigned char t;
-
- for (int x=0;x<Width*Height;x++)
-
- {
-
- t=Data[x*3];
-
- Data[x*3]=Data[x*3+2];
-
- Data[x*3+2]=t;
-
- }
-
-
-
- //Envoie la texture à OpenGL
-
- // glPixelStorei(GL_UNPACK_ALIGNMENT,1);
-
- glGenTextures(1, Name);
-
- glBindTexture(GL_TEXTURE_2D, Name[0]);
-
-
-
-
-
- glTexImage2D
-
- (
-
- GL_TEXTURE_2D, //target
-
- 0, //mipmap level
-
- Components, //nb couleurs
-
- Width, //largeur
-
- Height, //hauteur
-
- 0, //largeur du bord
-
- GL_RGB, //type des couleurs
-
- GL_UNSIGNED_BYTE, //codage de chaque composante
-
- Data //Image
-
- );
-
-
-
- return Name[0];
-
- }
-
-
-
-
-
- void init(void)
-
- {
-
- // initialise la buffer ou va etre rendu la scene
-
- glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH );
-
- // initialisation de la fenetre (taille 500x500)
-
- glutInitWindowSize (800, 800);
-
- // on positionne la fenetre sur l'ecran
-
- glutInitWindowPosition (100, 100);
-
- // on cree la fenetre
-
- glutCreateWindow ("Système Planetaire .:: G@BuLe ::. || q : Quitter || + : s'approcher || - : s'éloigner || l : lumières On/OFF");
-
- // couleur de remplissage lors de l'effacement du buffer
-
- glClearColor (0.0, 0.0, 0.0, 0.0);
-
- // model d'eclairage
-
-
-
- // Crée une source de lumière
-
- GLfloat position1 [] = { 0, 0.0F, 0.0F, 1.0F };
-
- glLightfv(GL_LIGHT0, GL_POSITION, position1);
-
- glEnable(GL_LIGHTING);
-
- glEnable(GL_LIGHT0);
-
- glShadeModel (GL_SMOOTH);
-
-
-
- // Z Buffer pour la suppression des parties cachées
-
- glEnable(GL_DEPTH_TEST);
-
-
-
- glEnable(GL_COLOR_MATERIAL);
-
-
-
- glEnable(GL_TEXTURE_2D);
-
- glMatrixMode (GL_MODELVIEW);
-
- glLoadIdentity ();
-
-
-
-
-
- Nom[0] = LoadBMP("sun.bmp");
-
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
-
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
-
-
-
-
-
- Nom[1] = LoadBMP("mercure.bmp");
-
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
-
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
-
-
-
- Nom[2] = LoadBMP("venus.bmp");
-
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
-
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
-
-
-
- Nom[3] = LoadBMP("earth.bmp");
-
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
-
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
-
-
-
- Nom[4] = LoadBMP("moon.bmp");
-
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
-
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
-
-
-
-
-
- Nom[5] = LoadBMP("space.bmp");
-
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
-
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
-
-
-
- glDepthFunc(GL_LESS);
-
- glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
-
- glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- }
-
-
-
-
-
- void display(void)
-
- {
-
-
-
-
-
- //materiaux
-
- GLfloat ambiant [4] = { 0.2, 0.2, 0.2, 1.0 };
-
- GLfloat diffuse [4] = { 0.6, 0.6, 0.6, 1.0 };
-
- GLfloat specular [4] = { 1.0, 1.0, 1.0, 1.0 };
-
- GLfloat emission [4] = { 0.5, 0.5, 0., 0.0 };
-
- GLfloat no_material [4] = {0.0,0.0,0.0,0.0};
-
- GLfloat shininess []= {50.0};
-
-
-
-
-
-
-
- inc_angles();
-
-
-
- // Affiche l'espace
-
- glLoadIdentity();
-
- gluLookAt(eyex,eyey,eyez,0,0,0,0.0,0.0,1.0);
-
- glClear (GL_COLOR_BUFFER_BIT);
-
- glClear (GL_DEPTH_BUFFER_BIT);
-
- glBindTexture(GL_TEXTURE_2D, Nom[5]);
-
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
-
-
-
- glTranslatef(-0.5,-0.5,0);
-
- glBegin(GL_QUADS);
-
- glTexCoord2f(0.0, 0.0); glVertex3f(100.0, -10.0, -10.0);
-
- glTexCoord2f(0.0, 1.0); glVertex3f(100.0, -10.0, 10.0);
-
- glTexCoord2f(1.0, 1.0); glVertex3f(-100.0, -10.0, 10.0);
-
- glTexCoord2f(1.0, 0.0); glVertex3f(-10.0, -10.0, -30.0);
-
- glEnd();
-
-
-
- // Definit les propriétés matérielles de la couleur spéculaire et du
-
- // degré de brillance.
-
- if (light){
-
- glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambiant);
-
- glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
-
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
-
- glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
-
- glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, emission);
-
- }
-
-
-
- // le soleil
-
- glPushMatrix();
-
- glBindTexture(GL_TEXTURE_2D, Nom[0]);
-
- gluQuadricTexture(obj, GL_TRUE );
-
- gluQuadricDrawStyle(obj, GLU_FILL);
-
- glTranslatef(0,0.0,0.0);
-
- glRotatef(angle0,0.0,0.0,1.0);
-
- gluSphere(obj,3.0,100.0,100.0);
-
- glPopMatrix();
-
-
-
- glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambiant);
-
- glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
-
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
-
- glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
-
- glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, no_material);
-
-
-
- // mercure
-
- glPushMatrix();
-
- glBindTexture(GL_TEXTURE_2D, Nom[1]);
-
- gluQuadricTexture(obj, GL_TRUE );
-
- gluQuadricDrawStyle(obj, GLU_FILL);
-
- glRotatef(10,1,0,0);
-
- glRotatef(angle5,0.0,0.0,1.0);
-
- glTranslatef(5.0,0.0,0.0);
-
- glRotatef(angle1,0.0,0.0,1.0);
-
- gluSphere(obj,0.55,100.0,100.0);
-
- glPopMatrix();
-
-
-
- // venus
-
- glPushMatrix();
-
- glBindTexture(GL_TEXTURE_2D, Nom[2]);
-
- gluQuadricTexture(obj, GL_TRUE );
-
- gluQuadricDrawStyle(obj, GLU_FILL);
-
-
-
- //glColor3f (1.0, 0.0, 0.0);
-
- glRotatef(340,1,0,0);
-
- glRotatef(angle6,0.0,0.0,1.0);
-
- glTranslatef(7.0,0.0,0.0);
-
- glRotatef(angle2,0.0,0.0,1.0);
-
- gluSphere(obj,0.815,100.0,100.0);
-
- glPopMatrix();
-
-
-
- // terre
-
- glPushMatrix();
-
- glBindTexture(GL_TEXTURE_2D, Nom[3]);
-
- gluQuadricTexture(obj, GL_TRUE );
-
- gluQuadricDrawStyle(obj, GLU_FILL);
-
- glRotatef(angle7,0.0,0.0,1.0);
-
- glRotatef(30,1,0,0);
-
- glTranslatef(9.5,0.0,0.0);
-
- glRotatef(360-angle7,0.0,0.0,1.0);
-
- glRotatef(angle3,0.0,0.0,1.0);
-
- glRotatef(23.0,0.0,0.0,1.0);
-
- gluSphere(obj,1.0,100.0,100.0);
-
-
-
- // lune
-
- glPushMatrix();
-
- glBindTexture(GL_TEXTURE_2D, Nom[4]);
-
- gluQuadricTexture(obj, GL_TRUE );
-
- gluQuadricDrawStyle(obj, GLU_FILL);
-
- glColor3f (1.0,1.0,1.0);
-
- glRotatef(30,1,0,0);
-
- glRotatef(angle8,0.0,0.0,1.0);
-
- glTranslatef(1.3,0.0,0.0);
-
- glRotatef(angle4,0.0,0.0,1.0);
-
- gluSphere(obj,0.05,100.0,100.0);
-
- glPopMatrix();
-
- glPopMatrix();
-
-
-
- glutSwapBuffers();
-
- glutPostRedisplay();
-
- }
-
-
-
-
-
- void reshape (int width,int height){
-
- glViewport(0, 0, width, height);
-
- glMatrixMode(GL_PROJECTION);
-
- glLoadIdentity();
-
- gluPerspective(45.0,width/height,1.0,3000.0);
-
- glMatrixMode(GL_MODELVIEW);
-
- }
-
-
-
- // fonction de gestion du clavier
-
- void keyboard(unsigned char key, int x, int y)
-
- {
-
- switch (key) {
-
- case 'l':
-
- if (light){
-
- light=false;
-
- glDisable(GL_LIGHT0);
-
- }else{
-
- light=true;
-
- glEnable(GL_LIGHT0);
-
- }
-
- break;
-
- case 'q':exit(0); break;
-
- case '-' : eyex +=5.0 ;break;
-
- case '+' : eyex -=5.0 ;break;
-
- default:printf ("La touche %d n�est pas active.\n", key); break;
-
- }
-
- glMatrixMode(GL_MODELVIEW);
-
- glutPostRedisplay();
-
- }
-
-
-
- int main(int argc, char** argv)
-
- {
-
- glutInit(&argc, argv);
-
-
-
- // on initialise la scene
-
- init ();
-
-
-
- // definition des fonctions "callback"
-
- // les 3 fonctions qui suivent permettent d'indiquer les fonctions a utilisé :
-
- // lors de l'affichage
-
- glutDisplayFunc(display);
-
- // lors du redimensionnement de la fentre
-
- glutReshapeFunc(reshape);
-
- // lors d'un appui sur un touche du clavier
-
- glutKeyboardFunc(keyboard);
-
-
-
- // la librairie glut gere elle meme la boucle d'evenement
-
- glutMainLoop();
-
-
-
- return 0;
-
- }
//***************************************************************************************
// G@BuLe - 2008
//***************************************************************************************
#include <stdio.h>
#include <stdlib.h>
#include"glut.h"
#include<GL/glu.h>
bool light =true;
GLubyte* data;
int eyex=0,eyey=25,eyez=12;
int width=800,height=800;
// Initialisation des angles
float angle0=0.0;
float angle1=0.0;
float angle2=0.0;
float angle3=0.0;
float angle4=0.0;
float angle5=0.0;
float angle6=0.0;
float angle7=0.0;
float angle8=0.0;
GLUquadricObj *obj = gluNewQuadric();
GLUquadricObj *obj_reverse = gluNewQuadric();
//Texture :
GLuint Nom[6];
//LoadBMP : charge une image 24bpp
#define EXIT {fclose(fichier);return -1;}
#define CTOI(C) (*(int*)&C) //récupère en int un nombre pointé par un char*
void inc_angles(){
(angle0 == 360.0)? angle0=0.0 : angle0 +=3.0/15;
(angle1 == 360.0)? angle1=0.0 : angle1 +=3.0;
(angle2 == 0.0)? angle2=360.0 : angle2 -=3.0;
(angle3 == 360.0)? angle3=0.0 : angle3 +=3;
(angle4 == 360.0)? angle4=0.0 : angle4 +=1.0;
(angle5 == 360.0)? angle5=0.0 : angle5 +=(0.088*4);
(angle6 == 360.0)? angle6=0.0 : angle6 +=(0.224*4);
(angle7 == 360.0)? angle7=0.0 : angle7 +=(3.0/365.0*40.0);
(angle8 == 360.0)? angle8=0.0 : angle8 +=2.0;
}
int LoadBMP(char *File)
{
unsigned char *Data;
FILE *fichier;
unsigned char Header[0x36];
GLuint DataPos,DataSize;
GLint Components;
GLsizei Width,Height;
GLenum Format,Type;
GLuint Name[1];
//Lit le fichier et son header
fichier = fopen(File,"rb");if (!fichier) return -1;
if (fread(Header,1,0x36,fichier)!=0x36) EXIT;
if (Header[0]!='B' || Header[1]!='M') EXIT;
if (CTOI(Header[0x1E])!=0) EXIT;
if (CTOI(Header[0x1C])!=24) EXIT;
//Récupère les infos du fichier
DataPos = CTOI(Header[0x0A]);
DataSize = CTOI(Header[0x22]);
//Récupère les infos de l'image
Width = CTOI(Header[0x12]);
Height = CTOI(Header[0x16]);
Type = GL_UNSIGNED_BYTE;
Format = GL_RGB;
Components = 3;
//!!!!
if (DataSize==0) DataSize=Width*Height*Components;
if (DataPos==0) DataPos=0x36;
//Charge l'image
fseek(fichier,DataPos,0);
Data = new unsigned char[DataSize];
if (!Data) EXIT;
if (fread(Data,1,DataSize,fichier)!=DataSize)
{
delete Data;
fclose(fichier);
return -1;
}
fclose(fichier);
//Inverse R et B
unsigned char t;
for (int x=0;x<Width*Height;x++)
{
t=Data[x*3];
Data[x*3]=Data[x*3+2];
Data[x*3+2]=t;
}
//Envoie la texture à OpenGL
// glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glGenTextures(1, Name);
glBindTexture(GL_TEXTURE_2D, Name[0]);
glTexImage2D
(
GL_TEXTURE_2D, //target
0, //mipmap level
Components, //nb couleurs
Width, //largeur
Height, //hauteur
0, //largeur du bord
GL_RGB, //type des couleurs
GL_UNSIGNED_BYTE, //codage de chaque composante
Data //Image
);
return Name[0];
}
void init(void)
{
// initialise la buffer ou va etre rendu la scene
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH );
// initialisation de la fenetre (taille 500x500)
glutInitWindowSize (800, 800);
// on positionne la fenetre sur l'ecran
glutInitWindowPosition (100, 100);
// on cree la fenetre
glutCreateWindow ("Système Planetaire .:: G@BuLe ::. || q : Quitter || + : s'approcher || - : s'éloigner || l : lumières On/OFF");
// couleur de remplissage lors de l'effacement du buffer
glClearColor (0.0, 0.0, 0.0, 0.0);
// model d'eclairage
// Crée une source de lumière
GLfloat position1 [] = { 0, 0.0F, 0.0F, 1.0F };
glLightfv(GL_LIGHT0, GL_POSITION, position1);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glShadeModel (GL_SMOOTH);
// Z Buffer pour la suppression des parties cachées
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_TEXTURE_2D);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
Nom[0] = LoadBMP("sun.bmp");
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
Nom[1] = LoadBMP("mercure.bmp");
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
Nom[2] = LoadBMP("venus.bmp");
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
Nom[3] = LoadBMP("earth.bmp");
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
Nom[4] = LoadBMP("moon.bmp");
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
Nom[5] = LoadBMP("space.bmp");
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glDepthFunc(GL_LESS);
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void display(void)
{
//materiaux
GLfloat ambiant [4] = { 0.2, 0.2, 0.2, 1.0 };
GLfloat diffuse [4] = { 0.6, 0.6, 0.6, 1.0 };
GLfloat specular [4] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat emission [4] = { 0.5, 0.5, 0., 0.0 };
GLfloat no_material [4] = {0.0,0.0,0.0,0.0};
GLfloat shininess []= {50.0};
inc_angles();
// Affiche l'espace
glLoadIdentity();
gluLookAt(eyex,eyey,eyez,0,0,0,0.0,0.0,1.0);
glClear (GL_COLOR_BUFFER_BIT);
glClear (GL_DEPTH_BUFFER_BIT);
glBindTexture(GL_TEXTURE_2D, Nom[5]);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTranslatef(-0.5,-0.5,0);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex3f(100.0, -10.0, -10.0);
glTexCoord2f(0.0, 1.0); glVertex3f(100.0, -10.0, 10.0);
glTexCoord2f(1.0, 1.0); glVertex3f(-100.0, -10.0, 10.0);
glTexCoord2f(1.0, 0.0); glVertex3f(-10.0, -10.0, -30.0);
glEnd();
// Definit les propriétés matérielles de la couleur spéculaire et du
// degré de brillance.
if (light){
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambiant);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, emission);
}
// le soleil
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, Nom[0]);
gluQuadricTexture(obj, GL_TRUE );
gluQuadricDrawStyle(obj, GLU_FILL);
glTranslatef(0,0.0,0.0);
glRotatef(angle0,0.0,0.0,1.0);
gluSphere(obj,3.0,100.0,100.0);
glPopMatrix();
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambiant);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, no_material);
// mercure
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, Nom[1]);
gluQuadricTexture(obj, GL_TRUE );
gluQuadricDrawStyle(obj, GLU_FILL);
glRotatef(10,1,0,0);
glRotatef(angle5,0.0,0.0,1.0);
glTranslatef(5.0,0.0,0.0);
glRotatef(angle1,0.0,0.0,1.0);
gluSphere(obj,0.55,100.0,100.0);
glPopMatrix();
// venus
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, Nom[2]);
gluQuadricTexture(obj, GL_TRUE );
gluQuadricDrawStyle(obj, GLU_FILL);
//glColor3f (1.0, 0.0, 0.0);
glRotatef(340,1,0,0);
glRotatef(angle6,0.0,0.0,1.0);
glTranslatef(7.0,0.0,0.0);
glRotatef(angle2,0.0,0.0,1.0);
gluSphere(obj,0.815,100.0,100.0);
glPopMatrix();
// terre
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, Nom[3]);
gluQuadricTexture(obj, GL_TRUE );
gluQuadricDrawStyle(obj, GLU_FILL);
glRotatef(angle7,0.0,0.0,1.0);
glRotatef(30,1,0,0);
glTranslatef(9.5,0.0,0.0);
glRotatef(360-angle7,0.0,0.0,1.0);
glRotatef(angle3,0.0,0.0,1.0);
glRotatef(23.0,0.0,0.0,1.0);
gluSphere(obj,1.0,100.0,100.0);
// lune
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, Nom[4]);
gluQuadricTexture(obj, GL_TRUE );
gluQuadricDrawStyle(obj, GLU_FILL);
glColor3f (1.0,1.0,1.0);
glRotatef(30,1,0,0);
glRotatef(angle8,0.0,0.0,1.0);
glTranslatef(1.3,0.0,0.0);
glRotatef(angle4,0.0,0.0,1.0);
gluSphere(obj,0.05,100.0,100.0);
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
glutPostRedisplay();
}
void reshape (int width,int height){
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0,width/height,1.0,3000.0);
glMatrixMode(GL_MODELVIEW);
}
// fonction de gestion du clavier
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 'l':
if (light){
light=false;
glDisable(GL_LIGHT0);
}else{
light=true;
glEnable(GL_LIGHT0);
}
break;
case 'q':exit(0); break;
case '-' : eyex +=5.0 ;break;
case '+' : eyex -=5.0 ;break;
default:printf ("La touche %d n�est pas active.\n", key); break;
}
glMatrixMode(GL_MODELVIEW);
glutPostRedisplay();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
// on initialise la scene
init ();
// definition des fonctions "callback"
// les 3 fonctions qui suivent permettent d'indiquer les fonctions a utilisé :
// lors de l'affichage
glutDisplayFunc(display);
// lors du redimensionnement de la fentre
glutReshapeFunc(reshape);
// lors d'un appui sur un touche du clavier
glutKeyboardFunc(keyboard);
// la librairie glut gere elle meme la boucle d'evenement
glutMainLoop();
return 0;
}
Historique
- 24 avril 2008 22:42:46 :
- Retification erreur : l lune tourne bien evidement autour du soleil ...
- 21 avril 2009 11:23:08 :
- Nouvelle version avec prise en compte de la souris
- 16 décembre 2009 20:43:13 :
- Update
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
glut - openGL [ par loss ]
Quels sont les fichiers necessaires pour utiliser glut(je compile avec VC++)?Ou est ce que je peux les telecharger?Merci d avance.
Gestion de la souris OpenGL SANS GLUT [ par Xentor ]
Comment faire pour connaitre le déplacement de la souris sans utiliser Glut ? (Savoir si on la déplace en haut, à gauche, etc...) J'ai fait plusieurs
OpenGl, glut et Dev c++ 4 [ par fabienGL ]
J'envoie un message car je passait au moin 3 heures sur le forums j'ai essayé tout ce ki à était di mé rien à faire ... j'utilise DEV C++ 4 et je sui
OpenGl & glut avec Dev c++ 4 et WinXP [ par fabienGL ]
J'envoie un message car je passait au moin 3 heures sur le forums j'ai essayé tout ce ki à était di mé rien à faire ... j'utilise DEV C++ 4 et j'ai Wi
glut et opengl [ par MiTcH37 ]
voila ce que j'ai lorsque je compile un prog avec du glut.h...C:\DOCUME~2\Mitch1\LOCALS~1\Temp\cc6Pbaaa.o(.text+0xcc):souris2.cpp: undefined reference
opengl [ par MiTcH37 ]
J'aimerais bien faire de l'opengl, mais ça marche pas... voila ce que j'ai lorsque je compile un prog avec du glut.h...C:\DOCUME~2\Mitch1\LOCALS~1\Tem
devc++ [ par MiTcH37 ]
qqun se sert de devc++ ?J'aimerais bien faire de l'opengl, mais ça marche pas... > > > > voila ce que j'ai lorsque je compile un prog avec
erreur de compile d une source opengl utilisant glut [ par kribler ]
KR!Bl3Rg lerreur suivante qui s afffiche :LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16quelqun pourrai maidermerci d
Pb Dev C++ 5 et OpenGl [ par guillaume21 ]
J'ai installé glut avec Dev c++ 5. J'ai mis glut.h dans include, glut32.lib dans lib et le dll dans system32 (et mem ds lib lol).J'ai aussi ajouté les
Mélanger OpenGL et Glut [ par tintin72 ]
SalutJ'aimerai me servir des fonctions d'entrée clavier/souris proposées par Glut, mais j'ai vu que Glut s'initialise avec une fonction main façon C.i
|
Derniers Blogs
IMAGINE CUP 2012, MAKE A SIGN EN FINALEIMAGINE CUP 2012, MAKE A SIGN EN FINALE par junarnoalg
Voilà qui est fait, la nouvelle est officielle ! L'équipe belge "Make a Sign" va au pays des kangourous défendre son projet dans la catégorie Software Design. http://www.imaginecup.com/CompetitionsContent/Competition/WorldwideFinalists.aspx V...
Cliquez pour lire la suite de l'article par junarnoalg KINECT 1.5 IS OUT !KINECT 1.5 IS OUT ! par Vko
La version 1.5 du Kinect For Microsoft vient tout juste de sortir ! Plein de nouveautés: Tracking de squelette en Near Mode Détection en position assise Détection faciale avec un SDK dédié Documentation et des guideline (enfin) Un out...
Cliquez pour lire la suite de l'article par Vko LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) par richardc
Mise à jour des Web API du 14 Mai
Réservez dès maintenant votre journée du 20 juin pour le Windows Azure Dev Camp 2012 à Paris
Mise à jour de Team Foundation Service
MechCommander 2 sur Windows 8
Entity Framework 5 Release Candidate e...
Cliquez pour lire la suite de l'article par richardc REACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITERREACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITER par Groc
Une mauvaise utilisation de rx lors de l'écriture d'une couche d'accès à des services peut conduire à des cas embarassants avec des erreurs mal gérées, des appels qui ne partent lorsqu'ils le devraient, et même des résultats incorrects . le tout nuis...
Cliquez pour lire la suite de l'article par Groc SHAREPOINT BLOG SITE, PROBLèME D'ARCHIVESSHAREPOINT BLOG SITE, PROBLèME D'ARCHIVES par junarnoalg
Dernièrement, nous avons migré le site
myTIC
vers un nouveau serveur SharePoint 2010. Dans les contenus que nous vouloins récupérer, nous avions un certain nombre de blogs.
Nous avons utilisé les commandes Power...
Cliquez pour lire la suite de l'article par junarnoalg
Forum
RE : SAC A DOS RE : SAC A DOS par hadjkaddour
Cliquez pour lire la suite par hadjkaddour
Logiciels
sDEVIS-FACTURES vlPRO (8.1.0.3)SDEVIS-FACTURES VLPRO (8.1.0.3)sDEVIS-FACTURES vlPRO a été mis au point pour les particuliers, créateurs, entrepreneurs, artisa... Cliquez pour télécharger sDEVIS-FACTURES vlPRO 974 Application Server (12.2.4.6)974 APPLICATION SERVER (12.2.4.6)Développez de puissantes applications dans un environnement de 'cloud computing', clusterisé, séc... Cliquez pour télécharger 974 Application Server vPicture (1.4.2.1)VPICTURE (1.4.2.1)Avec vPicture, hébergez vos images facilement et rapidement.
vPicture est un utilitaire simple, ... Cliquez pour télécharger vPicture Easy-Planning (2.2.1.6)EASY-PLANNING (2.2.1.6)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté au... Cliquez pour télécharger Easy-Planning COM-BACKUP (2.0)COM-BACKUP (2.0)
COM-BACKUP est un logiciel de sauvegarde qui permet de planifier les sauvegardes de vos dossiers ...
Cliquez pour télécharger COM-BACKUP
|