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
| #include <SDL/SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <opencv/highgui.h>
#include <opencv/cv.h>
#include <cstdlib>
#include "sdlglutils.cpp"
#include "image.h"
#include "charger.c"
void Dessiner();
GLuint texture1;
GLuint texture[263][400][3];
int main(int argc, char *argv[])
{
int i,j;
Image im;
im = (Image)malloc(sizeof(struct ima));
SDL_Event event;
SDL_Init(SDL_INIT_VIDEO);
atexit(SDL_Quit);
SDL_WM_SetCaption("SDL GL Application", NULL);
SDL_SetVideoMode(640, 480, 32, SDL_OPENGL);
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective(70,(double)640/480,1,1000);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
charger(im,"lost.ppm");
printf("%d %d\n",(*im).hauteur,(*im).largeur);
for(i=0;i<(*im).hauteur;i++){
for(j=0;j<(*im).largeur;j++){
texture[i][j][0]=(*im).image[j][i].r;
texture[i][j][1]=(*im).image[j][i].g;
texture[i][j][2]=(*im).image[j][i].b;
}
}
printf("Termine\n");
glGenTextures(1,&texture1);
glBindTexture(GL_TEXTURE_2D, texture1);
glTexImage2D(GL_TEXTURE_2D,0,3,640,480,0,GL_RGB,GL_INT,texture);
Dessiner();
Uint32 last_time = SDL_GetTicks();
Uint32 current_time,ellapsed_time;
Uint32 start_time;
for (;;)
{
start_time = SDL_GetTicks();
while (SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
exit(0);
break;
}
}
current_time = SDL_GetTicks();
ellapsed_time = current_time - last_time;
last_time = current_time;
Dessiner();
ellapsed_time = SDL_GetTicks() - start_time;
if (ellapsed_time < 10)
{
SDL_Delay(10 - ellapsed_time);
}
}
return 0;
}
void Dessiner()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
gluLookAt(0,5,0,0,0,0,0,0,1);
glMatrixMode( GL_TEXTURE );
glLoadIdentity( );
glBindTexture(GL_TEXTURE_2D, texture1);
glPushMatrix();
glBegin(GL_QUADS);
glTexCoord2d(0,1);
glVertex3d(1,1,1);
glTexCoord2d(0,0);
glVertex3d(1,1,-1);
glTexCoord2d(1,0);
glVertex3d(-1,1,-1);
glTexCoord2d(1,1);
glVertex3d(-1,1,1);
glEnd();
glFlush();
SDL_GL_SwapBuffers();
} |
Partager