1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
#ifdef __cplusplus
#include <cstdlib>
#else
#include <stdlib.h>
#endif
#ifdef __APPLE__
#include <SDL/SDL.h>
#else
#include <SDL.h>
#endif
#include <GL/glew.h>
#include <textfile.h>
void Display();
float angle=0;
int main ( int argc, char** argv )
{
// initialize SDL video
if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "Unable to init SDL: %s\n", SDL_GetError() );
return 1;
}
// make sure SDL cleans up before exit
atexit(SDL_Quit);
// create a new window
SDL_Surface* openGLContext = SDL_SetVideoMode(640, 480, 16,
SDL_OPENGL);
if ( !openGLContext )
{
printf("Unable to set 640x480 video: %s\n", SDL_GetError());
return 1;
}
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32);
// Propriété de l'affichage
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glClearColor(0.0f,0.0f,0.0f,0.5f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glViewport(0,0,800,600);
gluPerspective(45.0,800.0/600.0,1.0,100.0); // Angle de la caméra, clipping entre 1 et 100 (pas à partir de 0,
glMatrixMode(GL_MODELVIEW); // sinon on perd toute la précision du z-buffer)
/* SHADERS QUI FONT SYSTEMATIQUEMENT PLANTER AVEC RETURN = 3... ?
//création et importation des fichiers du cel-shading
GLuint fragmentShader;
GLuint vertexShader;
vertexShader = glCreateShader(GL_VERTEX_SHADER);
fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
char *vs = textFileRead("toon.vert");
char *fs = textFileRead("toon.frag");
const char *vv=vs;
const char *ff=fs;
glShaderSource(vertexShader, 1, &vv,NULL);
glShaderSource(fragmentShader, 1, &ff,NULL);
free(vs);free(fs);
glCompileShader(vertexShader);
glCompileShader(fragmentShader);
GLuint program;
program = glCreateProgram();
glAttachShader(program,vertexShader);
glAttachShader(program,fragmentShader);
glLinkProgram(program);
glUseProgram(program);*/
// program main loop
bool Running = true;
while (Running)
{
// message processing loop
SDL_Event event;
while (SDL_PollEvent(&event))
{
if (event.type==SDL_QUIT){Running = false ;}
}
Display();
if (angle>=360){angle=0;}
angle++;
}
return 0;
}
// DISPLAY QUI FAIT "FUIR" LE CUBE
void Display()
{
glClearColor(0,0,0,0); // selectionne la couleur noire (qui est celle par défaut)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(angle, 1,0,0);
glRotatef(angle, 0,1,0);
glRotatef(angle, 0,0,1);
gluLookAt(4,3,3,0,0,0,0,1,0);
glBegin(GL_QUADS);
glColor3d(1,0,0);
glVertex3i(1,1,1);
glVertex3i(1,-1,1);
glVertex3i(-1,-1,1);
glVertex3i(-1,1,1);
glColor3d(0,1,0);
glVertex3i(1,1,-1);
glVertex3i(1,-1,-1);
glVertex3i(-1,-1,-1);
glVertex3i(-1,1,-1);
glColor3d(0,0,1);
glVertex3i(1,1,1);
glVertex3i(1,-1,1);
glVertex3i(1,-1,-1);
glVertex3i(1,1,-1);
glColor3d(0,1,1);
glVertex3i(-1,1,1);
glVertex3i(-1,-1,1);
glVertex3i(-1,-1,-1);
glVertex3i(-1,1,-1);
glColor3d(1,1,0);
glVertex3i(-1,1,-1);
glVertex3i(-1,1,1);
glVertex3i(1,1,1);
glVertex3i(1,1,-1);
glColor3d(1,0,1);
glVertex3i(-1,-1,-1);
glVertex3i(-1,-1,1);
glVertex3i(1,-1,1);
glVertex3i(1,-1,-1);
glEnd();
SDL_GL_SwapBuffers( );
} |
Partager