void NonASCIIKeyboardPress(int key, int mouseXPosition, int mouseYPosition) { switch (key) { case UP_KEY: cameraFrame.MoveForward(CAMERA_LINEAR_STEP); break; case DOWN_KEY: cameraFrame.MoveForward(-CAMERA_LINEAR_STEP); break; case LEFT_KEY: cameraFrame.RotateWorld(CAMERA_ANGULAR_STEP, 0.0f, 1.0f, 0.0f); break; case RIGHT_KEY: cameraFrame.RotateWorld(-CAMERA_ANGULAR_STEP, 0.0f, 1.0f, 0.0f); break; case F1_KEY: fullscreen = !fullscreen; fullscreen ? glutFullScreen() : glutReshapeWindow(ORIG_WINDOW_SIZE[0], ORIG_WINDOW_SIZE[1]); break; default: break; } }
void SpecialKeys(int key, int x, int y) { float linear = 0.1f; float angular = float(m3dDegToRad(5.0f)); if (key == GLUT_KEY_UP) { cameraFrame.MoveForward(linear); } if (key == GLUT_KEY_DOWN) { cameraFrame.MoveForward(-linear); } if (key == GLUT_KEY_LEFT) { cameraFrame.RotateWorld(angular, 0.0f, 1.0f, 0.0f); } if (key == GLUT_KEY_RIGHT) { cameraFrame.RotateWorld(-angular, 0.0f, 1.0f, 0.0f); } }
// called on arrow keys void SpecialKeys(int key, int x, int y){ float linear = 0.1f; float angular = float(m3dDegToRad(5.0f)); // TODO - flatten movement to the XZ axis if(key == GLUT_KEY_UP) cameraFrame.MoveForward(linear); if(key == GLUT_KEY_DOWN) cameraFrame.MoveForward(-linear); if(key == GLUT_KEY_LEFT) cameraFrame.RotateWorld(angular, 0.0f, 1.0f, 0.0f); if(key == GLUT_KEY_RIGHT) cameraFrame.RotateWorld(-angular, 0.0f, 1.0f, 0.0f); }
// This function does any needed initialization on the rendering context. static void SetupRC(void) { // Background glClearColor(0.2f, 0.2f, 0.3f, 1.0f ); glEnable(GL_DEPTH_TEST); shaderManager.InitializeStockShaders(); viewFrame.MoveForward(4.0f); // Make the torus gltMakeTorus(torusBatch, .70f, 0.30f, 32, 16); cullingShader = gltLoadShaderTripletWithAttributes("../../Data/Shaders/Chapter11/GSCulling.vs", "../../Data/Shaders/Chapter11/GSCulling.gs", "../../Data/Shaders/Chapter11/GSCulling.fs", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_NORMAL, "vNormal"); locMVP = glGetUniformLocation(cullingShader, "mvpMatrix"); locMV = glGetUniformLocation(cullingShader, "mvMatrix"); locNM = glGetUniformLocation(cullingShader, "normalMatrix"); locViewpoint = glGetUniformLocation(cullingShader, "viewpoint"); }
// This function does any needed initialization on the rendering // context. void SetupRC(void) { // Background glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); shaderManager.InitializeStockShaders(); viewFrame.MoveForward(4.0f); // Make the sphere gltMakeSphere(sphereBatch, 1.0f, 52, 26); normalMapShader = gltLoadShaderPairWithAttributes("NormalMapped\\NormalMapped.vp", "NormalMapped\\NormalMapped.fp", 3, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_NORMAL, "vNormal", GLT_ATTRIBUTE_TEXTURE0, "vTexture0"); locAmbient = glGetUniformLocation(normalMapShader, "ambientColor"); locDiffuse = glGetUniformLocation(normalMapShader, "diffuseColor"); locLight = glGetUniformLocation(normalMapShader, "vLightPosition"); locMVP = glGetUniformLocation(normalMapShader, "mvpMatrix"); locMV = glGetUniformLocation(normalMapShader, "mvMatrix"); locNM = glGetUniformLocation(normalMapShader, "normalMatrix"); locColorMap = glGetUniformLocation(normalMapShader, "colorMap"); locNormalMap = glGetUniformLocation(normalMapShader, "normalMap"); glGenTextures(2, texture); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture[0]); LoadTGATexture("NormalMapped\\IceMoon.tga", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, texture[1]); LoadTGATexture("NormalMapped\\IceMoonBump.tga", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT); }
void SetupRC() { // Background glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); viewFrame.MoveForward(4.0f); shaderManager.InitializeStockShaders(); // Simple triangle // Load up a triangle GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f }; GLfloat vTexCoords [] = { 0.0f, 0.0f, 1.0f, 0.0f, 0.5f, 1.0f }; triangleBatch.Begin(GL_TRIANGLES, 3, 1); triangleBatch.CopyVertexData3f(vVerts); triangleBatch.CopyTexCoordData2f(vTexCoords, 0); triangleBatch.End(); texturedIdentity = gltLoadShaderPairWithAttributes("TexturedIdentity.vp", "TexturedIdentity.fp", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_TEXTURE0, "vTexCoords"); glGenTextures(1, &stoneTexture); glBindTexture(GL_TEXTURE_2D, stoneTexture); LoadTGATexture("Stone.tga", GL_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE); }
void setupRC() { expCounter = counterLoader(); //BG: glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //Enable depth testing so things won't look effed up: glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_SRC_COLOR); //Initialize stock shaders from GLTools: shaderManager.InitializeStockShaders(); //Move cam back: cameraFrame.MoveForward(-30.0f); cameraFrame.MoveRight(-5.0f); cameraFrame.MoveUp(-8.0f); newDeskButton.init(20, 80, 165, 70, "Assets/button_new_desk165x70.tga"); removeDeskButton.init(208, 80, 175, 67, "Assets/button_remove_desk175x67.tga"); exportButton.init(403, 80, 168, 67, "Assets/button_export168x67.tga"); M3DVector4f deskShine = {0.5, 0.5, 0.5, 1.0}; M3DVector4f deskColor = {0.0f, 0.0f, 0.5f, 1.0f}; hlGrid.init(0.0f, 0.0f, 0.0f, C_DM/2); cRoom.init(); stuDesks.init(deskColor, deskShine, C_DM/2); }
// This function does any needed initialization on the rendering // context. void SetupRC(void) { // Background glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); shaderManager.InitializeStockShaders(); viewFrame.MoveForward(4.0f); // Make the sphere gltMakeSphere(sphereBatch, 1.0f, 26, 13); ADSLightShader = shaderManager.LoadShaderPairWithAttributes("ADSGouraud.vp", "ADSGouraud.fp", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_NORMAL, "vNormal"); locAmbient = glGetUniformLocation(ADSLightShader, "ambientColor"); locDiffuse = glGetUniformLocation(ADSLightShader, "diffuseColor"); locSpecular = glGetUniformLocation(ADSLightShader, "specularColor"); locLight = glGetUniformLocation(ADSLightShader, "vLightPosition"); locMVP = glGetUniformLocation(ADSLightShader, "mvpMatrix"); locMV = glGetUniformLocation(ADSLightShader, "mvMatrix"); locNM = glGetUniformLocation(ADSLightShader, "normalMatrix"); }
// This function does any needed initialization on the rendering // context. void SetupRC(void) { // Background glClearColor(0.025f, 0.25f, 0.25f, 1.0f ); glEnable(GL_DEPTH_TEST); shaderManager.InitializeStockShaders(); viewFrame.MoveForward(4.0f); // Make the torus gltMakeTorus(torusBatch, .80f, 0.25f, 52, 26); toonShader = gltLoadShaderPairWithAttributes("ToonShader.vp", "ToonShader.fp", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_NORMAL, "vNormal"); locLight = glGetUniformLocation(toonShader, "vLightPosition"); locMVP = glGetUniformLocation(toonShader, "mvpMatrix"); locMV = glGetUniformLocation(toonShader, "mvMatrix"); locNM = glGetUniformLocation(toonShader, "normalMatrix"); locColorTable = glGetUniformLocation(toonShader, "colorTable"); glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_1D, texture); GLubyte textureData[4][3] = { 32, 0, 0, 64, 0, 0, 128, 0, 0, 255, 0, 0}; glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, 4, 0, GL_RGB, GL_UNSIGNED_BYTE, textureData); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); }
// This function does any needed initialization on the rendering context. void SetupRC(void) { // Background glClearColor(0.2f, 0.2f, 0.3f, 1.0f ); glEnable(GL_DEPTH_TEST); shaderManager.InitializeStockShaders(); viewFrame.MoveForward(4.0f); // Make the torus gltMakeTorus(torusBatch, .70f, 0.10f, 11, 7); explodeProgram = gltLoadShaderTripletWithAttributes("../../Data/Shaders/Chapter11/GSExplode.vs", "../../Data/Shaders/Chapter11/GSExplode.gs", "../../Data/Shaders/Chapter11/GSExplode.fs", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_NORMAL, "vNormal"); locMVP = glGetUniformLocation(explodeProgram, "mvpMatrix"); locMV = glGetUniformLocation(explodeProgram, "mvMatrix"); locNM = glGetUniformLocation(explodeProgram, "normalMatrix"); locPushOut = glGetUniformLocation(explodeProgram, "push_out"); }
// This function does any needed initialization on the rendering // context. void SetupRC(void) { // Background glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); glEnable(GL_DEPTH_TEST); shaderManager.InitializeStockShaders(); viewFrame.MoveForward(4.0f); // Make the torus gltMakeTorus(torusBatch, .80f, 0.25f, 52, 26); ADSDissloveShader = gltLoadShaderPairWithAttributes("Dissolve.vp", "Dissolve.fp", 3, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_NORMAL, "vNormal", GLT_ATTRIBUTE_TEXTURE0, "vTexCoords0"); locAmbient = glGetUniformLocation(ADSDissloveShader, "ambientColor"); locDiffuse = glGetUniformLocation(ADSDissloveShader, "diffuseColor"); locSpecular = glGetUniformLocation(ADSDissloveShader, "specularColor"); locLight = glGetUniformLocation(ADSDissloveShader, "vLightPosition"); locMVP = glGetUniformLocation(ADSDissloveShader, "mvpMatrix"); locMV = glGetUniformLocation(ADSDissloveShader, "mvMatrix"); locNM = glGetUniformLocation(ADSDissloveShader, "normalMatrix"); locTexture = glGetUniformLocation(ADSDissloveShader, "cloudTexture"); locDissolveFactor = glGetUniformLocation(ADSDissloveShader, "dissolveFactor"); glGenTextures(1, &cloudTexture); glBindTexture(GL_TEXTURE_1D, cloudTexture); LoadTGATexture("Clouds.tga", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE); }
void SpecialKeys(int key, int x, int y) { if(key == GLUT_KEY_F1) frameCamera.MoveForward(1.0f); if(key == GLUT_KEY_F2) frameCamera.MoveForward(-1.0f); if(key == GLUT_KEY_DOWN) frameCamera.RotateLocalX(0.01f); if(key == GLUT_KEY_UP) frameCamera.RotateLocalX(-0.01f); if(key == GLUT_KEY_LEFT) frameCamera.RotateLocalY(0.01f); if(key == GLUT_KEY_RIGHT) frameCamera.RotateLocalY(-0.01f); /*if(key == GLUT_KEY_UP) xRot-= 5.0f; if(key == GLUT_KEY_DOWN) xRot += 5.0f; if(key == GLUT_KEY_LEFT) yRot -= 5.0f; if(key == GLUT_KEY_RIGHT) yRot += 5.0f; if(key > 356.0f) xRot = 0.0f; if(key < -1.0f) xRot = 355.0f; if(key > 356.0f) yRot = 0.0f; if(key < -1.0f) yRot = 355.0f;*/ // Refresh the Window glutPostRedisplay(); }
void movingCylinder() { static CStopWatch cameraTimer; float fTime = cameraTimer.GetElapsedSeconds(); cameraTimer.Reset(); float linear = fTime * 3.0f; float angular = fTime * float(m3dDegToRad(15.0f)); if(isMoveForward == true) cameraFrame.MoveForward(linear); if(isMoveBack == true) cameraFrame.MoveForward(-linear); if(isRotateLeft == true) cameraFrame.RotateWorld(angular, 0.0f, 1.0f, 0.0f); if(isRotateRight == true) cameraFrame.RotateWorld(-angular, 0.0f, 1.0f, 0.0f); if(isRotateUp == true) cameraFrame.RotateWorld(angular, 1.0f, 0.0f, 0.0f); if(isRotateDown == true) cameraFrame.RotateWorld(-angular, 1.0f, 0.0f, 0.0f); }
// Respond to arrow keys by moving the camera frame of reference void SpecialKeys(int key, int x, int y) { if(key == GLUT_KEY_UP) viewFrame.MoveForward(0.1f); if(key == GLUT_KEY_DOWN) viewFrame.MoveForward(-0.1f); if(key == GLUT_KEY_LEFT) viewFrame.RotateLocalY(0.1); if(key == GLUT_KEY_RIGHT) viewFrame.RotateLocalY(-0.1); // Refresh the Window glutPostRedisplay(); }
void keyFunc(int key, int x, int y) { static const float step = 0.1f; static const float angle = m3dDegToRad(4); switch (key) { case GLUT_KEY_UP: objectFrame.RotateWorld(-angle, 1, 0, 0); break; case GLUT_KEY_DOWN: objectFrame.RotateWorld(angle, 1, 0, 0); break; case GLUT_KEY_LEFT: objectFrame.RotateWorld(-angle, 0, 1, 0); break; case GLUT_KEY_RIGHT: objectFrame.RotateWorld(angle, 0, 1, 0); break; case GLUT_KEY_HOME: cameraFrame.MoveForward(step); break; case GLUT_KEY_END: cameraFrame.MoveForward(-step); break; // enable/disable anisotropy case GLUT_KEY_F1: if (isAnisotropySupported) { isAnisotropy = !isAnisotropy; if (isAnisotropy) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, largest); else glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f); } break; default: break; } glutPostRedisplay(); }
////////////////////////////////////////////////////////////////// // This function does any needed initialization on the rendering // context. void SetupRC() { GLbyte *pBytes; GLint iWidth, iHeight, iComponents; GLenum eFormat; int i; // Cull backs of polygons glCullFace(GL_BACK); glFrontFace(GL_CCW); glEnable(GL_DEPTH_TEST); glGenTextures(1, &cubeTexture); glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTexture); // Set up texture maps glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // Load Cube Map images for(i = 0; i < 6; i++) { // Load this texture map pBytes = gltReadTGABits(szCubeFaces[i], &iWidth, &iHeight, &iComponents, &eFormat); glTexImage2D(cube[i], 0, iComponents, iWidth, iHeight, 0, eFormat, GL_UNSIGNED_BYTE, pBytes); free(pBytes); } glGenerateMipmap(GL_TEXTURE_CUBE_MAP); viewFrame.MoveForward(-4.0f); gltMakeSphere(sphereBatch, 1.0f, 52, 26); gltMakeCube(cubeBatch, 20.0f); reflectionShader = gltLoadShaderPairWithAttributes("Reflection.vp", "Reflection.fp", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_NORMAL, "vNormal"); locMVPReflect = glGetUniformLocation(reflectionShader, "mvpMatrix"); locMVReflect = glGetUniformLocation(reflectionShader, "mvMatrix"); locNormalReflect = glGetUniformLocation(reflectionShader, "normalMatrix"); locInvertedCamera = glGetUniformLocation(reflectionShader, "mInverseCamera"); skyBoxShader = gltLoadShaderPairWithAttributes("SkyBox.vp", "SkyBox.fp", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_NORMAL, "vNormal"); locMVPSkyBox = glGetUniformLocation(skyBoxShader, "mvpMatrix"); }
/////////////////////////////////////////////////////////////////////////////// // Update the camera based on user input, toggle display modes // void SpecialKeys(int key, int x, int y) { static CStopWatch cameraTimer; float fTime = cameraTimer.GetElapsedSeconds(); cameraTimer.Reset(); float linear = fTime * 0.60f; float angular = fTime * float(m3dDegToRad(60.0f)); if(key == GLUT_KEY_UP) cameraFrame.MoveForward(linear); if(key == GLUT_KEY_DOWN) cameraFrame.MoveForward(-linear); if(key == GLUT_KEY_LEFT) cameraFrame.RotateWorld(angular, 0.0f, 1.0f, 0.0f); if(key == GLUT_KEY_RIGHT) cameraFrame.RotateWorld(-angular, 0.0f, 1.0f, 0.0f); }
// This function does any needed initialization on the rendering // context. void SetupRC() { // Black background glClearColor(0.3f, 0.3f, 0.3f, 1.0f ); shaderManager.InitializeStockShaders(); viewFrame.MoveForward(7.0f); // Make the torus gltMakeTorus(torusBatch, 1.0f, 0.3f, 52, 26); glPointSize(4.0f); }
void handleInput(CStopWatch &inputTimer) { // Exit if (in.keyPressed(sf::Keyboard::Escape)) exit(0); // Camera movement float elapsedTime = inputTimer.GetElapsedSeconds() * 1.5f; inputTimer.Reset(); if (mouseActive) { if (in.keyPressed(sf::Keyboard::W)) cameraFrame.MoveForward(camSpeed*elapsedTime); if (in.keyPressed(sf::Keyboard::S)) cameraFrame.MoveForward(-camSpeed*elapsedTime); if (in.keyPressed(sf::Keyboard::A)) cameraFrame.MoveRight(camSpeed*elapsedTime); if (in.keyPressed(sf::Keyboard::D)) cameraFrame.MoveRight(-camSpeed*elapsedTime); if (in.keyPressed(sf::Keyboard::Space)) cameraFrame.MoveUp(camSpeed*elapsedTime); if (in.keyPressed(sf::Keyboard::LControl)) cameraFrame.MoveUp(-camSpeed*elapsedTime); } else { if (in.keyPressed(sf::Keyboard::W)) cameraFrame.MoveUp(camSpeed*elapsedTime); if (in.keyPressed(sf::Keyboard::S)) cameraFrame.MoveUp(-camSpeed*elapsedTime); if (in.keyPressed(sf::Keyboard::A)) cameraFrame.MoveRight(camSpeed*elapsedTime); if (in.keyPressed(sf::Keyboard::D)) cameraFrame.MoveRight(-camSpeed*elapsedTime); } }
/////////////////////////////////////////////////////////////////////////////// // This function does any needed initialization on the rendering context. // This is the first opportunity to do any OpenGL related tasks. void SetupRC() { // Black background glClearColor(0.7f, 0.7f, 0.7f, 1.0f ); shaderManager.InitializeStockShaders(); glEnable(GL_DEPTH_TEST); glGenTextures(1, &textureID); glBindTexture(GL_TEXTURE_2D, textureID); LoadTGATexture("stone.tga", GL_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE); MakePyramid(pyramidBatch); cameraFrame.MoveForward(-7.0f); }
void Init() { glClearColor(0.3,0.3,0.3,1.0); rTest.InitReader("Attack_Big_Center.FBX"); //init openGL functions glEnable(GL_TEXTURE_2D); // Enable Texture Mapping ( NEW ) glShadeModel(GL_SMOOTH); // Enable Smooth Shading glClearDepth(1.0f); // Depth Buffer Setup glEnable(GL_DEPTH_TEST); // Enables Depth Testing glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations //init as usual shaderManager.InitializeStockShaders(); //enable glEnable(GL_DEPTH_TEST); //move camera cameraFrame.MoveForward(-1000.0); //load texture fbxTexture = LoadBMPTexture("T_Sumo_Enemy_D.bmp"); }
void SetupRC() { glClearColor(0, 0, 0, 1); shaderManager.InitializeStockShaders(); glEnable(GL_DEPTH_TEST); gltMakeSphere(sphereBatch, 0.4, 20, 20); gltMakeCube(cubeBatch, 0.3); // Load up a triangle GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f }; GLfloat vColors [] = { 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f }; triangleBatch.Begin(GL_TRIANGLES, 3); triangleBatch.CopyVertexData3f(vVerts); triangleBatch.CopyColorData4f(vColors); triangleBatch.End(); mWcgCube.SetupCube(); /*transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix);*/ cameraFrame.MoveForward(-3.0f); m3dLoadIdentity44(mRotation); myShader = gltLoadShaderPairWithAttributes("shader.vp", "shader.fp", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_COLOR, "vColor"); locMVP = glGetUniformLocation(myShader, "mvpMatrix"); }
void SetupRC() { glClearColor(0.7f, 0.7f, 0.7f, 1.0f ); shaderManager.InitializeStockShaders(); glEnable(GL_DEPTH_TEST); transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix); cameraFrame.MoveForward(-15.0f); // 一组图元顶点——长得像佛罗里达州 GLfloat vCoast[24][3] = { {2.80, 1.20, 0.0 }, {2.0, 1.20, 0.0 }, {2.0, 1.08, 0.0 }, {2.0, 1.08, 0.0 }, {0.0, 0.80, 0.0 }, {-.32, 0.40, 0.0 }, {-.48, 0.2, 0.0 }, {-.40, 0.0, 0.0 }, {-.60, -.40, 0.0 }, {-.80, -.80, 0.0 }, {-.80, -1.4, 0.0 }, {-.40, -1.60, 0.0 }, {0.0, -1.20, 0.0 }, { .2, -.80, 0.0 }, {.48, -.40, 0.0 }, {.52, -.20, 0.0 }, {.48, .20, 0.0 }, {.80, .40, 0.0 }, {1.20, .80, 0.0 }, {1.60, .60, 0.0 }, {2.0, .60, 0.0 }, {2.2, .80, 0.0 }, {2.40, 1.0, 0.0 }, {2.80, 1.0, 0.0 } }; // 点批次 pointBatch.Begin(GL_POINTS, 24); pointBatch.CopyVertexData3f(vCoast); pointBatch.End(); // 线段批次 lineBatch.Begin(GL_LINES, 24); lineBatch.CopyVertexData3f(vCoast); lineBatch.End(); // 线批次 lineStripBatch.Begin(GL_LINE_STRIP, 24); lineStripBatch.CopyVertexData3f(vCoast); lineStripBatch.End(); // 循环线批次 lineLoopBatch.Begin(GL_LINE_LOOP, 24); lineLoopBatch.CopyVertexData3f(vCoast); lineLoopBatch.End(); GLfloat vPyramid[12][3] = { -2.0f, 0.0f, -2.0f, 2.0f, 0.0f, -2.0f, 0.0f, 4.0f, 0.0f, 2.0f, 0.0f, -2.0f, 2.0f, 0.0f, 2.0f, 0.0f, 4.0f, 0.0f, 2.0f, 0.0f, 2.0f, -2.0f, 0.0f, 2.0f, 0.0f, 4.0f, 0.0f, -2.0f, 0.0f, 2.0f, -2.0f, 0.0f, -2.0f, 0.0f, 4.0f, 0.0f }; triangleBatch.Begin(GL_TRIANGLES, 12); triangleBatch.CopyVertexData3f(vPyramid); triangleBatch.End(); GLfloat vPoints[100][3]; int nVerts = 0; GLfloat r = 3.0f; vPoints[nVerts][0] = 0.0f; vPoints[nVerts][1] = 0.0f; vPoints[nVerts][2] = 0.0f; for(GLfloat angle = 0; angle < M3D_2PI; angle += M3D_2PI / 6.0f) { nVerts++; vPoints[nVerts][0] = float(cos(angle)) * r; vPoints[nVerts][1] = float(sin(angle)) * r; vPoints[nVerts][2] = -0.5f; } nVerts++; vPoints[nVerts][0] = r; vPoints[nVerts][1] = 0; vPoints[nVerts][2] = 0.0f; triangleFanBatch.Begin(GL_TRIANGLE_FAN, 8); triangleFanBatch.CopyVertexData3f(vPoints); triangleFanBatch.End(); int iCounter = 0; GLfloat radius = 3.0f; for(GLfloat angle = 0.0f; angle <= (2.0f * M3D_PI); angle += 0.3f) { GLfloat x = radius * sin(angle); GLfloat y = radius * cos(angle); vPoints[iCounter][0] = x; vPoints[iCounter][1] = y; vPoints[iCounter][2] = -0.5; iCounter++; vPoints[iCounter][0] = x; vPoints[iCounter][1] = y; vPoints[iCounter][2] = 0.5; iCounter++; } vPoints[iCounter][0] = vPoints[0][0]; vPoints[iCounter][1] = vPoints[0][1]; vPoints[iCounter][2] = -0.5; iCounter++; vPoints[iCounter][0] = vPoints[1][0]; vPoints[iCounter][1] = vPoints[1][1]; vPoints[iCounter][2] = 0.5; iCounter++; triangleStripBatch.Begin(GL_TRIANGLE_STRIP, iCounter); triangleStripBatch.CopyVertexData3f(vPoints); triangleStripBatch.End(); }
// This function does any needed initialization on the rendering // context. void SetupRC(void) { // Background glClearColor(0.2f, 0.2f, 0.3f, 1.0f ); glEnable(GL_DEPTH_TEST); shaderManager.InitializeStockShaders(); viewFrame.MoveForward(4.0f); // Make the torus gltMakeTorus(torusBatch, .70f, 0.10f, 11, 7); gltMakeCube(cubeBatch, 1.0f); toonShader = gltLoadShaderTripletWithAttributes("GSTessellate.vs", "GSTessellate.gs", "GSTessellate.fs", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_NORMAL, "vNormal"); locMVP = glGetUniformLocation(toonShader, "mvpMatrix"); locMV = glGetUniformLocation(toonShader, "mvMatrix"); locNM = glGetUniformLocation(toonShader, "normalMatrix"); static const GLfloat vertices[] = { -1.0f, -1.0f, -1.0f, // A -1.0f, -1.0f, 1.0f, // B -1.0f, 1.0f, -1.0f, // C -1.0f, 1.0f, 1.0f, // D 1.0f, -1.0f, -1.0f, // E 1.0f, -1.0f, 1.0f, // F 1.0f, 1.0f, -1.0f, // G 1.0f, 1.0f, 1.0f // H }; static const GLshort indices[] = { 0, 1, 2, 3, 2, 1, 1, 5, 3, 7, 3, 5, 5, 4, 7, 6, 7, 4, 4, 0, 6, 2, 6, 0, 4, 5, 0, 1, 0, 5, 3, 7, 2, 6, 2, 7 }; glGenVertexArrays(1, &vao); glBindVertexArray(vao); glGenBuffers(1, &vertex_buffer); glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL); glEnableVertexAttribArray(0); glGenBuffers(1, &element_buffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, element_buffer); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); GLenum e = glGetError(); }
/////////////////////////////////////////////////////////////////////////////// // Update the camera based on user input, toggle display modes // void SpecialKeys(int key, int x, int y) { static CStopWatch cameraTimer; float fTime = cameraTimer.GetElapsedSeconds(); cameraTimer.Reset(); float linear = fTime * 3.0f; float angular = fTime * float(m3dDegToRad(60.0f)); if(key == GLUT_KEY_UP) cameraFrame.MoveForward(linear); if(key == GLUT_KEY_DOWN) cameraFrame.MoveForward(-linear); if(key == GLUT_KEY_LEFT) cameraFrame.RotateWorld(angular, 0.0f, 1.0f, 0.0f); if(key == GLUT_KEY_RIGHT) cameraFrame.RotateWorld(-angular, 0.0f, 1.0f, 0.0f); static bool bF2IsDown = false; if(key == GLUT_KEY_F2) { if(bF2IsDown == false) { bF2IsDown = true; bUseFBO = !bUseFBO; } } else { bF2IsDown = false; } #ifndef OPENGL_ES if(key == GLUT_KEY_F3) { glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_BUFFER_ARB, texBOTexture); glTexBufferARB(GL_TEXTURE_BUFFER_ARB, GL_R32F, texBO[0]); // FIX THIS IN GLEE glActiveTexture(GL_TEXTURE0); } else if(key == GLUT_KEY_F4) { glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_BUFFER_ARB, texBOTexture); glTexBufferARB(GL_TEXTURE_BUFFER_ARB, GL_R32F, texBO[1]); // FIX THIS IN GLEE glActiveTexture(GL_TEXTURE0); } else if(key == GLUT_KEY_F5) { glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_BUFFER_ARB, texBOTexture); glTexBufferARB(GL_TEXTURE_BUFFER_ARB, GL_R32F, texBO[2]); // FIX THIS IN GLEE glActiveTexture(GL_TEXTURE0); } #endif // Refresh the Window glutPostRedisplay(); }
// This function does any needed initialization on the rendering // context. void SetupRC(void) { // Background glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); glEnable(GL_DEPTH_TEST); viewFrame.MoveForward(-155.0f); viewFrame.MoveUp(20.0f); grassShader = gltLoadShaderPairWithAttributes("Grass.vs", "Grass.fs", 1, GLT_ATTRIBUTE_VERTEX, "vVertex"); locMVP = glGetUniformLocation(grassShader, "mvpMatrix"); glUseProgram(grassShader); glUniform1i(glGetUniformLocation(grassShader, "length_texture"), 0); glUniform1i(glGetUniformLocation(grassShader, "orientation_texture"), 1); glUniform1i(glGetUniformLocation(grassShader, "grasspalette_texture"), 2); glUniform1i(glGetUniformLocation(grassShader, "grasscolor_texture"), 3); glUniform1i(glGetUniformLocation(grassShader, "bend_texture"), 4); static const GLfloat grass_blade[] = { -0.3f, 0.0f, 0.3f, 0.0f, -0.20f, 1.0f, 0.1f, 1.3f, -0.05f, 2.3f, 0.0f, 3.3f }; // Greate a vertex array object and a vertex buffer for the quad // including position and texture coordinates glGenVertexArrays(1, &vao); glBindVertexArray(vao); glGenBuffers(1, &vertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(grass_blade), grass_blade, GL_STATIC_DRAW); glVertexAttribPointer(GLT_ATTRIBUTE_VERTEX, 2, GL_FLOAT, GL_FALSE, 0, NULL); glEnableVertexAttribArray(GLT_ATTRIBUTE_VERTEX); // glGenTextures(1, &length_texture); glBindTexture(GL_TEXTURE_2D, length_texture); GLint w, h, c; GLenum f; void * bits = gltReadTGABits("length.tga", &w, &h, &c, &f); glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, w, h, 0, GL_BGR, GL_UNSIGNED_BYTE, bits); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); free(bits); glGenTextures(1, &orientation_texture); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, orientation_texture); bits = gltReadTGABits("orientation.tga", &w, &h, &c, &f); glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, w, h, 0, GL_BGR, GL_UNSIGNED_BYTE, bits); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); free(bits); glGenTextures(1, &grasspalette_texture); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_1D, grasspalette_texture); glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB8, 1024, 0, GL_RGB, GL_UNSIGNED_BYTE, grasspalette_data); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glGenTextures(1, &grasscolor_texture); glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, grasscolor_texture); bits = gltReadTGABits("color.tga", &w, &h, &c, &f); glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, w, h, 0, GL_BGR, GL_UNSIGNED_BYTE, bits); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); free(bits); glGenTextures(1, &bend_texture); glActiveTexture(GL_TEXTURE4); glBindTexture(GL_TEXTURE_2D, bend_texture); bits = gltReadTGABits("bend.tga", &w, &h, &c, &f); glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, w, h, 0, GL_BGR, GL_UNSIGNED_BYTE, bits); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); free(bits); }
/////////////////////////////////////////////////////////////////////////////// // This function does any needed initialization on the rendering context. // This is the first opportunity to do any OpenGL related tasks. void SetupRC() { GLbyte *pBytes; GLint nWidth, nHeight, nComponents; GLenum format; shaderManager.InitializeStockShaders(); // Black background glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); glEnable(GL_DEPTH_TEST); glLineWidth(2.5f); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix); cameraFrame.MoveForward(-15.0f); cameraFrame.MoveUp(6.0f); cameraFrame.RotateLocalX(float(m3dDegToRad(20.0f))); MakeCube(cubeBatch); MakeFloor(floorBatch); // Make top topBlock.Begin(GL_TRIANGLE_FAN, 4, 1); topBlock.Normal3f(0.0f, 1.0f, 0.0f); topBlock.MultiTexCoord2f(0, 0.0f, 0.0f); topBlock.Vertex3f(-1.0f, 1.0f, 1.0f); topBlock.Normal3f(0.0f, 1.0f, 0.0f); topBlock.MultiTexCoord2f(0, 1.0f, 0.0f); topBlock.Vertex3f(1.0f, 1.0f, 1.0f); topBlock.Normal3f(0.0f, 1.0f, 0.0f); topBlock.MultiTexCoord2f(0, 1.0f, 1.0f); topBlock.Vertex3f(1.0f, 1.0f, -1.0f); topBlock.Normal3f(0.0f, 1.0f, 0.0f); topBlock.MultiTexCoord2f(0, 0.0f, 1.0f); topBlock.Vertex3f(-1.0f, 1.0f, -1.0f); topBlock.End(); // Make Front frontBlock.Begin(GL_TRIANGLE_FAN, 4, 1); frontBlock.Normal3f(0.0f, 0.0f, 1.0f); frontBlock.MultiTexCoord2f(0, 0.0f, 0.0f); frontBlock.Vertex3f(-1.0f, -1.0f, 1.0f); frontBlock.Normal3f(0.0f, 0.0f, 1.0f); frontBlock.MultiTexCoord2f(0, 1.0f, 0.0f); frontBlock.Vertex3f(1.0f, -1.0f, 1.0f); frontBlock.Normal3f(0.0f, 0.0f, 1.0f); frontBlock.MultiTexCoord2f(0, 1.0f, 1.0f); frontBlock.Vertex3f(1.0f, 1.0f, 1.0f); frontBlock.Normal3f(0.0f, 0.0f, 1.0f); frontBlock.MultiTexCoord2f(0, 0.0f, 1.0f); frontBlock.Vertex3f(-1.0f, 1.0f, 1.0f); frontBlock.End(); // Make left leftBlock.Begin(GL_TRIANGLE_FAN, 4, 1); leftBlock.Normal3f(-1.0f, 0.0f, 0.0f); leftBlock.MultiTexCoord2f(0, 0.0f, 0.0f); leftBlock.Vertex3f(-1.0f, -1.0f, -1.0f); leftBlock.Normal3f(-1.0f, 0.0f, 0.0f); leftBlock.MultiTexCoord2f(0, 1.0f, 0.0f); leftBlock.Vertex3f(-1.0f, -1.0f, 1.0f); leftBlock.Normal3f(-1.0f, 0.0f, 0.0f); leftBlock.MultiTexCoord2f(0, 1.0f, 1.0f); leftBlock.Vertex3f(-1.0f, 1.0f, 1.0f); leftBlock.Normal3f(-1.0f, 0.0f, 0.0f); leftBlock.MultiTexCoord2f(0, 0.0f, 1.0f); leftBlock.Vertex3f(-1.0f, 1.0f, -1.0f); leftBlock.End(); // Create shadow projection matrix GLfloat floorPlane[] = { 0.0f, 1.0f, 0.0f, 1.0f}; m3dMakePlanarShadowMatrix(shadowMatrix, floorPlane, vLightPos); // Load up four textures glGenTextures(4, textures); // Wood floor pBytes = gltReadTGABits("floor.tga", &nWidth, &nHeight, &nComponents, &format); glBindTexture(GL_TEXTURE_2D, textures[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0, format, GL_UNSIGNED_BYTE, pBytes); free(pBytes); // One of the block faces pBytes = gltReadTGABits("Block4.tga", &nWidth, &nHeight, &nComponents, &format); glBindTexture(GL_TEXTURE_2D, textures[1]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0, format, GL_UNSIGNED_BYTE, pBytes); free(pBytes); // Another block face pBytes = gltReadTGABits("block5.tga", &nWidth, &nHeight, &nComponents, &format); glBindTexture(GL_TEXTURE_2D, textures[2]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0, format, GL_UNSIGNED_BYTE, pBytes); free(pBytes); // Yet another block face pBytes = gltReadTGABits("block6.tga", &nWidth, &nHeight, &nComponents, &format); glBindTexture(GL_TEXTURE_2D, textures[3]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0, format, GL_UNSIGNED_BYTE, pBytes); free(pBytes); }
/////////////////////////////////////////////////////////////////////////////// // This function does any needed initialization on the rendering context. // This is the first opportunity to do any OpenGL related tasks. void SetupRC() { // Black background glClearColor(0.7f, 0.7f, 0.7f, 1.0f ); shaderManager.InitializeStockShaders(); glEnable(GL_DEPTH_TEST); transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix); cameraFrame.MoveForward(-15.0f); ////////////////////////////////////////////////////////////////////// // Some points, more or less in the shape of Florida GLfloat vCoast[24][3] = {{2.80, 1.20, 0.0 }, {2.0, 1.20, 0.0 }, {2.0, 1.08, 0.0 }, {2.0, 1.08, 0.0 }, {0.0, 0.80, 0.0 }, {-.32, 0.40, 0.0 }, {-.48, 0.2, 0.0 }, {-.40, 0.0, 0.0 }, {-.60, -.40, 0.0 }, {-.80, -.80, 0.0 }, {-.80, -1.4, 0.0 }, {-.40, -1.60, 0.0 }, {0.0, -1.20, 0.0 }, { .2, -.80, 0.0 }, {.48, -.40, 0.0 }, {.52, -.20, 0.0 }, {.48, .20, 0.0 }, {.80, .40, 0.0 }, {1.20, .80, 0.0 }, {1.60, .60, 0.0 }, {2.0, .60, 0.0 }, {2.2, .80, 0.0 }, {2.40, 1.0, 0.0 }, {2.80, 1.0, 0.0 }}; // Load point batch pointBatch.Begin(GL_POINTS, 24); pointBatch.CopyVertexData3f(vCoast); pointBatch.End(); // Load as a bunch of line segments lineBatch.Begin(GL_LINES, 24); lineBatch.CopyVertexData3f(vCoast); lineBatch.End(); // Load as a single line segment lineStripBatch.Begin(GL_LINE_STRIP, 24); lineStripBatch.CopyVertexData3f(vCoast); lineStripBatch.End(); // Single line, connect first and last points lineLoopBatch.Begin(GL_LINE_LOOP, 24); lineLoopBatch.CopyVertexData3f(vCoast); lineLoopBatch.End(); // For Triangles, we'll make a Pyramid GLfloat vPyramid[12][3] = { -2.0f, 0.0f, -2.0f, 2.0f, 0.0f, -2.0f, 0.0f, 4.0f, 0.0f, 2.0f, 0.0f, -2.0f, 2.0f, 0.0f, 2.0f, 0.0f, 4.0f, 0.0f, 2.0f, 0.0f, 2.0f, -2.0f, 0.0f, 2.0f, 0.0f, 4.0f, 0.0f, -2.0f, 0.0f, 2.0f, -2.0f, 0.0f, -2.0f, 0.0f, 4.0f, 0.0f}; triangleBatch.Begin(GL_TRIANGLES, 12); triangleBatch.CopyVertexData3f(vPyramid); triangleBatch.End(); // For a Triangle fan, just a 6 sided hex. Raise the center up a bit GLfloat vPoints[100][3]; // Scratch array, more than we need int nVerts = 0; GLfloat r = 3.0f; vPoints[nVerts][0] = 0.0f; vPoints[nVerts][1] = 0.0f; vPoints[nVerts][2] = 0.0f; for(GLfloat angle = 0; angle < M3D_2PI; angle += M3D_2PI / 6.0f) { nVerts++; vPoints[nVerts][0] = float(cos(angle)) * r; vPoints[nVerts][1] = float(sin(angle)) * r; vPoints[nVerts][2] = -0.5f; } // Close the fan nVerts++; vPoints[nVerts][0] = r; vPoints[nVerts][1] = 0; vPoints[nVerts][2] = 0.0f; // Load it up triangleFanBatch.Begin(GL_TRIANGLE_FAN, 8); triangleFanBatch.CopyVertexData3f(vPoints); triangleFanBatch.End(); // For triangle strips, a little ring or cylinder segment int iCounter = 0; GLfloat radius = 3.0f; for(GLfloat angle = 0.0f; angle <= (2.0f*M3D_PI); angle += 0.3f) { GLfloat x = radius * sin(angle); GLfloat y = radius * cos(angle); // Specify the point and move the Z value up a little vPoints[iCounter][0] = x; vPoints[iCounter][1] = y; vPoints[iCounter][2] = -0.5; iCounter++; vPoints[iCounter][0] = x; vPoints[iCounter][1] = y; vPoints[iCounter][2] = 0.5; iCounter++; } // Close up the loop vPoints[iCounter][0] = vPoints[0][0]; vPoints[iCounter][1] = vPoints[0][1]; vPoints[iCounter][2] = -0.5; iCounter++; vPoints[iCounter][0] = vPoints[1][0]; vPoints[iCounter][1] = vPoints[1][1]; vPoints[iCounter][2] = 0.5; iCounter++; // Load the triangle strip triangleStripBatch.Begin(GL_TRIANGLE_STRIP, iCounter); triangleStripBatch.CopyVertexData3f(vPoints); triangleStripBatch.End(); }
///////////////////////////////////////////////////////////////// // Window procedure, handles all messages for this program LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static HGLRC hRC; // Permenant Rendering context static HDC hDC; // Private GDI Device context switch (message) { // Window creation, setup for OpenGL case WM_CREATE: // Store the device context hDC = GetDC(hWnd); // The screen and desktop may have changed, so do this again FindBestPF(hDC, &startupOptions.nPixelFormat, &startupOptions.nPixelFormatMS); // Set pixelformat if(startupOptions.bFSAA == TRUE && (startupOptions.nPixelFormatMS != 0)) SetPixelFormat(hDC, startupOptions.nPixelFormatMS, NULL); else SetPixelFormat(hDC, startupOptions.nPixelFormat, NULL); // Create the rendering context and make it current hRC = wglCreateContext(hDC); wglMakeCurrent(hDC, hRC); SetupRC(hDC); break; // Check for ESC key case WM_CHAR: if(wParam == 27) DestroyWindow(hWnd); break; // Window is either full screen, or not visible case WM_ACTIVATE: { // Ignore this altogether unless we are in full screen mode if(startupOptions.bFullScreen == TRUE) { // Construct windowplacement structure WINDOWPLACEMENT wndPlacement; wndPlacement.length = sizeof(WINDOWPLACEMENT); wndPlacement.flags = WPF_RESTORETOMAXIMIZED; wndPlacement.ptMaxPosition.x = 0; wndPlacement.ptMaxPosition.y = 0; wndPlacement.ptMinPosition.x = 0; wndPlacement.ptMinPosition.y = 0; wndPlacement.rcNormalPosition.bottom = startupOptions.devMode.dmPelsHeight; wndPlacement.rcNormalPosition.left = 0; wndPlacement.rcNormalPosition.top = 0; wndPlacement.rcNormalPosition.right = startupOptions.devMode.dmPelsWidth; // Switching away from window if(LOWORD(wParam) == WA_INACTIVE) { wndPlacement.showCmd = SW_SHOWMINNOACTIVE; SetWindowPlacement(hWnd, &wndPlacement); ShowCursor(TRUE); } else // Switching back to window { wndPlacement.showCmd = SW_RESTORE; SetWindowPlacement(hWnd, &wndPlacement); ShowCursor(FALSE); } } } break; // Window is being destroyed, cleanup case WM_DESTROY: // Kill the timer that we created KillTimer(hWnd,101); ShutdownRC(); // Deselect the current rendering context and delete it wglMakeCurrent(hDC,NULL); wglDeleteContext(hRC); // Tell the application to terminate after the window // is gone. PostQuitMessage(0); break; // Window is resized. case WM_SIZE: // Call our function which modifies the clipping // volume and viewport ChangeSize(LOWORD(lParam), HIWORD(lParam)); break; // The painting function. This message sent by Windows // whenever the screen needs updating. case WM_PAINT: { // Only poll keyboard when this window has focus if(GetFocus() == hWnd) { float fTime; float fLinear, fAngular; // Get the time since the last time we rendered a frame LARGE_INTEGER lCurrent; QueryPerformanceCounter(&lCurrent); fTime = (float)(lCurrent.QuadPart - CameraTimer.QuadPart) / (float)CounterFrequency.QuadPart; CameraTimer = lCurrent; // Camera motion will be time based. This keeps the motion constant // regardless of frame rate. Higher frame rates produce smoother // animation and motion, they should not produce "faster" motion. fLinear = fTime * 1.0f; fAngular = (float)m3dDegToRad(60.0f * fTime); // Move the camera around, poll the keyboard if(GetAsyncKeyState(VK_UP)) frameCamera.MoveForward(fLinear); if(GetAsyncKeyState(VK_DOWN)) frameCamera.MoveForward(-fLinear); if(GetAsyncKeyState(VK_LEFT)) frameCamera.MoveForward(fAngular); if(GetAsyncKeyState(VK_RIGHT)) frameCamera.MoveForward(-fAngular); } // Call OpenGL drawing code RenderScene(); // Call function to swap the buffers SwapBuffers(hDC); // Not validated on purpose, gives and endless series // of paint messages... this is akin to having // a rendering loop //ValidateRect(hWnd,NULL); } break; default: // Passes it on if unproccessed return (DefWindowProc(hWnd, message, wParam, lParam)); } return (0L); }
// main rendering loop void RenderScene(void){ static CStopWatch rotTimer; float yRot = rotTimer.GetElapsedSeconds() * 60.0f; GLfloat vBarColor[] = {1.0f, 0.0f, 0.0f, 1.0f}; currentFrame = getLatestBufferIndex(); if(mapper.getSimpleArg('c')){ vBarColor[0] = .7; vBarColor[1] = .2 + sharedBuffer[currentFrame].averageAmp * 60; vBarColor[2] = 1.0; b = sharedBuffer[currentFrame].averageAmp; g = 0; r = 0; glClearColor(r, g, b, 1.0f); } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); modelViewMatrix.PushMatrix(); M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); modelViewMatrix.PushMatrix(mCamera); if(mapper.getCompoundArg('r') == "auto"){ cameraFrame.RotateWorld(.01, 0.0, 0.0, 1.0); cameraFrame.MoveForward(-.1 * sin(yRot * .05)); } // set up light source M3DVector4f vLightPos = { 0.0f, 10.0f, 5.0f, 1.0f }; M3DVector4f vLightEyePos; m3dTransformVector4(vLightEyePos, vLightPos, mCamera); for(int m = 0; m < NUM_MACROS; m++){ if(mapper.getSimpleArg('m')){ modelViewMatrix.PushMatrix(); macros[m].refFrame.RotateLocalY(.01 * macros[m].multiplier); macros[m].refFrame.RotateLocalX(.5 * sharedBuffer[currentFrame].averageAmp); modelViewMatrix.MultMatrix(macros[m].refFrame); } for(int i = 0; i < PACKET_SIZE; i++){ modelViewMatrix.PushMatrix(); GLfloat y = 5 * fabs(sharedBuffer[currentFrame].frames[i][0]); modelViewMatrix.MultMatrix(bars[i]); modelViewMatrix.Scale(barWidth, y, sharedBuffer[currentFrame].averageAmp * 4); if(mapper.getSimpleArg('t')){ modelViewMatrix.Translate(0.0, sharedBuffer[currentFrame].averageAmp, 0.0); } shaderManager.UseStockShader(GLT_SHADER_POINT_LIGHT_DIFF, transformPipeline.GetModelViewMatrix(), transformPipeline.GetProjectionMatrix(), vLightEyePos, vBarColor); cubeBatch.Draw(); modelViewMatrix.PopMatrix(); } if(mapper.getSimpleArg('m')){ modelViewMatrix.PopMatrix(); } } // draw prisms for amplitudes modelViewMatrix.PopMatrix(); modelViewMatrix.PopMatrix(); modelViewMatrix.PopMatrix(); glutSwapBuffers(); glutPostRedisplay(); if(currentFrame != -1){ sharedBuffer[currentFrame].free = true; } }