// Callback function called by GLUT to render sub-window content void DisplaySubWindow(void) { float v[4]; // will be used to set light parameters float mat[4*4]; // rotation matrix SubWindowData *win; win = GetCurrentSubWindowData(); if (win == NULL) return; // Tell AntTweakBar which is the current window TwSetCurrentWindow(win->WinID); // Clear frame buffer glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glEnable(GL_NORMALIZE); // Set light glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); v[0] = v[1] = v[2] = win->LightMultiplier*0.4f; v[3] = 1.0f; glLightfv(GL_LIGHT0, GL_AMBIENT, v); v[0] = v[1] = v[2] = win->LightMultiplier*0.8f; v[3] = 1.0f; glLightfv(GL_LIGHT0, GL_DIFFUSE, v); v[0] = -win->LightDirection[0]; v[1] = -win->LightDirection[1]; v[2] = -win->LightDirection[2]; v[3] = 0.0f; glLightfv(GL_LIGHT0, GL_POSITION, v); // Set material glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, win->MatAmbient); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, win->MatDiffuse); // Rotate and draw shape glPushMatrix(); glTranslatef(0.5f, -0.3f, 0.0f); if( win->AutoRotate ) { float axis[3] = { 0, 1, 0 }; float angle = (float)(GetTimeMs()-win->RotateTime)/1000.0f; float quat[4]; SetQuaternionFromAxisAngle(axis, angle, quat); MultiplyQuaternions(win->RotateStart, quat, win->Rotation); } ConvertQuaternionToMatrix(win->Rotation, mat); glMultMatrixf(mat); glScalef(win->Zoom, win->Zoom, win->Zoom); glCallList(win->ObjectShape); glPopMatrix(); // Draw tweak bars TwDraw(); // Present frame buffer glutSwapBuffers(); // Recall Display at next frame glutPostRedisplay(); }
void RenderScene() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); #if FIX_FUNCTION glLightfv(GL_LIGHT0, GL_POSITION, g_lightPos); #else if (lightPosLocation1 != -1) { //glUniformMatrix4fv(lightPosLocation, 1, GL_FALSE, lightPos); glUniform3fv(lightPosLocation1, 1, g_lightPos); } #endif glMatrixMode(GL_MODELVIEW); glPushMatrix(); gluLookAt(0.0, 0.0, 20.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glTranslatef(0.0f, 0.0f, -50.0f); float mat[4*4]; ConvertQuaternionToMatrix(g_Rotate, mat); /*float invmat[4*4]; m3dInvertMatrix44(invmat, mat); if (lightPosLocation != -1) { glUniformMatrix4fv(lightPosLocation, 1, GL_FALSE, mat); }*/ glMultMatrixf(mat); DrawGround(); DrawObjects(); glPopMatrix(); TwDraw(); glutSwapBuffers(); glutPostRedisplay(); }
std::vector<double> randomshift_on_sphere(const std::vector<double> &insamples, int num_pts){ std::vector<double> output(3*num_pts, 0.0); //Find two random vectors on the sphere double rx=0,ry=0,rz=0; uniformSampleSphere(drand48(), drand48(), &rx, &ry, &rz); double temp1[] = {rx, ry, rz}; uniformSampleSphere(drand48(), drand48(), &rx, &ry, &rz); double temp2[] = {rx, ry, rz}; //Compute a quaternion from these vectors double quat[] = {0,0,0,1}; QuaternionFromTwoVectors(temp1, temp2, quat); //Use the above quaternion to rotate all samples. for(int b = 0; b < num_pts; b++){ double qmat[16], qvout[4]; double qvec[] = {insamples[3*b+0], insamples[3*b+1], insamples[3*b+2],1}; ConvertQuaternionToMatrix(quat, qmat); MultiplyVecMat(qmat, qvec, qvout); //rotated samples are here output[3*b+0] = (qvout[0]); output[3*b+1] = (qvout[1]); output[3*b+2] = (qvout[2]); } return output; }
// Callback function called by GLUT to render screen void Display(void) { float v[4]; // will be used to set light paramters float mat[4*4]; // rotation matrix // Clear frame buffer glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glEnable(GL_NORMALIZE); // Set light glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); v[0] = v[1] = v[2] = g_LightMultiplier*0.4f; v[3] = 1.0f; glLightfv(GL_LIGHT0, GL_AMBIENT, v); v[0] = v[1] = v[2] = g_LightMultiplier*0.8f; v[3] = 1.0f; glLightfv(GL_LIGHT0, GL_DIFFUSE, v); v[0] = -g_LightDirection[0]; v[1] = -g_LightDirection[1]; v[2] = -g_LightDirection[2]; v[3] = 0.0f; glLightfv(GL_LIGHT0, GL_POSITION, v); // Set material glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, g_MatAmbient); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, g_MatDiffuse); // Rotate and draw shape glPushMatrix(); glTranslatef(0.5f, -0.3f, 0.0f); if( g_AutoRotate ) { float axis[3] = { 0, 1, 0 }; float angle = (float)(glutGet(GLUT_ELAPSED_TIME)-g_RotateTime)/1000.0f; float quat[4]; SetQuaternionFromAxisAngle(axis, angle, quat); MultiplyQuaternions(g_RotateStart, quat, g_Rotation); } ConvertQuaternionToMatrix(g_Rotation, mat); glMultMatrixf(mat); glScalef(g_Zoom, g_Zoom, g_Zoom); glCallList(g_CurrentShape); glPopMatrix(); // Draw tweak bars TwDraw(); // Present frame buffer glutSwapBuffers(); // Recall Display at next frame glutPostRedisplay(); }
//-------------------------------------------------------------- void testApp::draw(){ float v[4]; // will be used to set light paramters float mat[4*4]; // rotation matrix // Clear frame buffer glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glEnable(GL_NORMALIZE); // Set light glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); v[0] = v[1] = v[2] = g_LightMultiplier*0.4f; v[3] = 1.0f; glLightfv(GL_LIGHT0, GL_AMBIENT, v); v[0] = v[1] = v[2] = g_LightMultiplier*0.8f; v[3] = 1.0f; glLightfv(GL_LIGHT0, GL_DIFFUSE, v); v[0] = -g_LightDirection.x; v[1] = -g_LightDirection.y; v[2] = -g_LightDirection.z; v[3] = 0.0f; glLightfv(GL_LIGHT0, GL_POSITION, v); // Set material glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, g_MatAmbient); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, g_MatDiffuse); // Rotate and draw shape glPushMatrix(); //glTranslatef(0.5f, -0.3f, 0.0f); glTranslatef(ofGetWidth()/2, ofGetHeight()/2, 0.0f); ConvertQuaternionToMatrix(g_Rotation, mat); glMultMatrixf(mat); glScalef(g_Zoom, g_Zoom, g_Zoom); glCallList(g_CurrentShape); glPopMatrix(); //TWEAK BAR bar.draw(); }
int main (int argc, const char * argv[]) { TwBar *myBar; float bgColor[] = { 0.0f, 0.0f, 0.0f, 0.1f }; glm::mat4 mat; float axis[] = { 0.7f, 0.7f, 0.7f }; // initial model rotation float angle = 0.8f; double FT = 0; double FPS = 0; double starting = 0.0; double ending = 0.0; int rate = 0; int fr = 0; zNear = 0.1f; zFar = 100.0f; FOV = 45.0f; // Current time double time = 0; // initialise GLFW int running = GL_TRUE; if (!glfwInit()) { exit(EXIT_FAILURE); } //only for OpenGL 2.1 #ifdef USE_OPENGL21 glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 2); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 1); #endif //Only for OpenGL 3.2 #ifdef USE_OPENGL32 glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwOpenWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, 1); #endif GLFWvidmode mode; glfwGetDesktopMode(&mode); if( !glfwOpenWindow(windowWidth, windowHeight, mode.RedBits, mode.GreenBits, mode.BlueBits, 0, 32, 0, GLFW_WINDOW /* or GLFW_FULLSCREEN */) ) { glfwTerminate(); exit(EXIT_FAILURE); } glfwEnable(GLFW_MOUSE_CURSOR); glfwEnable(GLFW_KEY_REPEAT); // Ensure we can capture the escape key being pressed below glfwEnable( GLFW_STICKY_KEYS ); glfwSetMousePos(windowWidth/2, windowHeight/2); glfwSetWindowTitle("Chapter-11"); // Initialize AntTweakBar if ( !TwInit(TW_OPENGL_CORE, NULL)) { fprintf(stderr,"AntweakBar initialiazation failed: %s\n",TwGetLastError()); exit(1); } // Create a tweak bar myBar = TwNewBar("TweakBar"); //init GLEW and basic OpenGL information // VERY IMPORTANT OTHERWISE GLEW CANNOT HANDLE GL3 #ifdef USE_OPENGL32 glewExperimental = true; #endif glewInit(); std::cout<<"\nUsing GLEW "<<glewGetString(GLEW_VERSION)<<std::endl; if (GLEW_VERSION_2_1) { std::cout<<"\nYay! OpenGL 2.1 is supported and GLSL 1.2!\n"<<std::endl; } if (GLEW_VERSION_3_2) { std::cout<<"Yay! OpenGL 3.2 is supported and GLSL 1.5!\n"<<std::endl; } /* This extension defines an interface that allows various types of data (especially vertex array data) to be cached in high-performance graphics memory on the server, thereby increasing the rate of data transfers. Chunks of data are encapsulated within "buffer objects", which conceptually are nothing more than arrays of bytes, just like any chunk of memory. An API is provided whereby applications can read from or write to buffers, either via the GL itself (glBufferData, glBufferSubData, glGetBufferSubData) or via a pointer to the memory. */ if (glewIsSupported("GL_ARB_vertex_buffer_object")) std::cout<<"ARB VBO's are supported"<<std::endl; else if (glewIsSupported("GL_APPLE_vertex_buffer_object")) std::cout<<"APPLE VBO's are supported"<<std::endl; else std::cout<<"VBO's are not supported,program will not run!!!"<<std::endl; /* This extension introduces named vertex array objects which encapsulate vertex array state on the client side. The main purpose of these objects is to keep pointers to static vertex data and provide a name for different sets of static vertex data. By extending vertex array range functionality this extension allows multiple vertex array ranges to exist at one time, including their complete sets of state, in manner analogous to texture objects. GenVertexArraysAPPLE creates a list of n number of vertex array object names. After creating a name, BindVertexArrayAPPLE associates the name with a vertex array object and selects this vertex array and its associated state as current. To get back to the default vertex array and its associated state the client should bind to vertex array named 0. */ if (glewIsSupported("GL_ARB_vertex_array_object")) std::cout<<"ARB VAO's are supported\n"<<std::endl; else if (glewIsSupported("GL_APPLE_vertex_array_object"))//this is the name of the extension for GL2.1 in MacOSX std::cout<<"APPLE VAO's are supported\n"<<std::endl; else std::cout<<"VAO's are not supported, program will not run!!!\n"<<std::endl; std::cout<<"Vendor: "<<glGetString (GL_VENDOR)<<std::endl; std::cout<<"Renderer: "<<glGetString (GL_RENDERER)<<std::endl; std::cout<<"Version: "<<glGetString (GL_VERSION)<<std::endl; std::ostringstream stream1,stream2; stream1 << glGetString(GL_VENDOR); stream2 << glGetString(GL_RENDERER); std::string vendor ="Title : Chapter-11 Vendor : " + stream1.str() + " Renderer : " +stream2.str(); const char *tit = vendor.c_str(); glfwSetWindowTitle(tit); // Set GLFW event callbacks // - Redirect window size changes to the callback function WindowSizeCB glfwSetWindowSizeCallback(WindowSizeCB); // - Directly redirect GLFW mouse button events to AntTweakBar glfwSetMouseButtonCallback((GLFWmousebuttonfun)TwEventMouseButtonGLFW); // - Directly redirect GLFW mouse position events to AntTweakBar glfwSetMousePosCallback((GLFWmouseposfun)TwEventMousePosGLFW); // - Directly redirect GLFW mouse wheel events to AntTweakBar glfwSetMouseWheelCallback((GLFWmousewheelfun)TwEventMouseWheelGLFW); // - Directly redirect GLFW key events to AntTweakBar glfwSetKeyCallback((GLFWkeyfun)TwEventKeyGLFW); // - Directly redirect GLFW char events to AntTweakBar glfwSetCharCallback((GLFWcharfun)TwEventCharGLFW); TwDefine("TweakBar label='Main TweakBar' alpha=0 help='Use this bar to control the objects of the scene.' "); // Add 'wire' to 'myBar': it is a modifable variable of type TW_TYPE_BOOL32 (32 bits boolean). Its key shortcut is [w]. TwAddVarRW(myBar, "wireframe mode", TW_TYPE_BOOL32, &wireFrame," label='Wireframe mode' key=w help='Toggle wireframe display mode.' "); // Add 'bgColor' to 'myBar': it is a modifable variable of type TW_TYPE_COLOR3F (3 floats color) TwAddVarRW(myBar, "bgColor", TW_TYPE_COLOR3F, &bgColor, " label='Background color' "); // Add 'Rotation' to 'myBar': this is a variable of type TW_TYPE_QUAT4F which defines the scene's orientation TwAddVarRW(myBar, "SceneRotation", TW_TYPE_QUAT4F, &Rotation," label='Scene rotation' opened=true help='Change the scenes orientation.' "); TwAddButton(myBar, "Reset", ResetView,NULL," label='Reset View' "); TwAddVarRW(myBar, "Near Clip Plane", TW_TYPE_FLOAT, &zNear,"min=0.5 max=100 step=0.5 label='Near Clip' group='Projection Properties'"); TwAddVarRW(myBar, "Far Clip Plane", TW_TYPE_FLOAT, &zFar," min=0.5 max=1000 step=0.5 label='Far Clip' group='Projection Properties'"); TwAddVarRW(myBar, "Field of View", TW_TYPE_FLOAT, &FOV," label='FoV' readonly=true group='Projection Properties'"); TwAddVarRW(myBar, "MS per 1 Frame" , TW_TYPE_DOUBLE, &FPS, "label='MS per 1 Frame' readonly=true group='Frame Rate'"); TwAddVarRW(myBar, "Frames Per Second" , TW_TYPE_INT32, &rate, "label='FPS' readonly=true group='Frame Rate'"); TwAddVarRW(myBar, "vSYNC" , TW_TYPE_BOOL8, &SYNC, "label='vSync' readonly=true group='Frame Rate'"); // Enable depth test glEnable(GL_DEPTH_TEST); // Accept fragment if it closer to the camera than the former one glDepthFunc(GL_LESS); initPlane(); //initialize Plane init3Dmodel(); // initialize 3D model create_Bump_bar(); GLfloat rat = 0.001f; if(SYNC == false) { rat = 0.001f; } else { rat = 0.01f; } // Initialize time time = glfwGetTime(); double currentTime; float lastTime = 0.0f; int Frames = 0; double LT = glfwGetTime(); starting = glfwGetTime(); setVSync(SYNC); while (running) { glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT ); glClearColor( bgColor[0], bgColor[1], bgColor[2], bgColor[3]); //black color FOV = initialFoV - 5 * glfwGetMouseWheel(); if(camera == true) { glfwGetMousePos(&xpos,&ypos); glfwSetMousePos(windowWidth/2, windowHeight/2); horizAngle += mouseSpeedo * float(windowWidth/2 - xpos ); verticAngle += mouseSpeedo * float( windowHeight/2 - ypos ); } glm::vec3 direction(cos(verticAngle) * sin(horizAngle),sin(verticAngle),cos(verticAngle) * cos(horizAngle)); glm::vec3 right = glm::vec3(sin(horizAngle - 3.14f/2.0f),0,cos(horizAngle - 3.14f/2.0f)); glm::vec3 up = glm::cross( right, direction ); currentTime = glfwGetTime(); float dTime = float(currentTime - lastTime); lastTime = (float)currentTime; // Move forward if (glfwGetKey( GLFW_KEY_UP ) == GLFW_PRESS){ pos += direction * dTime* speedo; } // Move backward if (glfwGetKey( GLFW_KEY_DOWN ) == GLFW_PRESS){ pos -= direction * dTime * speedo; } // Strafe right if (glfwGetKey( GLFW_KEY_RIGHT ) == GLFW_PRESS){ pos += right * dTime * speedo; } //Strafe left if (glfwGetKey( GLFW_KEY_LEFT ) == GLFW_PRESS){ pos -= right * dTime * speedo; } if (glfwGetKey(GLFW_KEY_SPACE) == GLFW_PRESS){ if(camera == false) { camera=true; glfwSetMousePos(windowWidth/2, windowHeight/2); glfwGetMousePos(&xpos,&ypos); } else { camera=false; glfwSetMousePos(windowWidth/2, windowHeight/2); glfwGetMousePos(&xpos,&ypos); } } mat = ConvertQuaternionToMatrix(Rotation, mat); glm::mat4 cube; glm::mat4 translateMat = glm::mat4(); translateMat = glm::translate(translateMat,glm::vec3(5.0,3.0,4.0)); cube = mat * translateMat; displayPlane(mat,pos,direction,up); display3Dmodel(cube,mat,pos,direction,up); // drawing the AntWeakBar if (wireFrame) { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); TwDraw(); } else { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); TwDraw(); } fr++; ending = glfwGetTime(); if(ending - starting >= 1) { rate = fr; fr = 0; starting = glfwGetTime(); } double CT = glfwGetTime(); Frames++; if(CT -LT >= 1.0) { FPS = 1000.0 / (double)Frames; Frames = 0; LT += 1.0f; } glfwSwapBuffers(); //check if ESC was pressed running=!glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED); } //close OpenGL window and terminate AntTweakBar and GLFW TwTerminate(); glfwTerminate(); exit(EXIT_SUCCESS); }
// Callback function called by GLUT to render screen void Display(void) { // Clear frame buffer glClearColor(0.7, 0.7, 0.7, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glEnable(GL_NORMALIZE); float lightPositon[4]; float l = sqrtf(powf(lightDirection[0], 2) + powf(lightDirection[1], 2) + powf(lightDirection[2], 2)); lightPositon[0] = -lightDistance*lightDirection[0] / l; lightPositon[1] = -lightDistance*lightDirection[1] / l; lightPositon[2] = -lightDistance*lightDirection[2] / l; lightPositon[3] = 1.0f; // point light glUseProgram(0); glPushMatrix(); glTranslatef(0.5f, -0.3f, 0.0f); if (g_AutoRotate) { float axis[3] = { 0, 1, 0 }; float angle = (float)(GetTimeMs() - g_RotateTime) / 1000.0f; float quat[4]; SetQuaternionFromAxisAngle(axis, angle, quat); MultiplyQuaternions(g_RotateStart, quat, g_Rotation); } ConvertQuaternionToMatrix(g_Rotation, mat); glMultMatrixf(mat); glScalef(g_Zoom, g_Zoom, g_Zoom); glCallList(DRAW_EN); glPopMatrix(); GLuint currentProgram = programs[currentShader]; if (currentShader == 1) { glUseProgram(0); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient); glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, lightDiffuse); glLightfv(GL_LIGHT0, GL_POSITION, lightPositon); float materialAmbient[] = { rf[0] * 0.2f, rf[1] * 0.2f, rf[2] * 0.2f }; float materialDiffuse[] = { rf[0] * 0.6f, rf[1] * 0.6f, rf[2] * 0.6f }; float materialSpecular[] = { 1 - rf[0] * roughness / 2, 1 - rf[1] * roughness / 2, 1 - rf[2] * roughness / 2 }; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, materialAmbient); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, materialDiffuse); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, materialSpecular); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 24); } else { glUseProgram(currentProgram); glUniform1i(glGetUniformLocation(currentProgram, "env_brdf"), IBL); //#####glUniform1i(glGetUniformLocation(currentProgram, "env_map"), MAP); glUniform1i(glGetUniformLocation(currentProgram, "cubemap"), MAP); glUniform1i(glGetUniformLocation(currentProgram, "tex"), TEX); //glUniform1i(glGetUniformLocation(currentShader, "lightNum"), 0); //glUniform1f(glGetUniformLocation(currentProgram, "density"), lightAmbient[1]); //glUniform3fv(glGetUniformLocation(currentProgram, "ambient"), 1, lightAmbient); glLightfv(GL_LIGHT0, GL_POSITION, lightPositon); glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse); glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient); //glUniform3fv(glGetUniformLocation(currentProgram, "lightPos"), 1, lightPositon); //glUniform3fv(glGetUniformLocation(currentProgram, "diffuse"), 1, lightDiffuse); glUniform3fv(glGetUniformLocation(currentProgram, "rf"), 1, rf); glUniform1f(glGetUniformLocation(currentProgram, "roughness"), roughness); glUniform1i(glGetUniformLocation(currentProgram, "iftex"), -1); glUniformMatrix4fv(glGetUniformLocation(currentProgram, "g_rotation"), 1, GL_FALSE, mat); } // Rotate and draw shape glPushMatrix(); glTranslatef(0.5f, -0.3f, 0.0f); if (g_AutoRotate) { float axis[3] = { 0, 1, 0 }; float angle = (float)(GetTimeMs() - g_RotateTime) / 1000.0f; float quat[4]; SetQuaternionFromAxisAngle(axis, angle, quat); MultiplyQuaternions(g_RotateStart, quat, g_Rotation); } ConvertQuaternionToMatrix(g_Rotation, mat); glMultMatrixf(mat); glScalef(g_Zoom, g_Zoom, g_Zoom); glCallList(g_CurrentShape); glPopMatrix(); glUseProgram(0); // Draw tweak bars TwDraw(); // Present frame buffer glutSwapBuffers(); // Recall Display at next frame glutPostRedisplay(); }
void Display(void) { //display the background image here /*glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, 1, 0, 1, -1, 1); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glDepthMask(GL_FALSE); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glRasterPos2i(0, 0); glDrawPixels()*/ /* glClearColor(1.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glEnable(GL_TEXTURE_2D); */ //background(); float v[4]; float v1[4]; float mat[4 * 4]; glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glEnable(GL_NORMALIZE); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); v[0] = v[1] = v[2] = g_LightMultiplier*0.4f; v[3] = 1.0f; glLightfv(GL_LIGHT0, GL_AMBIENT, v); v[0] = v[1] = v[2] = g_LightMultiplier*0.8f; v[3] = 1.0f; glLightfv(GL_LIGHT0, GL_DIFFUSE, v); v[0] = -g_LightDirection[0]; v[1] = -g_LightDirection[1]; v[2] = -g_LightDirection[2]; v[3] = 0.0f; glLightfv(GL_LIGHT0, GL_POSITION, v); glEnable(GL_LIGHTING); glEnable(GL_LIGHT1); v1[0] = v1[1] = v1[2] = g_LightMultiplier*0.4f; v1[3] = 1.0f; glLightfv(GL_LIGHT1, GL_AMBIENT, v1); v1[0] = v1[1] = v1[2] = g_LightMultiplier*0.8f; v1[3] = 1.0f; glLightfv(GL_LIGHT1, GL_DIFFUSE, v1); v1[0] = -g_LightDirection2[0]; v1[1] = -g_LightDirection2[1]; v1[2] = -g_LightDirection2[2]; v1[3] = 0.0f; glLightfv(GL_LIGHT1, GL_POSITION, v1); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, g_MatAmbient1); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, g_MatDiffuse1); glPushMatrix(); glTranslatef(0.5f, -0.3f, 0.0f); if (g_AutoRotate) { float axis[3] = { 0, 1, 0 }; float angle = (float)(GetTimeMs() - g_RotateTime) / 1000.0f; float quat[4]; SetQuaternionFromAxisAngle(axis, angle, quat); MultiplyQuaternions(g_RotateStart, quat, g_Rotation); } ConvertQuaternionToMatrix(g_Rotation, mat); glMultMatrixf(mat); glScalef(g_Zoom, g_Zoom, g_Zoom); Matrices identity; animation->evaluate(newTime); if (animate){ float timeDiff = currentTime - prevTime; prevTime = currentTime; currentTime = time(NULL); newTime = newTime + 0.01; } skeletonWasp->calculate(identity.IDENTITY); skinningWasp->update(); skinningWasp->draw(); glPopMatrix(); TwDraw(); glutSwapBuffers(); glutPostRedisplay(); }