/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Avril 2001 */
/* Une facette texturee avec un damier */
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "ModuleManipulateur.h"
#include "ModuleMenus.h"
#include "ModuleReshape.h"
static GLbyte *image ;
static int w2 ;
static int h2 ;
GLbyte *makeRasterImage() {
GLbyte *image =(GLbyte *) malloc(768*sizeof(GLbyte));
for ( int i = 0 ; i < 16 ; i++ )
for ( int j = 0 ; j < 16 ; j++ ) {
int p = 3*(j+i*16);
image[p] = image[p+1] = image[p+2] = ((((i/4)+(j/4))%2) == 0 ) ? 0xFF : 0x00 ; }
return(image);
}
void display2() {
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRasterPos2i(w2/2-8,h2/2-8);
glDrawPixels(16,16,GL_RGB,GL_UNSIGNED_BYTE,image);
glPopMatrix();
glutSwapBuffers();
}
void reshape2(int w,int h) {
w2 = w;
h2 = h;
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,w,0,h,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void display1() {
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
glPushMatrix();
manipulateurSouris();
manipulateurClavier();
glBegin(GL_POLYGON);
glTexCoord2f(0.0f,0.0f);
glVertex3f(-4.0f,1.0f,-2.0f);
glTexCoord2f(0.0f,2.0f);
glVertex3f(2.0f,4.0f,3.0f);
glTexCoord2f(1.0f,2.0f);
glVertex3f(5.0f,-1.0f,-1.0f);
glTexCoord2f(1.0f,0.0f);
glVertex3f(-3.0f,-2.0f,4.0f);
glEnd();
glPopMatrix();
glutSwapBuffers();
}
void myInit1() {
image = makeRasterImage();
glTexImage2D(GL_TEXTURE_2D,0,3,16,16,0,GL_RGB,GL_UNSIGNED_BYTE,image);
glEnable(GL_TEXTURE_2D);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
}
void myInit2() {
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
}
int main(int argc,char **argv) {
glutInit(&argc,argv);
glutInitWindowSize(250,250);
glutInitWindowPosition(50,50);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
int f1 = glutCreateWindow("Facette texturee");
creationMenuBasique();
myInit1();
setParametresPerspectiveBasique(65.0F,1.0F,1.0F,20.0F,0.0F,0.0F,-10.0F);
setManipulateurDistance(10.0F);
glutReshapeFunc(reshapePerspectiveBasique);
glutDisplayFunc(display1);
glutKeyboardFunc(keyBasique);
glutSpecialFunc(specialBasique);
glutMotionFunc(motionBasique);
glutMouseFunc(sourisBasique);
glutInitWindowPosition(350,100);
glutInitWindowSize(170,80);
int f2 = glutCreateWindow("Texture utilisee");
creationMenuBasique();
myInit2();
glutDisplayFunc(display2);
glutReshapeFunc(reshape2);
glutMainLoop();
return(0);
}