132001f49Smrg/** 232001f49Smrg * Enable as much fixed-function vertex processing state as possible 332001f49Smrg * to test fixed-function -> program code generation. 432001f49Smrg */ 532001f49Smrg 632001f49Smrg 732001f49Smrg 832001f49Smrg#include <GL/glew.h> 932001f49Smrg#include <stdio.h> 1032001f49Smrg#include <string.h> 1132001f49Smrg#include <stdlib.h> 1232001f49Smrg#include "glut_wrap.h" 1332001f49Smrg 1432001f49Smrg 1532001f49Smrgstatic void 1632001f49SmrgReshape(int width, int height) 1732001f49Smrg{ 1832001f49Smrg glViewport(0, 0, (GLint)width, (GLint)height); 1932001f49Smrg glMatrixMode(GL_PROJECTION); 2032001f49Smrg glLoadIdentity(); 2132001f49Smrg glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); 2232001f49Smrg glMatrixMode(GL_MODELVIEW); 2332001f49Smrg} 2432001f49Smrg 2532001f49Smrg 2632001f49Smrgstatic void 2732001f49SmrgDraw(void) 2832001f49Smrg{ 2932001f49Smrg glClear(GL_COLOR_BUFFER_BIT); 3032001f49Smrg 3132001f49Smrg glBegin(GL_TRIANGLES); 3232001f49Smrg glColor3f(.8,0,0); 3332001f49Smrg glVertex3f(-0.9, -0.9, -30.0); 3432001f49Smrg glColor3f(0,.9,0); 3532001f49Smrg glVertex3f( 0.9, -0.9, -30.0); 3632001f49Smrg glColor3f(0,0,.7); 3732001f49Smrg glVertex3f( 0.0, 0.9, -30.0); 3832001f49Smrg glEnd(); 3932001f49Smrg 4032001f49Smrg glFlush(); 4132001f49Smrg 4232001f49Smrg glutSwapBuffers(); 4332001f49Smrg} 4432001f49Smrg 4532001f49Smrg 4632001f49Smrgstatic void 4732001f49SmrgInit(void) 4832001f49Smrg{ 4932001f49Smrg GLubyte tex[16][16][4]; 5032001f49Smrg GLfloat pos[4] = {5, 10, 3, 1.0}; 5132001f49Smrg int i, j; 5232001f49Smrg 5332001f49Smrg fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); 5432001f49Smrg fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); 5532001f49Smrg fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); 5632001f49Smrg fflush(stderr); 5732001f49Smrg 5832001f49Smrg glClearColor(0.3, 0.1, 0.3, 0.0); 5932001f49Smrg 6032001f49Smrg for (i = 0; i < 16; i++) { 6132001f49Smrg for (j = 0; j < 16; j++) { 6232001f49Smrg if ((i+j) & 1) { 6332001f49Smrg tex[i][j][0] = 100; 6432001f49Smrg tex[i][j][1] = 100; 6532001f49Smrg tex[i][j][2] = 100; 6632001f49Smrg tex[i][j][3] = 255; 6732001f49Smrg } 6832001f49Smrg else { 6932001f49Smrg tex[i][j][0] = 200; 7032001f49Smrg tex[i][j][1] = 200; 7132001f49Smrg tex[i][j][2] = 200; 7232001f49Smrg tex[i][j][3] = 255; 7332001f49Smrg } 7432001f49Smrg } 7532001f49Smrg } 7632001f49Smrg 7732001f49Smrg 7832001f49Smrg glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1); 7932001f49Smrg glFogi(GL_FOG_MODE, GL_LINEAR); 8032001f49Smrg glEnable(GL_FOG); 8132001f49Smrg 8232001f49Smrg glPointParameterfv(GL_DISTANCE_ATTENUATION_EXT, pos); 8332001f49Smrg 8432001f49Smrg for (i = 0; i < 8; i++) { 8532001f49Smrg GLuint texObj; 8632001f49Smrg 8732001f49Smrg glEnable(GL_LIGHT0 + i); 8832001f49Smrg glLightf(GL_LIGHT0 + i, GL_SPOT_EXPONENT, 3.5); 8932001f49Smrg glLightf(GL_LIGHT0 + i, GL_SPOT_CUTOFF, 30.); 9032001f49Smrg glLightf(GL_LIGHT0 + i, GL_CONSTANT_ATTENUATION, 3.); 9132001f49Smrg glLightf(GL_LIGHT0 + i, GL_LINEAR_ATTENUATION, 3.); 9232001f49Smrg glLightf(GL_LIGHT0 + i, GL_QUADRATIC_ATTENUATION, 3.); 9332001f49Smrg glLightfv(GL_LIGHT0 + i, GL_POSITION, pos); 9432001f49Smrg 9532001f49Smrg glActiveTexture(GL_TEXTURE0 + i); 9632001f49Smrg glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); 9732001f49Smrg glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); 9832001f49Smrg glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); 9932001f49Smrg glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); 10032001f49Smrg glEnable(GL_TEXTURE_GEN_S); 10132001f49Smrg glEnable(GL_TEXTURE_GEN_T); 10232001f49Smrg glEnable(GL_TEXTURE_GEN_R); 10332001f49Smrg glEnable(GL_TEXTURE_GEN_Q); 10432001f49Smrg glEnable(GL_TEXTURE_2D); 10532001f49Smrg 10632001f49Smrg glMatrixMode(GL_TEXTURE); 10732001f49Smrg glScalef(2.0, 1.0, 3.0); 10832001f49Smrg 10932001f49Smrg glGenTextures(1, &texObj); 11032001f49Smrg glBindTexture(GL_TEXTURE_2D, texObj); 11132001f49Smrg glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, 11232001f49Smrg GL_RGBA, GL_UNSIGNED_BYTE, tex); 11332001f49Smrg glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 11432001f49Smrg glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 11532001f49Smrg glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 11632001f49Smrg } 11732001f49Smrg 11832001f49Smrg glEnable(GL_LIGHTING); 11932001f49Smrg glActiveTexture(GL_TEXTURE0); 12032001f49Smrg glMatrixMode(GL_MODELVIEW); 12132001f49Smrg} 12232001f49Smrg 12332001f49Smrg 12432001f49Smrgstatic void 12532001f49SmrgKey(unsigned char key, int x, int y) 12632001f49Smrg{ 12732001f49Smrg if (key == 27) { 12832001f49Smrg exit(0); 12932001f49Smrg } 13032001f49Smrg glutPostRedisplay(); 13132001f49Smrg} 13232001f49Smrg 13332001f49Smrg 13432001f49Smrgint 13532001f49Smrgmain(int argc, char **argv) 13632001f49Smrg{ 13732001f49Smrg GLenum type = GLUT_RGB | GLUT_DOUBLE; 13832001f49Smrg 13932001f49Smrg glutInit(&argc, argv); 14032001f49Smrg glutInitWindowPosition(0, 0); 14132001f49Smrg glutInitWindowSize( 250, 250); 14232001f49Smrg glutInitDisplayMode(type); 14332001f49Smrg if (glutCreateWindow(*argv) == GL_FALSE) { 14432001f49Smrg exit(1); 14532001f49Smrg } 14632001f49Smrg glewInit(); 14732001f49Smrg glutReshapeFunc(Reshape); 14832001f49Smrg glutKeyboardFunc(Key); 14932001f49Smrg glutDisplayFunc(Draw); 15032001f49Smrg Init(); 15132001f49Smrg glutMainLoop(); 15232001f49Smrg return 0; 15332001f49Smrg} 154