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
|
SDL_Color couleurNoire = {0, 0, 0};
SDL_Color couleurVerte = {0,0xff,0};
void Init()
{
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
//Définit la position de la fenêtre sur l'écran
glutInitWindowPosition(0,0);
//Définit la taille de la fenêtre à l'écran
glutInitWindowSize(600, 800);
//Création de la fenètre de nom simple
glutCreateWindow("nom de fenetre");
// Mise en place de la vue OpenGL
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// Mise en place de la perspective
gluPerspective(45.0f,(GLfloat)w/(GLfloat)h,0.1f,1000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
lightDiffuse[0]= 1.0f;
lightDiffuse[1]= 1.0f;
lightDiffuse[2]= 1.0f;
lightDiffuse[3]= 1.0f;
light2Pos[0]= 50.0f;
light2Pos[1]= 50.0f;
light2Pos[2]= -50.0f;
light2Pos[3]= 0.0f;
light1Pos[0]= -50.0f;
light1Pos[1]= 50.0f;
light1Pos[2]= 50.0f;
light1Pos[3]= 0.0f;
glLightfv(GL_LIGHT1, GL_DIFFUSE, lightDiffuse);
glLightfv(GL_LIGHT2, GL_DIFFUSE, lightDiffuse);
glLightfv(GL_LIGHT1, GL_SPECULAR, lightDiffuse);
glLightfv(GL_LIGHT2, GL_SPECULAR, lightDiffuse);
glLightfv(GL_LIGHT1, GL_POSITION, light1Pos);
glLightfv(GL_LIGHT2, GL_POSITION, light2Pos);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHT2);
glEnable(GL_LIGHTING);
glClearColor(0.3F,0.7F,0.9F,1.0F);
glShadeModel (GL_SMOOTH);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL);
if(TTF_Init() == -1) //initialisation de SDL_TTF
{
fprintf(stderr, "Erreur d'initialisation de TTF_Init : %s\n", TTF_GetError());
exit(EXIT_FAILURE);
}
// chargement de la police
police = TTF_OpenFont("arial.ttf", 48);
if (police== NULL) {
printf("TTF_OpenFont: %s\n", TTF_GetError());
exit(3);
}
ecran = TTF_RenderText_Shaded(police,"test", couleurNoire, couleurVerte);
glGenTextures(1, &tex);
if (tex == 0) {
puts("err while gen tex");
exit(4);
}
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// choix du format en fonction du nombres d'octets par pixel
switch (ecran->format->BytesPerPixel) {
case 1:
internalFormat = 1;
format = GL_LUMINANCE;
break;
case 2:
internalFormat = 2;
format = GL_LUMINANCE_ALPHA;
break;
case 3:
internalFormat = 3;
format = GL_RGB;
break;
case 4:
internalFormat = 4;
format = GL_RGBA;
break;
default:
printf ("unknown pixel format (%d byte(s) per pixel). Exiting.\n",
ecran->format->BytesPerPixel);
exit (5);
}
buildResult = gluBuild2DMipmaps(GL_TEXTURE_2D, internalFormat,
ecran->w, ecran->h,
format, GL_UNSIGNED_BYTE,
ecran->pixels);
printf("resultat: %d (%s)\n"
"octets par pixel:%d\n",buildResult ,
gluErrorString(buildResult),
ecran->format->BytesPerPixel);
SDL_FreeSurface(ecran);
glutFullScreen();
} |
Partager