begin process at 2012 05 27 20:04:57
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

OpenGL

 > INTRODUCTION À OPENGL

INTRODUCTION À OPENGL


 Information sur la source

Note :
4,5 / 10 - par 2 personnes
4,50 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :OpenGL Niveau :Débutant Date de création :13/04/2005 Vu :3 884

Auteur : BobRobert

Ecrire un message privé
Commentaire sur cette source (5)
Ajouter un commentaire et/ou une note

 Description

petit programme très simple implementant quelque fonctions de opengl, pour débuter ds le domaine de la 3D.

Source

  • //main.c
  • /*****************************************************************
  • / BoBRobert
  • /*****************************************************************
  • /*Une petite "démo" pour commencer
  • Bon ttes les fct ne st pas utils mais le but est de faire un moteur d'affichage réutilisable*/
  • //#include <windows.h>
  • #include <stdio.h>
  • #include <stdlib.h>
  • #include <GL/glut.h>
  • #include <math.h>
  • #include <time.h>
  • //Mes objets perso
  • #include "formes.h"
  • //#include "readconf.h"
  • void affichage();
  • void clavier(unsigned char touche, int x, int y);
  • void reshape(int, int);
  • void mouse(int,int,int,int);
  • void mousemotion(int,int);
  • char presseL, presseD;/*varible globale pour l'état de la sourie*/
  • int px,py,pz;
  • /*Structure permettant la définition d'un point (ca peut kan meme servir lol)*/
  • typedef struct{
  • float x;
  • float y;
  • float z;
  • float r;
  • float g;
  • float b;
  • }point;
  • /*fonction d'initialisation de la fenêtre de rendu*/
  • /*paramètres en entrée :
  • - Position de la fenêtre x,y
  • - taille de la fenêtre x,y
  • - nom de la fenêtre (string) max 19 caractères
  • */
  • void Glut_Window(int xPos,int yPos,int xTaille,int yTaille,char WinName[20]){
  • glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  • glutInitWindowPosition(xPos,yPos);/*position de la fenetre*/
  • glutInitWindowSize(xTaille,yTaille);/*taille de la fenetre*/
  • glutCreateWindow(WinName);/*création de la fenetre*/
  • }
  • /*fonction de gestion du redimentionnement de la fenetre de rendu(pas super o point)*/
  • void reshape(int xWin,int yWin){
  • if(xWin<yWin)
  • glViewport(0,(yWin-xWin)/2,xWin,xWin);
  • else
  • glViewport((xWin-yWin)/2,0,yWin,yWin);
  • }
  • /*Paramètres d'initialisation de la belle scène*/
  • void Glut_Init_Screen(){
  • glClearColor(0.0,1.0,1.0,0.0);//efface tt
  • glColor3f(1.0,1.0,1.0);//initialise la couleure de font
  • glPointSize(2.0);//taille des points
  • glEnable(GL_DEPTH_TEST);
  • }
  • /*gère les entrées sortie*/
  • void Glut_IO(){
  • glutDisplayFunc(affichage);//No Comment lol
  • glutKeyboardFunc(clavier);
  • glutReshapeFunc(reshape);
  • glutMouseFunc(mouse);
  • glutMotionFunc(mousemotion);
  • }
  • /*gestion des évennement clavier*/
  • void clavier(unsigned char touche,int x,int y)
  • {
  • switch (touche){
  • case 'p': /*carre plein */
  • glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
  • glutPostRedisplay();
  • break;
  • case 'f': /*fil de fer */
  • glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
  • glutPostRedisplay();
  • break;
  • case 's': /* sommets*/
  • glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);
  • glutPostRedisplay();
  • break;
  • /*case 'z':
  • px++;
  • glutPostRedisplay();
  • break;
  • case 'd':
  • px--;
  • glutPostRedisplay();
  • break;*/
  • case 'q' : /*quitte */
  • exit(0);
  • }
  • }
  • /*fonction déterminant l'état des boutons de la sourie*/
  • void mouse(int button, int stat, int x, int y){
  • //pour le bouton gauche
  • //détermine si le bouton gauche est pressé
  • if(button == GLUT_LEFT_BUTTON &stat == GLUT_DOWN){
  • presseL=1;//état du bouton
  • xold=x;
  • yold=y;
  • }
  • //si relaché
  • if(button ==GLUT_LEFT_BUTTON &stat == GLUT_UP)
  • presseL=0;
  • //pour le bouton droit
  • }
  • void mousemotion(int x, int y){
  • if(presseL==1){
  • anglex=anglex+(x-xold);
  • angley=angley+(y-yold);
  • glutPostRedisplay();
  • }
  • xold=x;
  • yold=y;
  • }
  • /*fct d'affichage de la scène*/
  • void affichage()
  • {
  • glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  • //Coeur3D();
  • //glTranslatef(-px,0.0,-pz);
  • cube();
  • //Disque(1,1,1,1);
  • //glutWireSphere(1,20,20);
  • glFlush();
  • glutSwapBuffers();
  • }
  • //Le Bo main
  • int main(int argc, char **argv){
  • printf("Welcome in THE opengl World\n");
  • //read_conf();
  • glutInit(&argc,argv);/*initialise GLUT*/
  • Glut_Window(200,200,500,500,"OpenGL Power!!!!!!");/*initialisation de la fenetre*/
  • Glut_Init_Screen();/*paramètres de la scène*/
  • Glut_IO();/*entrées sorties*/
  • glutMainLoop();
  • return 0;
  • }
  • //formes.h a mettre ds un autre ficher
  • /*lib de ttes les formes (lol)*/
  • int anglex, angley, x, y, xold, yold;//variables globales de gestion de la position de la sourie
  • /*définition d'objets divers et variée*/
  • void rotation(){
  • glLoadIdentity();
  • glRotatef(-angley,1.1,0.0,0.0);
  • glRotatef(-anglex,0.0,1.0,0.0);
  • }
  • //carré 2D
  • void Carre2D(){
  • //carré
  • glBegin(GL_POLYGON);
  • glColor3f(1.0,0.0,0.0);
  • glVertex2f(-0.5,-0.5);
  • glColor3f(0.0,1.0,0.0);
  • glVertex2f(0.5,-0.5);
  • glColor3f(0.0,0.0,1.0);
  • glVertex2f(0.5,0.5);
  • glColor3f(1.0,1.0,1.0);
  • glVertex2f(-0.5,0.5);
  • glEnd();
  • }
  • //cube
  • void cube(){
  • rotation();
  • glBegin(GL_POLYGON);
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(-0.5,-0.5,-0.5);
  • glColor3f(0.0,1.0,0.0);
  • glVertex3f(0.5,-0.5,-0.5);
  • glColor3f(0.0,0.0,1.0);
  • glVertex3f(0.5,0.5,-0.5);
  • glColor3f(1.0,1.0,1.0);
  • glVertex3f(-0.5,0.5,-0.5);
  • glEnd();
  • glBegin(GL_POLYGON);
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(-0.5,-0.5,0.5);
  • glColor3f(0.0,1.0,0.0);
  • glVertex3f(0.5,-0.5,0.5);
  • glColor3f(0.0,0.0,1.0);
  • glVertex3f(0.5,0.5,0.5);
  • glColor3f(1.0,1.0,1.0);
  • glVertex3f(-0.5,0.5,0.5);
  • glEnd();
  • glBegin(GL_POLYGON);
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(0.5,0.5,-0.5);
  • glColor3f(0.0,1.0,0.0);
  • glVertex3f(-0.5,0.5,-0.5);
  • glColor3f(0.0,0.0,1.0);
  • glVertex3f(-0.5,0.5,0.5);
  • glColor3f(1.0,1.0,1.0);
  • glVertex3f(0.5,0.5,0.5);
  • glEnd();
  • glBegin(GL_POLYGON);
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(0.5,-0.5,-0.5);
  • glColor3f(0.0,1.0,0.0);
  • glVertex3f(-0.5,-0.5,-0.5);
  • glColor3f(0.0,0.0,1.0);
  • glVertex3f(-0.5,-0.5,0.5);
  • glColor3f(1.0,1.0,1.0);
  • glVertex3f(0.5,-0.5,0.5);
  • glEnd();
  • glBegin(GL_POLYGON);
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(0.5,-0.5,-0.5);
  • glColor3f(0.0,1.0,0.0);
  • glVertex3f(0.5,0.5,-0.5);
  • glColor3f(0.0,0.0,1.0);
  • glVertex3f(0.5,0.5,0.5);
  • glColor3f(1.0,1.0,1.0);
  • glVertex3f(0.5,-0.5,0.5);
  • glEnd();
  • glBegin(GL_POLYGON);
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(-0.5,-0.5,-0.5);
  • glColor3f(0.0,1.0,0.0);
  • glVertex3f(-0.5,0.5,-0.5);
  • glColor3f(0.0,0.0,1.0);
  • glVertex3f(-0.5,0.5,0.5);
  • glColor3f(1.0,1.0,1.0);
  • glVertex3f(-0.5,-0.5,0.5);
  • glEnd();
  • }
  • //disque
  • void Disque(int rayon,int R,int G, int B){
  • int i;
  • glBegin(GL_POLYGON);
  • for(i=0;i<361;i++){
  • glColor3f(R,G,B);
  • glVertex3f(rayon*cos(i*3.14/180),rayon*sin(i*3.14/180),0);
  • }
  • glEnd();
  • }
  • //Arc de disque
  • void ArcDisque(int rayon,int debut,int fin,int R,int G, int B){
  • int i;
  • glBegin(GL_POLYGON);
  • glVertex3f(0,0,0);
  • for(i=debut;i<fin;i++){
  • glColor3f(R,G,B);
  • glVertex3f(rayon*cos(i*3.14/180),rayon*sin(i*3.14/180),0);
  • }
  • glEnd();
  • }
  • //coeur en 2D(o comme il est bo :$)
  • void Coeur2D(){
  • glBegin(GL_POLYGON);
  • //droite
  • glColor3f(1.0,0.0,0.0);
  • glVertex2f(0.0,-0.6);//a0
  • glColor3f(1.0,0.0,0.0);
  • glVertex2f(0.1,-0.5);//a1
  • glColor3f(1.0,0.0,0.0);
  • glVertex2f(0.2,-0.4);//a2
  • glColor3f(1.0,0.0,0.0);
  • glVertex2f(0.3,-0.25);//a3
  • glColor3f(1.0,0.0,0.0);
  • glVertex2f(0.4,-0.05);//a4
  • glColor3f(1.0,0.0,0.0);
  • glVertex2f(0.5,0.15);//a5
  • glColor3f(1.0,0.0,0.0);
  • glVertex2f(0.55,0.25);//a6
  • glColor3f(1.0,0.0,0.0);
  • glVertex2f(0.5,0.35);//a7
  • glColor3f(1.0,0.0,0.0);
  • glVertex2f(0.4,0.5);//a8
  • glColor3f(1.0,0.0,0.0);
  • glVertex2f(0.25,0.55);//a9
  • glColor3f(1.0,0.0,0.0);
  • glVertex2f(0.1,0.5);//a10
  • glColor3f(1.0,0.0,0.0);
  • glVertex2f(0.05,0.45);//a11
  • glColor3f(1.0,0.0,0.0);
  • glVertex2f(0.0,0.3);//a12
  • //gauche
  • glColor3f(1.0,0.0,0.0);
  • glVertex2f(-0.0,-0.6);//-a0
  • glColor3f(1.0,0.0,0.0);
  • glVertex2f(-0.1,-0.5);//-a1
  • glColor3f(1.0,0.0,0.0);
  • glVertex2f(-0.2,-0.4);//-a2
  • glColor3f(1.0,0.0,0.0);
  • glVertex2f(-0.3,-0.25);//-a3
  • glColor3f(1.0,0.0,0.0);
  • glVertex2f(-0.4,-0.05);//-a4
  • glColor3f(1.0,0.0,0.0);
  • glVertex2f(-0.5,0.15);//-a5
  • glColor3f(1.0,0.0,0.0);
  • glVertex2f(-0.55,0.25);//-a6
  • glColor3f(1.0,0.0,0.0);
  • glVertex2f(-0.5,0.35);//-a7
  • glColor3f(1.0,0.0,0.0);
  • glVertex2f(-0.4,0.5);//-a8
  • glColor3f(1.0,0.0,0.0);
  • glVertex2f(-0.25,0.55);//-a9
  • glColor3f(1.0,0.0,0.0);
  • glVertex2f(-0.1,0.5);//-a10
  • glColor3f(1.0,0.0,0.0);
  • glVertex2f(-0.05,0.45);//-a11
  • glColor3f(1.0,0.0,0.0);
  • glVertex2f(-0.0,0.3);//-a12
  • glEnd();
  • }
  • //coeur en 3D encore plus bo
  • void Coeur3D(){
  • //annimation
  • rotation();
  • glBegin(GL_POLYGON);
  • //droite
  • glColor3f(1.0,1.0,0.0);
  • glVertex3f(0.0,-0.6,0.25);//a0
  • glColor3f(1.0,1.0,0.0);
  • glVertex3f(0.1,-0.5,0.25);//a1
  • glColor3f(1.0,1.0,0.0);
  • glVertex3f(0.2,-0.4,0.25);//a2
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(0.3,-0.25,0.25);//a3
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(0.4,-0.05,0.25);//a4
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(0.5,0.15,0.25);//a5
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(0.55,0.25,0.25);//a6
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(0.5,0.35,0.25);//a7
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(0.4,0.5,0.25);//a8
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(0.25,0.55,0.25);//a9
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(0.1,0.5,0.25);//a10
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(0.05,0.45,0.25);//a11
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(0.0,0.3,0.25);//a12
  • //gauche
  • glColor3f(1.0,1.0,0.0);
  • glVertex3f(-0.0,-0.6,0.25);//-a0
  • glColor3f(1.0,1.0,0.0);
  • glVertex3f(-0.1,-0.5,0.25);//-a1
  • glColor3f(1.0,1.0,0.0);
  • glVertex3f(-0.2,-0.4,0.25);//-a2
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(-0.3,-0.25,0.25);//-a3
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(-0.4,-0.05,0.25);//-a4
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(-0.5,0.15,0.25);//-a5
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(-0.55,0.25,0.25);//-a6
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(-0.5,0.35,0.25);//-a7
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(-0.4,0.5,0.25);//-a8
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(-0.25,0.55,0.25);//-a9
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(-0.1,0.5,0.25);//-a10
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(-0.05,0.45,0.25);//-a11
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(-0.0,0.3,0.25);//-a12
  • glEnd();
  • glBegin(GL_POLYGON);
  • //droite
  • glColor3f(1.0,1.0,0.0);
  • glVertex3f(0.0,-0.6,-0.25);//a0
  • glColor3f(1.0,1.0,0.0);
  • glVertex3f(0.1,-0.5,-0.25);//a1
  • glColor3f(1.0,1.0,0.0);
  • glVertex3f(0.2,-0.4,-0.25);//a2
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(0.3,-0.25,-0.25);//a3
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(0.4,-0.05,-0.25);//a4
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(0.5,0.15,-0.25);//a5
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(0.55,0.25,-0.25);//a6
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(0.5,0.35,-0.25);//a7
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(0.4,0.5,-0.25);//a8
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(0.25,0.55,-0.25);//a9
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(0.1,0.5,-0.25);//a10
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(0.05,0.45,-0.25);//a11
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(0.0,0.3,-0.25);//a12
  • //gauche
  • glColor3f(1.0,1.0,0.0);
  • glVertex3f(-0.0,-0.6,-0.25);//-a0
  • glColor3f(1.0,1.0,0.0);
  • glVertex3f(-0.1,-0.5,-0.25);//-a1
  • glColor3f(1.0,1.0,0.0);
  • glVertex3f(-0.2,-0.4,-0.25);//-a2
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(-0.3,-0.25,-0.25);//-a3
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(-0.4,-0.05,-0.25);//-a4
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(-0.5,0.15,-0.25);//-a5
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(-0.55,0.25,-0.25);//-a6
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(-0.5,0.35,-0.25);//-a7
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(-0.4,0.5,-0.25);//-a8
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(-0.25,0.55,-0.25);//-a9
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(-0.1,0.5,-0.25);//-a10
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(-0.05,0.45,-0.25);//-a11
  • glColor3f(1.0,0.0,0.0);
  • glVertex3f(-0.0,0.3,-0.25);//-a12
  • glEnd();
  • }
//main.c

/***************************************************************** 
/  BoBRobert
/***************************************************************** 

/*Une petite "démo" pour commencer 
Bon ttes les fct ne st pas utils mais le but est de faire un moteur d'affichage réutilisable*/ 
//#include <windows.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <GL/glut.h> 
#include <math.h> 
#include <time.h> 

//Mes objets perso 
#include "formes.h" 
//#include "readconf.h" 

void affichage(); 
void clavier(unsigned char touche, int x, int y); 
void reshape(int, int); 
void mouse(int,int,int,int); 
void mousemotion(int,int); 

char presseL, presseD;/*varible globale pour l'état de la sourie*/ 

int px,py,pz; 

/*Structure permettant la définition d'un point (ca peut kan meme servir lol)*/ 
typedef struct{ 
   float x; 
   float y; 
   float z; 
   float r; 
   float g; 
   float b; 
}point; 

/*fonction d'initialisation de la fenêtre de rendu*/ 
/*paramètres en entrée : 
          - Position de la fenêtre x,y 
         - taille de la fenêtre x,y 
         - nom de la fenêtre (string) max 19 caractères 
*/ 
void Glut_Window(int xPos,int yPos,int xTaille,int yTaille,char WinName[20]){ 
   glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); 
   glutInitWindowPosition(xPos,yPos);/*position de la fenetre*/ 
   glutInitWindowSize(xTaille,yTaille);/*taille de la fenetre*/ 
   glutCreateWindow(WinName);/*création de la fenetre*/ 
} 


/*fonction de gestion du redimentionnement de la fenetre de rendu(pas super o point)*/ 
void reshape(int xWin,int yWin){ 
   if(xWin<yWin) 
      glViewport(0,(yWin-xWin)/2,xWin,xWin); 
   else 
      glViewport((xWin-yWin)/2,0,yWin,yWin); 
} 

/*Paramètres d'initialisation de la belle scène*/ 
void Glut_Init_Screen(){ 
   glClearColor(0.0,1.0,1.0,0.0);//efface tt 
   glColor3f(1.0,1.0,1.0);//initialise la couleure de font 
   glPointSize(2.0);//taille des points 
   glEnable(GL_DEPTH_TEST); 
} 


/*gère les entrées sortie*/ 
void Glut_IO(){ 
   glutDisplayFunc(affichage);//No Comment lol 
   glutKeyboardFunc(clavier); 
   glutReshapeFunc(reshape); 
   glutMouseFunc(mouse); 
   glutMotionFunc(mousemotion); 
} 


/*gestion des évennement clavier*/ 
void clavier(unsigned char touche,int x,int y) 
{ 
    switch (touche){ 
      case 'p': /*carre plein */ 
         glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); 
         glutPostRedisplay(); 
         break; 
      case 'f': /*fil de fer */ 
         glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); 
         glutPostRedisplay(); 
         break; 
      case 's': /* sommets*/ 
         glPolygonMode(GL_FRONT_AND_BACK,GL_POINT); 
         glutPostRedisplay(); 
         break; 
      /*case 'z': 
         px++; 
         glutPostRedisplay(); 
         break; 
      case 'd': 
         px--; 
         glutPostRedisplay(); 
         break;*/ 
      case 'q' : /*quitte */ 
         exit(0); 
   } 
} 

/*fonction déterminant l'état des boutons de la sourie*/ 
void mouse(int button, int stat, int x, int y){ 
//pour le bouton gauche 
   //détermine si le bouton gauche est pressé 
   if(button == GLUT_LEFT_BUTTON &stat == GLUT_DOWN){ 
      presseL=1;//état du bouton 
      xold=x; 
      yold=y; 
   } 
   //si relaché 
   if(button ==GLUT_LEFT_BUTTON &stat == GLUT_UP) 
   presseL=0; 

//pour le bouton droit 
} 

void mousemotion(int x, int y){ 
   if(presseL==1){ 
      anglex=anglex+(x-xold); 
      angley=angley+(y-yold); 
      glutPostRedisplay(); 
   } 
   xold=x; 
   yold=y; 
} 


/*fct d'affichage de la scène*/ 
void affichage() 
{ 
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    
   //Coeur3D(); 
   //glTranslatef(-px,0.0,-pz); 
   cube(); 
   //Disque(1,1,1,1); 
   //glutWireSphere(1,20,20); 

   glFlush(); 

   glutSwapBuffers(); 
} 


//Le Bo main 
int main(int argc, char **argv){ 

   printf("Welcome in THE opengl World\n"); 
   //read_conf(); 
   glutInit(&argc,argv);/*initialise GLUT*/ 

   Glut_Window(200,200,500,500,"OpenGL Power!!!!!!");/*initialisation de la fenetre*/ 
  
   Glut_Init_Screen();/*paramètres de la scène*/ 

   Glut_IO();/*entrées sorties*/ 

   glutMainLoop(); 
   return 0; 
} 

//formes.h a mettre ds un autre ficher

/*lib de ttes les formes (lol)*/ 

int anglex, angley, x, y, xold, yold;//variables globales de gestion de la position de la sourie 

/*définition d'objets divers et variée*/ 

void rotation(){ 
   glLoadIdentity(); 
   glRotatef(-angley,1.1,0.0,0.0); 
   glRotatef(-anglex,0.0,1.0,0.0); 
} 

//carré 2D 
void Carre2D(){ 
//carré 
    glBegin(GL_POLYGON); 
   glColor3f(1.0,0.0,0.0); 
   glVertex2f(-0.5,-0.5); 
   glColor3f(0.0,1.0,0.0); 
   glVertex2f(0.5,-0.5); 
   glColor3f(0.0,0.0,1.0); 
   glVertex2f(0.5,0.5); 
   glColor3f(1.0,1.0,1.0); 
   glVertex2f(-0.5,0.5); 
   glEnd(); 
} 

//cube 
void cube(){ 

rotation(); 

    glBegin(GL_POLYGON); 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(-0.5,-0.5,-0.5); 
   glColor3f(0.0,1.0,0.0); 
   glVertex3f(0.5,-0.5,-0.5); 
   glColor3f(0.0,0.0,1.0); 
   glVertex3f(0.5,0.5,-0.5); 
   glColor3f(1.0,1.0,1.0); 
   glVertex3f(-0.5,0.5,-0.5); 
   glEnd(); 
    
    glBegin(GL_POLYGON); 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(-0.5,-0.5,0.5); 
   glColor3f(0.0,1.0,0.0); 
   glVertex3f(0.5,-0.5,0.5); 
   glColor3f(0.0,0.0,1.0); 
   glVertex3f(0.5,0.5,0.5); 
   glColor3f(1.0,1.0,1.0); 
   glVertex3f(-0.5,0.5,0.5); 
   glEnd(); 
    
   glBegin(GL_POLYGON); 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(0.5,0.5,-0.5); 
   glColor3f(0.0,1.0,0.0); 
   glVertex3f(-0.5,0.5,-0.5); 
   glColor3f(0.0,0.0,1.0); 
   glVertex3f(-0.5,0.5,0.5); 
   glColor3f(1.0,1.0,1.0); 
   glVertex3f(0.5,0.5,0.5); 
   glEnd(); 
    
   glBegin(GL_POLYGON); 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(0.5,-0.5,-0.5); 
   glColor3f(0.0,1.0,0.0); 
   glVertex3f(-0.5,-0.5,-0.5); 
   glColor3f(0.0,0.0,1.0); 
   glVertex3f(-0.5,-0.5,0.5); 
   glColor3f(1.0,1.0,1.0); 
   glVertex3f(0.5,-0.5,0.5); 
   glEnd(); 
    
   glBegin(GL_POLYGON); 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(0.5,-0.5,-0.5); 
   glColor3f(0.0,1.0,0.0); 
   glVertex3f(0.5,0.5,-0.5); 
   glColor3f(0.0,0.0,1.0); 
   glVertex3f(0.5,0.5,0.5); 
   glColor3f(1.0,1.0,1.0); 
   glVertex3f(0.5,-0.5,0.5); 
   glEnd(); 
    
    glBegin(GL_POLYGON); 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(-0.5,-0.5,-0.5); 
   glColor3f(0.0,1.0,0.0); 
   glVertex3f(-0.5,0.5,-0.5); 
   glColor3f(0.0,0.0,1.0); 
   glVertex3f(-0.5,0.5,0.5); 
   glColor3f(1.0,1.0,1.0); 
   glVertex3f(-0.5,-0.5,0.5); 
   glEnd(); 
} 

//disque 
void Disque(int rayon,int R,int G, int B){ 
int i; 
glBegin(GL_POLYGON); 
    for(i=0;i<361;i++){ 
        glColor3f(R,G,B); 
        glVertex3f(rayon*cos(i*3.14/180),rayon*sin(i*3.14/180),0); 
    } 
glEnd(); 
} 

//Arc de disque 
void ArcDisque(int rayon,int debut,int fin,int R,int G, int B){ 
int i; 
glBegin(GL_POLYGON); 
glVertex3f(0,0,0); 
    for(i=debut;i<fin;i++){ 
        glColor3f(R,G,B); 
        glVertex3f(rayon*cos(i*3.14/180),rayon*sin(i*3.14/180),0); 
    } 
glEnd(); 
} 

//coeur en 2D(o comme il est bo :$) 
void Coeur2D(){ 
   glBegin(GL_POLYGON); 
//droite 
   glColor3f(1.0,0.0,0.0); 
   glVertex2f(0.0,-0.6);//a0 
   glColor3f(1.0,0.0,0.0); 
   glVertex2f(0.1,-0.5);//a1 
   glColor3f(1.0,0.0,0.0); 
   glVertex2f(0.2,-0.4);//a2 
   glColor3f(1.0,0.0,0.0); 
   glVertex2f(0.3,-0.25);//a3 
   glColor3f(1.0,0.0,0.0); 
   glVertex2f(0.4,-0.05);//a4 
   glColor3f(1.0,0.0,0.0); 
   glVertex2f(0.5,0.15);//a5 
   glColor3f(1.0,0.0,0.0); 
   glVertex2f(0.55,0.25);//a6 
   glColor3f(1.0,0.0,0.0); 
   glVertex2f(0.5,0.35);//a7 
   glColor3f(1.0,0.0,0.0); 
   glVertex2f(0.4,0.5);//a8 
   glColor3f(1.0,0.0,0.0); 
   glVertex2f(0.25,0.55);//a9 
   glColor3f(1.0,0.0,0.0); 
   glVertex2f(0.1,0.5);//a10 
   glColor3f(1.0,0.0,0.0); 
   glVertex2f(0.05,0.45);//a11 
   glColor3f(1.0,0.0,0.0); 
   glVertex2f(0.0,0.3);//a12 
//gauche 
   glColor3f(1.0,0.0,0.0); 
   glVertex2f(-0.0,-0.6);//-a0 
   glColor3f(1.0,0.0,0.0); 
   glVertex2f(-0.1,-0.5);//-a1 
   glColor3f(1.0,0.0,0.0); 
   glVertex2f(-0.2,-0.4);//-a2 
   glColor3f(1.0,0.0,0.0); 
   glVertex2f(-0.3,-0.25);//-a3 
   glColor3f(1.0,0.0,0.0); 
   glVertex2f(-0.4,-0.05);//-a4 
   glColor3f(1.0,0.0,0.0); 
   glVertex2f(-0.5,0.15);//-a5 
   glColor3f(1.0,0.0,0.0); 
   glVertex2f(-0.55,0.25);//-a6 
   glColor3f(1.0,0.0,0.0); 
   glVertex2f(-0.5,0.35);//-a7 
   glColor3f(1.0,0.0,0.0); 
   glVertex2f(-0.4,0.5);//-a8 
   glColor3f(1.0,0.0,0.0); 
   glVertex2f(-0.25,0.55);//-a9 
   glColor3f(1.0,0.0,0.0); 
   glVertex2f(-0.1,0.5);//-a10 
   glColor3f(1.0,0.0,0.0); 
   glVertex2f(-0.05,0.45);//-a11 
   glColor3f(1.0,0.0,0.0); 
   glVertex2f(-0.0,0.3);//-a12 
   glEnd(); 
} 

//coeur en 3D encore plus bo 
void Coeur3D(){ 
//annimation 
rotation(); 

   glBegin(GL_POLYGON); 
//droite 
   glColor3f(1.0,1.0,0.0); 
   glVertex3f(0.0,-0.6,0.25);//a0 
   glColor3f(1.0,1.0,0.0); 
   glVertex3f(0.1,-0.5,0.25);//a1 
   glColor3f(1.0,1.0,0.0); 
   glVertex3f(0.2,-0.4,0.25);//a2 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(0.3,-0.25,0.25);//a3 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(0.4,-0.05,0.25);//a4 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(0.5,0.15,0.25);//a5 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(0.55,0.25,0.25);//a6 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(0.5,0.35,0.25);//a7 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(0.4,0.5,0.25);//a8 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(0.25,0.55,0.25);//a9 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(0.1,0.5,0.25);//a10 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(0.05,0.45,0.25);//a11 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(0.0,0.3,0.25);//a12 
//gauche 
   glColor3f(1.0,1.0,0.0); 
   glVertex3f(-0.0,-0.6,0.25);//-a0 
   glColor3f(1.0,1.0,0.0); 
   glVertex3f(-0.1,-0.5,0.25);//-a1 
   glColor3f(1.0,1.0,0.0); 
   glVertex3f(-0.2,-0.4,0.25);//-a2 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(-0.3,-0.25,0.25);//-a3 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(-0.4,-0.05,0.25);//-a4 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(-0.5,0.15,0.25);//-a5 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(-0.55,0.25,0.25);//-a6 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(-0.5,0.35,0.25);//-a7 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(-0.4,0.5,0.25);//-a8 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(-0.25,0.55,0.25);//-a9 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(-0.1,0.5,0.25);//-a10 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(-0.05,0.45,0.25);//-a11 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(-0.0,0.3,0.25);//-a12 
   glEnd(); 

   glBegin(GL_POLYGON); 
//droite 
   glColor3f(1.0,1.0,0.0); 
   glVertex3f(0.0,-0.6,-0.25);//a0 
   glColor3f(1.0,1.0,0.0); 
   glVertex3f(0.1,-0.5,-0.25);//a1 
   glColor3f(1.0,1.0,0.0); 
   glVertex3f(0.2,-0.4,-0.25);//a2 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(0.3,-0.25,-0.25);//a3 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(0.4,-0.05,-0.25);//a4 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(0.5,0.15,-0.25);//a5 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(0.55,0.25,-0.25);//a6 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(0.5,0.35,-0.25);//a7 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(0.4,0.5,-0.25);//a8 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(0.25,0.55,-0.25);//a9 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(0.1,0.5,-0.25);//a10 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(0.05,0.45,-0.25);//a11 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(0.0,0.3,-0.25);//a12 
//gauche 
   glColor3f(1.0,1.0,0.0); 
   glVertex3f(-0.0,-0.6,-0.25);//-a0 
   glColor3f(1.0,1.0,0.0); 
   glVertex3f(-0.1,-0.5,-0.25);//-a1 
   glColor3f(1.0,1.0,0.0); 
   glVertex3f(-0.2,-0.4,-0.25);//-a2 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(-0.3,-0.25,-0.25);//-a3 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(-0.4,-0.05,-0.25);//-a4 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(-0.5,0.15,-0.25);//-a5 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(-0.55,0.25,-0.25);//-a6 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(-0.5,0.35,-0.25);//-a7 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(-0.4,0.5,-0.25);//-a8 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(-0.25,0.55,-0.25);//-a9 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(-0.1,0.5,-0.25);//-a10 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(-0.05,0.45,-0.25);//-a11 
   glColor3f(1.0,0.0,0.0); 
   glVertex3f(-0.0,0.3,-0.25);//-a12 
   glEnd(); 
}



 Sources du même auteur

Source avec Zip AFFICHAGE DU TABLEAU DES 256 VALEURS EN ASCII

 Sources de la même categorie

Source avec Zip Source avec une capture AFFICHER DES COURBES DE BEZIER par shorzy
Source avec Zip Source avec une capture BASE/MOTEUR 3D EN QT/OPENGL (COMPLET ET FONCTIONNEL!) POUR U... par envi33
Source avec Zip Source avec une capture CLASSE AVEC OPENGL - OBJETS 3D ET ANIMATIONS par rasta63
Source avec Zip Source avec une capture LETTRES 3D AVEC OPENGL ET QT par opossum_farceur
Source avec Zip CUBE 3D GLUT32 VC++ ET DEVC++ par bobby03

Commentaires et avis

Commentaire de Arnaud16022 le 14/04/2005 21:58:18

#include "formes.h"
pas inclus dans la source + pas de zip

Commentaire de Cyberboy2054 le 15/04/2005 15:55:39

Elle sert a quoi la structure point vu que tu t'en sers pas ?
Sinon j'ai pas trouvé ce qui est réutilisable la dedans ...

Commentaire de nightlord666 le 06/08/2005 22:57:14

Juste une question : pourquoi dans la fonction disque tu met les couleurs en int alors qu'elles sont en float normalement ?

Sinon je trouve ta source super pour moi qui avait jamais programmé en OPENGL. Je t'ai mis 7 (pas de ZIP...).

Commentaire de aymenk le 06/09/2011 23:56:25 2/10

"formes.h" introuvable , on ne peut compilé ce code ...désolé pour la note

Commentaire de aymenk le 06/09/2011 23:57:20

...et désolé pour ce retard je vois que votre code et vieux de 6 ans et sans mise à jour...

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,452 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales