//-------------------------------------------------------------- void testApp::draw() { /// Scene Manager draw // ------------------ setDrawFloorAuto(true); int main_screen_width = 1920; int main_screen_height = 1200; main_screen_width = min(main_screen_width, ofGetWidth()); main_screen_height = min(main_screen_height, ofGetHeight()); ramCameraManager::instance().setActiveCamera(0); ofPushView(); ofViewport(0, 0, 1920, 1200); ramBeginCamera(); drawFloor(); ramEndCamera(); sceneManager.draw(); ofPopView(); int screen_w = 1280, screen_h = 720; int inv_screen_height = ofGetHeight() - screen_h; for (int i = 0; i < 5; i++) { ofPushView(); ofCamera *screen_camera = ramCameraManager::instance().getCamera(i + 1); ofViewport(ofRectangle(main_screen_width + i * screen_w, inv_screen_height, screen_w, screen_w)); ramCameraManager::instance().setActiveCamera(i + 1); screen_camera->begin(); drawFloor(); screen_camera->end(); sceneManager.draw(); ofPopView(); } ramCameraManager::instance().setActiveCamera(0); setDrawFloorAuto(false); }
void OgreBuilding::drawLedge() { addBoundingBox(1); drawFloor(); Point lowerBound = cursor.getPosition(); cursor.move(ledgeHeight); Point higherBound = cursor.getPosition(); renderStorey(ledgeMaterial, lowerBound, higherBound); drawFloor(); substractBoundingBox(1); }
void RedBuilding::finishDrawing() { drawStorey(); addBoundingBox(2); drawFloor(); drawSpacer(); drawRooftop(); }
//========================================================================== void MyGlWindow::draw() //========================================================================== { glViewport(0,0,w(),h()); // clear the window, be sure to clear the Z-Buffer too glClearColor(0.2f,0.2f,.2f,0); // background should be blue glClearStencil(0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glEnable(GL_DEPTH); glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); // now draw the ground plane setProjection(); setupFloor(); glPushMatrix(); drawFloor(50,32); glPopMatrix(); // now to draw the shadows setupLight(); // Add a sphere to the scene. glBegin(GL_LINES); glColor3f(1,0,0); glVertex3f(0,0,0); glVertex3f(0,100,0); glColor3f(0,1,0); glVertex3f(0,0,0); glVertex3f(100,0,0); glColor3f(0,0,1); glVertex3f(0,0,0); glVertex3f(0,0,100); glEnd(); setupShadows(); drawStuff(); unsetupShadows(); // Enable blending glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); drawStuff(); }
void drawHouse(double xLoc, double yLoc, double zLoc, double xSize, double ySize, double zSize) { //printf("j");fflush(stdout); glPushMatrix(); glTranslated(xLoc, yLoc, zLoc); // For house coordinates house; house.x = 5.0; house.y = 4.0; house.z = 4.0; //glTranslated(-house.x/2.0, house.y/2.0, 0); int logNum = 8; double logOverlap= .1; //printf("k");fflush(stdout); // Wall Zero glPushMatrix(); glTranslated(0,-house.y*logOverlap, 0); glRotated(0, 0, 0, 0); drawWallWithOpening(house.z, house.x, logNum, house.x*.37, 0, house.x*.63, house.z*.75); glPopMatrix(); //printf("l");fflush(stdout); // Wall 1 glPushMatrix(); glTranslated(house.x*logOverlap, 0, 0); glRotated(-90, 0, 0, 1); drawWallWithOpening(house.z, house.y, logNum, house.y*.4, house.z*.4, house.y*.75, house.z*.75); glPopMatrix(); //printf("m");fflush(stdout); // Wall 2 glPushMatrix(); glTranslated(0, house.y*(logOverlap - 1), 0); glRotated(00, 0, 0, 0); drawWall(house.z, house.x, logNum); glPopMatrix(); //printf("n");fflush(stdout); // Wall 3 glPushMatrix(); glTranslated(house.x*(1 - logOverlap), 0, 0); glRotated(-90, 0, 0, 1); drawWallWithOpening(house.z, house.y, logNum, house.y*.25, house.z*.4, house.y*.6, house.z*.75); glPopMatrix(); //printf("o");fflush(stdout); drawRoof(2.0, house); //printf("y");fflush(stdout); drawFloor(house, logOverlap); glPopMatrix(); }
void ramBaseApp::draw(ofEventArgs &args) { glPushAttrib(GL_ALL_ATTRIB_BITS); glEnable(GL_DEPTH_TEST); ramBeginCamera(); if (draw_floor_auto) drawFloor(); getActorManager().draw(); bool enable_physics = ramGetEnablePhysicsPrimitive(); ramEnablePhysicsPrimitive(false); glPushAttrib(GL_ALL_ATTRIB_BITS); glPushMatrix(); ofPushStyle(); if (ramShadowEnabled()) { // shadow ramBeginShadow(); drawNodeArrays(); ramEndShadow(); } ofPopStyle(); glPopMatrix(); glPopAttrib(); ramEnablePhysicsPrimitive(enable_physics); glPushAttrib(GL_ALL_ATTRIB_BITS); glPushMatrix(); ofPushStyle(); if (drawModel) { // entities drawNodeArrays(); } ofPopStyle(); glPopMatrix(); glPopAttrib(); ramEndCamera(); glPopAttrib(); }
void drawGameFrame() { drawFloor(); player->draw(); for (int i=0;i<bullets.size();++i) { bullets[i].draw(); } for (int i=0;i<enemies.size();++i) { enemies[i].draw(); } }
//-------------------------------------------------------------- void testApp::draw() { ofBackgroundGradient(ofColor(10,10,10), ofColor::black, OF_GRADIENT_CIRCULAR); easyCam.begin(); drawFloor(); drawParticles(); easyCam.end(); kinect.drawDepth(0, 0, 160, 120); // background.drawSmoothedBg(0, 130, 160, 120); drawDebugText(); }
void drawHouse() { ErrCheck("Before drawHouse"); glPushMatrix(); coordinates house; house.x = 5.0; house.y = 3.0; house.z = 4.0; glTranslated(-house.x/2.0, 0, house.z/2.0); int logNum = 8; double logOverlap= .1; // Wall Zero glPushMatrix(); glTranslated(0, 0, -house.z*logOverlap); glRotated(0, 0, 0, 0); drawWallWithOpening(house.y, house.x, logNum, house.x*.4, 0, house.x*.6, house.y*.75); //drawWall(house.y, house.x, logNum); glPopMatrix(); // Wall 1 glPushMatrix(); glTranslated(house.x*logOverlap, 0, 0); glRotated(90, 0, 1, 0); drawWallWithOpening(house.y, house.z, logNum, house.z*.4, house.y*.4, house.z*.75, house.y*.75); glPopMatrix(); // Wall 2 glPushMatrix(); glTranslated(0, 0, house.z*(logOverlap - 1)); glRotated(00, 0, 0, 0); drawWall(house.y, house.x, logNum); glPopMatrix(); // Wall 3 glPushMatrix(); glTranslated(house.x*(1 - logOverlap), 0, 0); glRotated(90, 0, 1, 0); drawWallWithOpening(house.y, house.z, logNum, house.z*.4, house.y*.4, house.z*.75, house.y*.75); //drawWall(house.y, house.z, logNum); glPopMatrix(); drawRoof(2.0, house); drawFloor(house, logOverlap); glPopMatrix(); ErrCheck("After drawFloor"); }
void drawScene(int pass) { /* The 0.03 in the Y column is just to shift the texture coordinates a little based on Y (depth in the water) so that vertical faces (like on the cube) do not get totally vertical caustics. */ GLfloat sPlane[4] = { 0.05, 0.03, 0.0, 0.0 }; GLfloat tPlane[4] = { 0.0, 0.03, 0.05, 0.0 }; /* The causticScale determines how large the caustic "ripples" will be. See the "Increate/Decrease ripple size" menu options. */ sPlane[0] = 0.05 * causticScale; sPlane[1] = 0.03 * causticScale; tPlane[1] = 0.03 * causticScale; tPlane[2] = 0.05 * causticScale; if (pass == PASS_CAUSTIC) { /* Set current color to "white" and disable lighting to emulate OpenGL 1.1's GL_REPLACE texture environment. */ glColor3f(1.0, 1.0, 1.0); glDisable(GL_LIGHTING); /* Generate the S & T coordinates for the caustic textures from the object coordinates. */ glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGenfv(GL_S, GL_OBJECT_PLANE, sPlane); glTexGenfv(GL_T, GL_OBJECT_PLANE, tPlane); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); if (HaveTexObj) { glBindTexture(GL_TEXTURE_2D, currentCaustic+1); } else { glCallList(currentCaustic+101); } } drawFloor(pass); drawObject(pass); if (pass == PASS_CAUSTIC) { glEnable(GL_LIGHTING); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); } }
/********************************************************************************* * Call this part whenever display events are needed. * Display events are called in case of re-rendering by OS. ex) screen movement, screen maximization, etc. **********************************************************************************/ void display() { glClearColor(0, 0.6, 0.8, 1); // Clear color setting glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the screen // set viewing transformation. glLoadMatrixd(wld2cam[cameraIndex].GLmatrix()); drawOtherCamera(); // Locate the camera's position, and draw all of them. drawFloor(); // Draw floor. // TODO: // update cow2wld here to animate the cow. //double animTime=glfwGetTime()-animStartTime; //you need to modify both the translation and rotation parts of the cow2wld matrix. // have not more than 6 cow if (cowCount < 6) { for (int i = 0; i < cowCount; i++) drawCow(cowPos[i], false); drawCow(cow2wld, cursorOnCowBoundingBox); // Draw cow. } else if (cowCount == 6) { // Have 6 cow if (!flag) { // Initalaize time and state and start spline flag = true; glfwSetTime(0.0f); curTime = 0.0f; cowFlag = false; newPos = cowPos[0].getTranslation(); catMullRomSpline(curTime); } else if (curTime < 9) { // Before 9 second keep draw cow curTime = glfwGetTime(); catMullRomSpline(curTime); } else { // After 9 second initialize cowCount = 0; flag = false; } } //drawBet(); glFlush(); }
void ThreeDWidget::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); drawView(); drawFloor(); drawOriginal(); // drawSkeleton(); drawPointCloud(); if(_calibrated) drawCameras(); }
void OgreBuilding::drawObliqueLedge() { Polygon bottomBase = boundingBox->base(); Point lowerBound = cursor.getPosition(); cursor.move(ledgeHeight); Point higherBound = cursor.getPosition(); addBoundingBox(2); Polygon topBase = boundingBox->base(); renderObliqueShape(ledgeMaterial, bottomBase, topBase, lowerBound, higherBound); drawFloor(); substractBoundingBox(2); }
/* Called when GLUT wants to repaint the screen (we do all our rendering/geometry here) */ void display(void) { float xCamera, yCamera, zCamera; /* Camera coordinates */ float xRoot, yRoot, zRoot; /* Root position */ /* Clear frame buffer and set up MODELVIEW matrix */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /* Calculate the camera position using polar coordinates */ xCamera = rCamera*sin(thetaCamera)*cos(phiCamera); yCamera = rCamera*sin(thetaCamera)*sin(phiCamera); zCamera = rCamera*cos(thetaCamera); /* Calculate root postion */ xRoot = gMo->root_pos[currentFrame].x; yRoot = -gMo->root_pos[currentFrame].z; zRoot = gMo->root_pos[currentFrame].y; if(initialPose) { /* Place the camera and draw the skeleton in its initial position */ gluLookAt(xCamera, yCamera, zCamera, 0, 0, 0, 0, 0, 1); drawInitialPose(gSkel, referenceFrame); } else { /* Place camera at specified position and draw the skeleton under mocap data */ gluLookAt(xCamera+xRoot, yCamera+yRoot, zCamera+zRoot, xRoot, yRoot, zRoot, 0, 0, 1); drawSkeleton(gSkel, gMo, currentFrame, referenceFrame); } drawFloor(140, 140); if(referenceFrame) drawReferenceFrame(20); /* Ensure any queued up OpenGL calls are run and swap buffers */ glFlush(); glutSwapBuffers(); }
void drawMap(int width, int height, std::vector<CaseType> &map) { int LightPos[4] = {0, 0, 3, 1}; float ambient[4] = {0.45f, 0.45f, 0.45f, 1.0f}; float diffuse[4] = {1.f, 1.f, 1.f, 1.f}; glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslated(0, 0, 5); glRotated(90, 0, 0, 1); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, diffuse); glLightiv(GL_LIGHT0, GL_POSITION, LightPos); glLoadIdentity(); gluLookAt((width - 1) / 2, -height / 6, height - 5, (width - 1) / 2, height + 30, -height - 20, 0, 1, 1); drawFloor(width, height); for (int i = 0; i < width * height; i++) { switch (map[i]) { case CaseType::WALL: glLoadIdentity(); gluLookAt((width - 1) / 2, -height / 6, height - 5, (width - 1) / 2, height + 30, -height - 20, 0, 1, 1); drawCube(i % width, height - i / width - 1, 0.25, 0.4f, 0.4f, 0.4f); break; case CaseType::SNAKE: glLoadIdentity(); gluLookAt((width - 1) / 2, -height / 6, height - 5, (width - 1) / 2, height + 30, -height - 20, 0, 1, 1); drawSphere(i % width, height - i / width - 1, 0.75f, 0.f, 0.5f, 0.f); break; case CaseType::POWERUP: glLoadIdentity(); gluLookAt((width - 1) / 2, -height / 6, height - 5, (width - 1) / 2, height + 30, -height - 20, 0, 1, 1); drawSphere(i % width, height - i / width - 1, 0.5, 0.5f, 0.f, 0.f); break; default: break; } } }
void SludgeFloorMaker::drawRect() { glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0f, 1.00f, 1.00f); pasteSprite(&backdrop.sprites[0], &backdrop.myPalette, FALSE); glDisable(GL_TEXTURE_2D); glColor3f(1.0f, 0.35f, 0.35f); glBegin(GL_LINES); { glVertex3f( 0.0, 0.0, 0.0); glVertex3f( 1000.0, 0.0, 0.0); glVertex3f( 0.0, 0.0, 0.0); glVertex3f( 0.0, 1000.0, 0.0); } glEnd(); if (lit) { glColor3f(1.0f, 0.00f, 1.00f); glBegin(GL_QUADS); { glVertex3i( litX-8, litY-8, 0); glVertex3i( litX+8, litY-8, 0); glVertex3i( litX+8, litY+8, 0); glVertex3i( litX-8, litY+8, 0); } glEnd(); } drawFloor(getFloor(), r, g, b); if (selection == 1) { glColor3f(1.0f, 0.00f, 1.00f); glBegin(GL_LINES); { glVertex3i(selx1, sely1, 0); glVertex3i(selx2, sely2, 0); } glEnd(); } }
void ramBaseApp::draw(ofEventArgs &args) { glPushAttrib(GL_ALL_ATTRIB_BITS); glEnable(GL_DEPTH_TEST); ramBeginCamera(); if (draw_floor_auto) drawFloor(); getActorManager().draw(); bool enable_physics = ramGetEnablePhysicsPrimitive(); ramEnablePhysicsPrimitive(false); if (ramShadowEnabled()) { // shadow ramBeginShadow(); drawNodeArrays(); ramEndShadow(); } ramEnablePhysicsPrimitive(enable_physics); if (drawModel) { // entities drawNodeArrays(); } ramEndCamera(); glPopAttrib(); getCommunicationManager().draw(); draw(); // calling testApp(or ofApp)::draw() }
void ofApp::draw(){ ofSetWindowTitle(ofToString(ofGetFrameRate(), 1) + "fps"); ofSetColor(255); if (bDraw3D) { mesh = kinect.getDepth()->getMesh(pointCloudOpts); ofEnableDepthTest(); camera.update(); camera.begin(); ofPushMatrix(); ofScale(100, 100, 100); { drawFloor(); if (bDrawSensorDebug) drawSensorPosition(); ofPushMatrix(); ofMultMatrix(kinect.getBodyFrame()->getFloorTransform()); { if (bDrawMesh) drawMesh(); drawBodies(); if (bDrawSensorDebug) drawFrustum(); } ofPopMatrix(); } ofPopMatrix(); camera.end(); ofDisableDepthTest(); } else { kinect.getColor()->draw(0, 0, ofGetWidth(), ofGetHeight()); kinect.getBodyFrame()->drawProjected(0, 0, ofGetWidth(), ofGetHeight()); } drawFaceFeatures(); drawGestures(); }
void OgreBuilding::interpretSymbol(char symbol) { switch (symbol) { case 'B': drawBasement(); break; case 'F': drawStorey(); break; case 'G': drawFloor(); break; case 'S': drawSpacer(); break; case 'O': drawObliqueLedge(); break; case 'L': drawLedge(); break; case 'R': drawRooftop(); break; case 'H': drawHoweRooftop(); break; case '-': substractBoundingBox(5); break; case '+': addBoundingBox(5); break; default: /* Try to interpret symbols defined in parent. */ Building::interpretSymbol(symbol); break; } }
void redraw(void) { if (useStencil) { /* Clear; default stencil clears to zero. */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); } else { /* Not using stencil; just clear color and depth. */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } glPushMatrix(); /* Perform scene rotations based on user mouse input. */ glRotatef(angle2, 1.0, 0.0, 0.0); glRotatef(angle, 0.0, 1.0, 0.0); /* Translate the dinosaur to be at (0,0,0). */ glTranslatef(-8, -8, -bodyWidth / 2); glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition); glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition); if (useStencil) { /* We can eliminate the visual "artifact" of seeing the "flipped" dinosaur underneath the floor by using stencil. The idea is draw the floor without color or depth update but so that a stencil value of one is where the floor will be. Later when rendering the dinosaur reflection, we will only update pixels with a stencil value of 1 to make sure the reflection only lives on the floor, not below the floor. */ /* Don't update color or depth. */ glDisable(GL_DEPTH_TEST); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); /* Draw 1 into the stencil buffer. */ glEnable(GL_STENCIL_TEST); glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); glStencilFunc(GL_ALWAYS, 1, 0xffffffff); /* Now render floor; floor pixels just get their stencil set to 1. */ drawFloor(); /* Re-enable update of color and depth. */ glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glEnable(GL_DEPTH_TEST); /* Now, only render where stencil is set to 1. */ glStencilFunc(GL_EQUAL, 1, 0xffffffff); /* draw if ==1 */ glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); } glPushMatrix(); /* The critical reflection step: Reflect dinosaur through the floor (the Y=0 plane) to make a relection. */ glScalef(1.0, -1.0, 1.0); /* Position lights now in reflected space. */ glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition); glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition); /* XXX Ugh, unfortunately the back face culling reverses when we reflect the dinosaur. Easy solution is just disable back face culling for rendering the reflection. Also, the normals for lighting get screwed up by the scale; enabled normalize to ensure normals are still properly normalized despite the scaling. We could have fixed the dinosaur rendering code, but this is more expedient. */ glEnable(GL_NORMALIZE); glCullFace(GL_FRONT); /* Draw the reflected dinosaur. */ drawDinosaur(); /* Disable noramlize again and re-enable back face culling. */ glDisable(GL_NORMALIZE); glCullFace(GL_BACK); glPopMatrix(); /* Restore light positions on returned from reflected space. */ glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition); glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition); if (useStencil) { /* Don't want to be using stenciling for drawing the actual dinosaur (not its reflection) and the floor. */ glDisable(GL_STENCIL_TEST); } /* Back face culling will get used to only draw either the top or the bottom floor. This let's us get a floor with two distinct appearances. The top floor surface is reflective and kind of red. The bottom floor surface is not reflective and blue. */ /* Draw "top" of floor. Use blending to blend in reflection. */ glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(0.7, 0.0, 0.0, 0.3); drawFloor(); glDisable(GL_BLEND); /* Draw "bottom" of floor in blue. */ glFrontFace(GL_CW); /* Switch face orientation. */ glColor4f(0.1, 0.1, 0.7, 1.0); drawFloor(); glFrontFace(GL_CCW); /* Draw "actual" dinosaur, not its reflection. */ drawDinosaur(); glPopMatrix(); glutSwapBuffers(); }
void MyWindow::draw() { int i; if (!valid()) { //Init viewport and projection initGL(); double w = this->w(), h = this->h(); glViewport(0, 0, (int)w, (int)h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); double left = -.1; double bottom = -.1; double right = 1.1; double top = 1.1; if(w > 1 && h > 1) { if(w > h) { right = -0.1 + 1.2 * w / h; } if(h > w) { bottom = 1.1 - 1.2 * h / w; } } double scale = 1. / 1000.; left = -w * scale; right = w * scale; bottom = -h * scale; top = h * scale; glFrustum(left, right, bottom, top, 5., 30.); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); //Transform------ Vector3 trans = transform.getTrans(); glTranslated(trans[0], trans[1], -10 + trans[2]); double scale = transform.getScale(); glScaled(scale, scale, scale); Quaternion<> r = transform.getRot(); double ang = r.getAngle(); if(fabs(ang) > 1e-6) { Vector3 ax = r.getAxis(); glRotated(ang * 180. / M_PI, ax[0], ax[1], ax[2]); } //Draw---------- if(floor) drawFloor(); vector<const Mesh *> ms(meshes.size()); for(i = 0; i < (int)meshes.size(); ++i) { ms[i] = &(meshes[i]->getMesh()); } //shadows if(floor) { Vector3 lightRay = transform.getRot().inverse() * Vector3(1, 2, 2); if(lightRay[1] == 0) lightRay[1] = 1e-5; lightRay = -lightRay / lightRay[1]; glDisable(GL_LIGHTING); glColor3f(0.1f, 0.1f, 0.1f); glPushMatrix(); float matr[16] = {1,0,0,0, (float)lightRay[0],0,(float)lightRay[2],0, 0,0,1,0, 0,0.01f,0,1}; glMultMatrixf(matr); glDepthMask(0); for(i = 0; i < (int)ms.size(); ++i) drawMesh(*(ms[i]), flatShading); glDepthMask(1); glEnable(GL_LIGHTING); glPopMatrix(); } static GLfloat colr[4] = {1.f, .9f, .75f, 1.0f }; static GLfloat colrb[4] = {1.f, .9f, .75f, 1.0f }; glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, colr); glMaterialfv( GL_BACK, GL_AMBIENT_AND_DIFFUSE, colrb); //draw meshes for(i = 0; i < (int)meshes.size(); ++i) { drawMesh(*(ms[i]), flatShading); } //draw lines glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); for(i = 0; i < (int)lines.size(); ++i) { glColor3d(lines[i].color[0], lines[i].color[1], lines[i].color[2]); glLineWidth((float)lines[i].thickness); glBegin(GL_LINES); glVertex3d(lines[i].p1[0], lines[i].p1[1], lines[i].p1[2]); glVertex3d(lines[i].p2[0], lines[i].p2[1], lines[i].p2[2]); glEnd(); } if(skeleton) { glLineWidth(5); for(i = 0; i < (int)meshes.size(); ++i) { vector<Vector3> v = meshes[i]->getSkel(); if(v.size() == 0) continue; glColor3d(.5, 0, 0); const vector<int> &prev = human.fPrev(); glBegin(GL_LINES); for(int j = 1; j < (int)prev.size(); ++j) { int k = prev[j]; glVertex3d(v[j][0], v[j][1], v[j][2]); glVertex3d(v[k][0], v[k][1], v[k][2]); } glEnd(); } } }
void SceneRenderer::drawScene(GLint positionAttrib, GLint normalAttrib) { drawFloor(positionAttrib, normalAttrib); drawModel(positionAttrib, normalAttrib); }
// this is the code that actually draws the window // it puts a lot of the work into other routines to simplify things void TrainView::draw() { glViewport(0,0,w(),h()); // clear the window, be sure to clear the Z-Buffer too glClearColor(0,0,.3f,0); // background should be blue // we need to clear out the stencil buffer since we'll use // it for shadows glClearStencil(0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glEnable(GL_DEPTH); // Blayne prefers GL_DIFFUSE glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); // prepare for projection glMatrixMode(GL_PROJECTION); glLoadIdentity(); setProjection(); // put the code to set up matrices here // TODO: you might want to set the lighting up differently // if you do, // we need to set up the lights AFTER setting up the projection // enable the lighting glEnable(GL_COLOR_MATERIAL); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); // top view only needs one light if (tw->topCam->value()) { glDisable(GL_LIGHT1); glDisable(GL_LIGHT2); } else { glEnable(GL_LIGHT1); glEnable(GL_LIGHT2); } // set the light parameters GLfloat lightPosition1[] = {0,1,1,0}; // {50, 200.0, 50, 1.0}; GLfloat lightPosition2[] = {1, 0, 0, 0}; GLfloat lightPosition3[] = {0, -1, 0, 0}; GLfloat yellowLight[] = {0.5f, 0.5f, .1f, 1.0}; GLfloat whiteLight[] = {1.0f, 1.0f, 1.0f, 1.0}; GLfloat blueLight[] = {.1f,.1f,.3f,1.0}; GLfloat grayLight[] = {.3f, .3f, .3f, 1.0}; glLightfv(GL_LIGHT0, GL_POSITION, lightPosition1); glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight); glLightfv(GL_LIGHT0, GL_AMBIENT, grayLight); glLightfv(GL_LIGHT1, GL_POSITION, lightPosition2); glLightfv(GL_LIGHT1, GL_DIFFUSE, yellowLight); glLightfv(GL_LIGHT2, GL_POSITION, lightPosition3); glLightfv(GL_LIGHT2, GL_DIFFUSE, blueLight); // now draw the ground plane setupFloor(); glDisable(GL_LIGHTING); drawFloor(200,10); glEnable(GL_LIGHTING); setupObjects(); // we draw everything twice - once for real, and then once for // shadows drawStuff(); // this time drawing is for shadows (except for top view) if (!tw->topCam->value()) { setupShadows(); drawStuff(true); unsetupShadows(); } }
void display(void) { //時間計測 static double time1, time2, drawTime, frame; if(ang <= 0.001) time1 = timeGetTime(); //step1:textureの作成 glClearColor( 0.7, 0.6, 0.6, 1.0 );//背景色 //framebuffer objectを有効化 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, fbName ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glViewport( 0, 0, TEX_WIDTH, TEX_HEIGHT ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluPerspective(fb_view.fovY, (double)TEX_WIDTH/(double)TEX_HEIGHT, fb_view.nearZ, fb_view.farZ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); gluLookAt(fb_view.pos[0], fb_view.pos[1], fb_view.pos[2], fb_view.cnt[0], fb_view.cnt[1], fb_view.cnt[2], 0.0, 1.0, 0.0); glUseProgram(shaderProg2); draw1(); drawFloor(10.0, 10.0, 10, 10); glUseProgram(0); drawShadow(1); //framebuffer objectの無効化 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); //step2:通常にrendering resize(width, height); glClearColor(0.2, 0.2, 0.3, 1.0);//背景色 //カラーバッファ,デプスバッファのクリア glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity();//視点を変えるときはこの位置に必要 if(cos(M_PI * view.theta /180.0) >= 0.0)//カメラ仰角90度でビューアップベクトル切替 gluLookAt(view.pos[0], view.pos[1], view.pos[2], view.cnt[0], view.cnt[1], view.cnt[2], 0.0, 1.0, 0.0); else gluLookAt(view.pos[0], view.pos[1], view.pos[2], view.cnt[0], view.cnt[1], view.cnt[2], 0.0, -1.0, 0.0); //光源設定//'l'を押した後光源位置可変 glLightfv(GL_LIGHT0, GL_POSITION, lightPos); //描画 glBindTexture(GL_TEXTURE_2D, texName); glUseProgram(shaderProg1); GLint samplerLoc = glGetUniformLocation(shaderProg1, "sampler"); glUniform1i(samplerLoc, 0);//GL_TEXTURE0を適用 draw0(); drawFloor(10.0, 10.0, 10, 10); glUseProgram(0); glBindTexture(GL_TEXTURE_2D, 0); //影 drawShadow(0); //回転角度更新 ang += dang; if(ang >= 360.0) { time2 = timeGetTime(); //1回転当たりの描画時間 drawTime = (time2 - time1) * 0.001; frame = (360.0 / dang) / drawTime; printf("フレーム数 = %4.2f[fps] \n", frame); //フレームあたりの描画時間 drawTime = 1.0 / frame; printf("描画時間 = %4.5f[spf] \n", drawTime); ang = 0.0; } if(flagHelp) { printf("矢印キーによるアフィン変換/光源移動 \n"); printf(" →,←:x軸 \n"); printf(" ↑,↓:y軸 \n"); printf(" [Shift]+↑,↓:z軸 \n"); printf(" 'r'を押した後:回転 \n"); printf(" 't'を押した後:平行移動 \n"); printf(" 's'を押した後:スケーリング \n"); printf(" 'l'を押した後、光源位置の移動可 \n"); printf("マウス操作で視点変更可 \n"); printf(" dolly:中央付近を左ボタンクリックで近づき,右ボタンクリックで遠ざかる \n"); printf(" pan:左横および右横を右ボタンクリックで注視点が左右に変化する \n"); printf(" tilt:真上および真下を右ボタンクリックで注視点が上下に変化する \n"); printf(" tumble:左右にドラッグすると視点が左右に変化する \n"); printf(" crane:上下にドラッグすると視点が上下に変化する \n"); printf(" zoom:左下を右ボタンクリックでズームイン \n"); printf(" 右下を右ボタンクリックでズームアウト \n"); printf("[Shift]+'r'でリセット \n"); printf("[Page Up]キー:回転角度+0.1 \n"); printf("[Page Dn]キー:回転角度-0.1 \n"); flagHelp = false; } //終了 glutSwapBuffers(); }
static void redraw(void) { int start = 0, end = 0; if (reportSpeed) { start = glutGet(GLUT_ELAPSED_TIME); } /* Clear; default stencil clears to zero. */ if ((stencilReflection && renderReflection) || (stencilShadow && renderShadow)) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); } else { /* Avoid clearing stencil when not using it. */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } /* Reposition the light source. */ lightPosition[0] = 12*cos(lightAngle); lightPosition[1] = lightHeight; lightPosition[2] = 12*sin(lightAngle); if (directionalLight) { lightPosition[3] = 0.0; } else { lightPosition[3] = 1.0; } shadowMatrix(floorShadow, floorPlane, lightPosition); glPushMatrix(); /* Perform scene rotations based on user mouse input. */ glRotatef(angle2, 1.0, 0.0, 0.0); glRotatef(angle, 0.0, 1.0, 0.0); /* Tell GL new light source position. */ glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); if (renderReflection) { if (stencilReflection) { /* We can eliminate the visual "artifact" of seeing the "flipped" dinosaur underneath the floor by using stencil. The idea is draw the floor without color or depth update but so that a stencil value of one is where the floor will be. Later when rendering the dinosaur reflection, we will only update pixels with a stencil value of 1 to make sure the reflection only lives on the floor, not below the floor. */ /* Don't update color or depth. */ glDisable(GL_DEPTH_TEST); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); /* Draw 1 into the stencil buffer. */ glEnable(GL_STENCIL_TEST); glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); glStencilFunc(GL_ALWAYS, 1, 0xffffffff); /* Now render floor; floor pixels just get their stencil set to 1. */ drawFloor(); /* Re-enable update of color and depth. */ glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glEnable(GL_DEPTH_TEST); /* Now, only render where stencil is set to 1. */ glStencilFunc(GL_EQUAL, 1, 0xffffffff); /* draw if ==1 */ glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); } glPushMatrix(); /* The critical reflection step: Reflect dinosaur through the floor (the Y=0 plane) to make a relection. */ glScalef(1.0, -1.0, 1.0); /* Reflect the light position. */ glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); /* To avoid our normals getting reversed and hence botched lighting on the reflection, turn on normalize. */ glEnable(GL_NORMALIZE); glCullFace(GL_FRONT); /* Draw the reflected dinosaur. */ drawDinosaur(); /* Disable noramlize again and re-enable back face culling. */ glDisable(GL_NORMALIZE); glCullFace(GL_BACK); glPopMatrix(); /* Switch back to the unreflected light position. */ glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); if (stencilReflection) { glDisable(GL_STENCIL_TEST); } } /* Back face culling will get used to only draw either the top or the bottom floor. This let's us get a floor with two distinct appearances. The top floor surface is reflective and kind of red. The bottom floor surface is not reflective and blue. */ /* Draw "bottom" of floor in blue. */ glFrontFace(GL_CW); /* Switch face orientation. */ glColor4f(0.1, 0.1, 0.7, 1.0); drawFloor(); glFrontFace(GL_CCW); if (renderShadow) { if (stencilShadow) { /* Draw the floor with stencil value 3. This helps us only draw the shadow once per floor pixel (and only on the floor pixels). */ glEnable(GL_STENCIL_TEST); glStencilFunc(GL_ALWAYS, 3, 0xffffffff); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); } } /* Draw "top" of floor. Use blending to blend in reflection. */ glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(0.7, 0.0, 0.0, 0.3); glColor4f(1.0, 1.0, 1.0, 0.3); drawFloor(); glDisable(GL_BLEND); if (renderDinosaur) { /* Draw "actual" dinosaur, not its reflection. */ drawDinosaur(); } if (renderShadow) { /* Render the projected shadow. */ if (stencilShadow) { /* Now, only render where stencil is set above 2 (ie, 3 where the top floor is). Update stencil with 2 where the shadow gets drawn so we don't redraw (and accidently reblend) the shadow). */ glStencilFunc(GL_LESS, 2, 0xffffffff); /* draw if ==1 */ glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); } /* To eliminate depth buffer artifacts, we use polygon offset to raise the depth of the projected shadow slightly so that it does not depth buffer alias with the floor. */ if (offsetShadow) { switch (polygonOffsetVersion) { case EXTENSION: #ifdef GL_EXT_polygon_offset glEnable(GL_POLYGON_OFFSET_EXT); break; #endif #ifdef GL_VERSION_1_1 case ONE_DOT_ONE: glEnable(GL_POLYGON_OFFSET_FILL); break; #endif case MISSING: /* Oh well. */ break; } } /* Render 50% black shadow color on top of whatever the floor appareance is. */ glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_LIGHTING); /* Force the 50% black. */ glColor4f(0.0, 0.0, 0.0, 0.5); glPushMatrix(); /* Project the shadow. */ glMultMatrixf((GLfloat *) floorShadow); drawDinosaur(); glPopMatrix(); glDisable(GL_BLEND); glEnable(GL_LIGHTING); if (offsetShadow) { switch (polygonOffsetVersion) { #ifdef GL_EXT_polygon_offset case EXTENSION: glDisable(GL_POLYGON_OFFSET_EXT); break; #endif #ifdef GL_VERSION_1_1 case ONE_DOT_ONE: glDisable(GL_POLYGON_OFFSET_FILL); break; #endif case MISSING: /* Oh well. */ break; } } if (stencilShadow) { glDisable(GL_STENCIL_TEST); } } glPushMatrix(); glDisable(GL_LIGHTING); glColor3f(1.0, 1.0, 0.0); if (directionalLight) { /* Draw an arrowhead. */ glDisable(GL_CULL_FACE); glTranslatef(lightPosition[0], lightPosition[1], lightPosition[2]); glRotatef(lightAngle * -180.0 / M_PI, 0, 1, 0); glRotatef(atan(lightHeight/12) * 180.0 / M_PI, 0, 0, 1); glBegin(GL_TRIANGLE_FAN); glVertex3f(0, 0, 0); glVertex3f(2, 1, 1); glVertex3f(2, -1, 1); glVertex3f(2, -1, -1); glVertex3f(2, 1, -1); glVertex3f(2, 1, 1); glEnd(); /* Draw a white line from light direction. */ glColor3f(1.0, 1.0, 1.0); glBegin(GL_LINES); glVertex3f(0, 0, 0); glVertex3f(5, 0, 0); glEnd(); glEnable(GL_CULL_FACE); } else { /* Draw a yellow ball at the light source. */ glTranslatef(lightPosition[0], lightPosition[1], lightPosition[2]); glutSolidSphere(1.0, 5, 5); } glEnable(GL_LIGHTING); glPopMatrix(); glPopMatrix(); if (reportSpeed) { glFinish(); end = glutGet(GLUT_ELAPSED_TIME); printf("Speed %.3g frames/sec (%d ms)\n", 1000.0/(end-start), end-start); fflush(stdout); } glutSwapBuffers(); }
void display(void) { //時間計測 static double time1, time2, drawTime, frame; if(ang <= 0.001) time1 = timeGetTime(); //カラーバッファ,デプスバッファのクリア glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity();//視点を変えるときはこの位置に必要 if(cos(M_PI * view.theta /180.0) >= 0.0)//カメラ仰角90度でビューアップベクトル切替 gluLookAt(view.pos[0], view.pos[1], view.pos[2], view.cnt[0], view.cnt[1], view.cnt[2], 0.0, 1.0, 0.0); else gluLookAt(view.pos[0], view.pos[1], view.pos[2], view.cnt[0], view.cnt[1], view.cnt[2], 0.0, -1.0, 0.0); if(flagWireframe)//'w'でwireframeとsolid model切り替え { glPolygonMode(GL_FRONT,GL_LINE); glPolygonMode(GL_BACK,GL_POINT); } else glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); setLight(); glUseProgram(shaderProg); //描画 draw0(); draw1(); drawFloor(20.0, 20.0, 20, 20); glUseProgram(0); //影 drawShadow(0);//光源0に対する影 drawShadow(1);//光源1に対する影 //光源描画 drawLight(); drawSpotlight(); //回転角度更新 ang += dang; if(ang >= 360.0) { time2 = timeGetTime(); //1回転当たりの描画時間 drawTime = (time2 - time1) * 0.001; frame = (360.0 / dang) / drawTime; printf("フレーム数 = %4.4f[fps] \n", frame); //フレームあたりの描画時間 drawTime = 1.0 / frame; printf("描画時間 = %4.4f[spf] \n", drawTime); ang = 0.0; } if(flagHelp) { printf("矢印キーによるアフィン変換/光源移動 \n"); printf(" →,←:x軸 \n"); printf(" ↑,↓:y軸 \n"); printf(" [Shift]+↑,↓:z軸 \n"); printf(" 'r'を押した後:回転 \n"); printf(" 't'を押した後:平行移動 \n"); printf(" 's'を押した後:スケーリング \n"); printf(" 'l'を押した後、光源位置の移動可 \n"); printf("'w'でワイヤーフレームとソリッドモデル切り替え \n"); printf("マウス操作で視点変更可 \n"); printf(" dolly:中央付近を左ボタンクリックで近づき,右ボタンクリックで遠ざかる \n"); printf(" pan:左横および右横を右ボタンクリックで注視点が左右に変化する \n"); printf(" tilt:真上および真下を右ボタンクリックで注視点が上下に変化する \n"); printf(" tumble:左右にドラッグすると視点が左右に変化する \n"); printf(" crane:上下にドラッグすると視点が上下に変化する \n"); printf(" zoom:左下を右ボタンクリックでズームイン \n"); printf(" 右下を右ボタンクリックでズームアウト \n"); printf("[Shift]+'r'でリセット \n"); printf("[Page Up]キー:回転角度+0.1 \n"); printf("[Page Dn]キー:回転角度-0.1 \n"); printf("[F1]:光源の減衰モード切りかえ \n"); printf("[F2]キー:スポットライト指数調整 \n"); printf("[F3]キー:スポットライトのカットオフ角度調整 \n"); flagHelp = false; } //終了 glutSwapBuffers(); }
void display(void) { glFogf (GL_FOG_DENSITY, density); printf("%f \n",density); // Position the light and show where it is glPushMatrix(); glRotatef(90,0,1,0); glTranslatef(move_x, move_y, move_z); // glLightf(GL_LIGHT4, GL_CONSTANT_ATTENUATION, const_att); glLightfv(GL_LIGHT4, GL_POSITION, light_pos); //glDisable(GL_LIGHTING); //glDisable(GL_LIGHT4); glColor3d(0.9, 0.9, 0.5); glutSolidSphere(0.1, 10, 10); //glEnable(GL_LIGHTING); //glEnable(GL_LIGHT4); glPopMatrix(); for(int i =0;i<16;i++) { HeadMatrix[i] = dragonmodel.TransformMatrixArray[0][i]; } light_position[0] = HeadMatrix[12]; light_position[1] = HeadMatrix[13]; light_position[2] = HeadMatrix[14]; light_direction[0] = HeadMatrix[8]; light_direction[1] = HeadMatrix[9]; light_direction[2] = HeadMatrix[10]; normalizeCamTarget(); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, light_direction); glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, fSpotLight); glLightfv(GL_LIGHT7, GL_POSITION, light_position); glLightfv(GL_LIGHT7, GL_SPOT_DIRECTION, light_direction); glLightf(GL_LIGHT7, GL_SPOT_CUTOFF, fSpotLight); // glLightfv(GL_LIGHT5, GL_POSITION, lightBody_position); // glLightfv(GL_LIGHT5, GL_SPOT_DIRECTION, light_direction); glLightf(GL_LIGHT5, GL_SPOT_CUTOFF, fSpotLight); // glLightfv(GL_LIGHT1, GL_POSITION, light1_position); // glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, light1_direction); // glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, fSpotLight); //glLoadIdentity(); //135-206-250 //glClearColor(0.52734375,0.8046875,0.9765625,0); //light blue //overcast //glClearColor(0.6796875,0.71484375,0.7421875,0); //darker overcast glClearColor(0.1796875,0.21484375,0.2421875,0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // cam_position[0] = cam_radius * sin(cam_phi) * sin(cam_theta); // cam_position[1] = cam_radius * cos(cam_phi); // cam_position[2] = cam_radius * sin(cam_phi) * cos(cam_theta); cam_target[0] = dragonmodel.getTransformMatrixArrayValue(0,12); cam_target[1] = dragonmodel.getTransformMatrixArrayValue(0,13); cam_target[2] = dragonmodel.getTransformMatrixArrayValue(0,14); GLfloat x; GLfloat y; GLfloat z; GLfloat total; x = cam_position[0] - cam_target[0]; y = cam_position[1] - cam_target[1]; z = cam_position[2] - cam_target[2]; total = x*x + y*y + z*z; total = sqrt(total); //printf("\n"); //printf(" wanted_cam_radius = %f\n" , wanted_cam_radius); ////printf(" camradius = %f\n" , cam_radius); //printf(" dist = %f\n" , total); GLfloat diff = wanted_cam_radius - total; //diff = diff*diff; //diff = sqrt(diff); //printf(" diff = %f\n" , diff); // if (diff>10 || diff<-10) // { // cam_radius += diff; // } // if(cam_radius>wanted_cam_radius) // { // cam_radius += 0.05*(diff); // } // else // cam_radius -= 0.05*(diff); //-= 0.5*(diff); cam_position[0] = cam_radius * sin(cam_phi) * sin(cam_theta)+ cam_target[0] ; cam_position[1] = cam_radius * cos(cam_phi)+ cam_target[1]; cam_position[2] = cam_radius * sin(cam_phi) * cos(cam_theta)+cam_target[2]; glLightfv(GL_LIGHT2, GL_POSITION, cam_position); glLightfv(GL_LIGHT2, GL_SPOT_DIRECTION, light2_target); glLightf(GL_LIGHT2, GL_SPOT_CUTOFF, 20); if(cameraFlag == false) { gluLookAt(cam_position[0],cam_position[1],cam_position[2], cam_target[0], cam_target[1], cam_target[2], 0,1,0);//cam_up[0], cam_up[1], cam_up[2]); } if(cameraFlag == true) { dragonmodel.updateCamera(); } glPushMatrix(); drawFloor(); drawSun(); //glPushMatrix(); glScalef(0.5,0.5,0.5); dragonmodel.drawTrees(); ////////////forest //making trees float scale; for (int i = 0; i < amount; i++) { glPushAttrib(GL_ALL_ATTRIB_BITS); glPushMatrix(); glTranslatef(location[i][0], 0, location[i][1]); if (location[i][2] == 0) { scale = (i % 50) + 1; glPushMatrix(); glScalef( scale/25, scale/25, scale/25); dragonmodel.drawTrees(); glPopMatrix(); } else if (location[i][2] == 1) { scale = (i % 50) + 1; glPushMatrix(); glScalef( scale/25, scale/25, scale/25); dragonmodel.drawTrees2(); glPopMatrix(); } else if (location[i][2] == 2) { scale = (i % 50) + 1; glPushMatrix(); glScalef( scale/25, scale/25, scale/25); dragonmodel.drawTrees3(); glPopMatrix(); } else { scale = (i % 50) + 1; glPushMatrix(); glScalef( scale/25, scale/25, scale/25); dragonmodel.drawTrees4(); glPopMatrix(); } //printf("%d \n", location[i][2]); glPopMatrix(); glPopAttrib(); } glPopMatrix(); glPopMatrix(); //Psuh Dragon up glPushAttrib(GL_ALL_ATTRIB_BITS); glPushMatrix(); glTranslatef(0,20,0); if(colorflag == 0) { glDisable(GL_COLOR_MATERIAL); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, trans); glMaterialfv(GL_FRONT, GL_SHININESS, shine); glMaterialfv(GL_BACK, GL_AMBIENT_AND_DIFFUSE, trans); glMaterialfv(GL_BACK, GL_SHININESS, shine); } dragonmodel.drawDragon(); if(colorflag == 0) { glEnable(GL_COLOR_MATERIAL); } glPopMatrix(); glPopAttrib(); glutSwapBuffers(); }
//-------------------------------------------------------------- void testApp::draw(){ ofSetColor(0); ofBackground(120); ofDrawBitmapString("FPS: " + ofToString(ofGetFrameRate(), 2), 20,20); if(displayMode == DT_DM_3D){ cm.begin(); glEnable(GL_DEPTH_TEST); ofScale(-100,100,100); ofNoFill(); ofPushMatrix(); ofScale(0.05, 0.05, 0.05); ofDrawGrid(); ofPopMatrix(); ofPushMatrix(); ofTranslate(0, m_kinectManager.getFloorY(), 0); drawFloor(); ofPopMatrix(); ofNoFill(); ofSetColor(255,255,0); ofPushMatrix(); ofVec3f a = m_kinectManager.getQAxis(); ofRotate(m_kinectManager.getQAngle(), a.x, a.y, a.z); ofScale(2,0.5,0.5); ofBox(0.15); ofPopMatrix(); if(isViewSegPoints){ if(m_kinectManager.getDancer())m_kinectManager.drawUserPointCloud(); }else{ m_kinectManager.drawScenePointCloud(); } if(isViewCom && m_kinectManager.getDancer()){ ofNoFill(); ofSetColor(0, 255, 255); ofVec3f com = m_kinectManager.getDancer()->com; ofSphere(com.x, com.y, com.z, m_kinectManager.getDancerHeight()/2); } if(isViewCScene)m_bankManager->getCurrentScene()->draw(cm.getPosition()); cm.end(); glDisable(GL_DEPTH_TEST); } if(displayMode == DT_DM_2D){ ofSetColor(255); ofPushMatrix(); ofTranslate(ofGetWidth() - 750, 50); m_kinectManager.getLiveImg()->draw(0,0,320,240); ofTranslate(0, 260); ofDrawBitmapString("live depthMap", 0,0); ofTranslate(0, 40); m_kinectManager.getSegMask()->draw(0,0,320,240); ofTranslate(0, 260); ofDrawBitmapString("segmented depthMap", 0,0); ofTranslate(0, 40); ofPopMatrix(); ofPushMatrix(); ofTranslate(ofGetWidth() - 360, 50); ofFill(); ofSetColor(50); ofRect(0,0,320,240); m_kinectManager.getCfFinder()->draw(0,0,320,240); ofTranslate(0, 260); ofSetColor(255); ofDrawBitmapString("contour analysis", 0,0); ofPopMatrix(); } }
void display(void) { glClearColor(1,1,1,1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ); convertToView(); glMatrixMode(GL_MODELVIEW); glLoadMatrixf( modelViewMatrix ); glColor4f(1,1,1,1); drawFloor(textures[FLOORID]); drawWalls(textures[WALLID]); //draw the items on the screen glRotatef(angle,0,1,0); //rotate the square //draw the snowman snowman.display(); snowman2.display(); snowman3.display(); //draw the car vehicle.display(translateToThirdPerson, textures[SIRENID], textures[VEHICLEID], firstPersonView, overheadView); //scoreboard sb.setMsg2(msgDamage); //draw the Snowdift snowcave.display(textures[FLOORID]); snowcave2.display(textures[FLOORID]); //pond display pond.display(textures[PONDID],textures[WATERID]); //gifts //for (int i=0; i<giftCount;i++) // gifts[i].display(); glPushMatrix(); for (int i=0; i<giftCount;i++) gifts[i].display(); glPopMatrix(); // Tractor Beam Function pullInObject(); glPopMatrix(); //ScoreBoard() glPushMatrix(); glLoadIdentity(); if(!overheadView) glTranslatef(sbOrigin.x,sbOrigin.y,sbOrigin.z); else glTranslatef(0,0,-40); sb.display(overheadView); glPopMatrix(); drawCieling(); npc.display(textures[FLOORID]); //draw the snowballs in flight displayProjectiles(); glFlush(); glutSwapBuffers(); }
void OPGL::drawScene() { if(showPreformance) ++fps; //glClearColor( 0.0f, 0.0f, 0.0f, 1.0f ); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glPushMatrix(); glRotatef(-_angle[1]/4, 1.0f, 0.0f, 0.0f); glRotatef(-_angle[0]/4, 0.0f, 1.0f, 0.0f); GLfloat lightColor[] = {1.0f, 1.0f, 1.0f, 1.0f}; GLfloat lightPos[] = {3.0,-3.0,3.0,0.3};//2 * BOX_SIZE * cos(_angle[0] * M_PI/180), 2*BOX_SIZE * sin(_angle[0] * M_PI/180), 4 * BOX_SIZE, 1.0f}; glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor); glLightfv(GL_LIGHT0, GL_POSITION, lightPos); // Show Light sphere glPushMatrix(); glDisable(GL_LIGHTING); glColor3f(1.0, 1.0, 0.0); /* Draw a yellow ball at the light source. */ glTranslatef(-lightPos[0], -lightPos[1], -lightPos[2]); glutSolidSphere(0.2, 5, 5); glEnable(GL_LIGHTING); glPopMatrix(); glFrontFace(GL_CW); /* Switch face orientation.*/ glPushMatrix(); glTranslatef(0.0, -0.92, 0.0); drawFloor(); glFrontFace(GL_CCW); /* Switch face orientation.*/ drawFloor(); glPopMatrix(); glBegin(GL_TRIANGLES); for(unsigned int i=0; i < object.Faces.size();i+=3){ //if(i%3){ glColor3f(5.0f, 0.0f, 0.0f); if(i + 2 < object.Faces.size()){ Vector v1 = (object.Faces[i + 0]), v2 = (object.Faces[i + 1]), v3 = (object.Faces[i + 2]); v2.sub(v1); v3.sub(v1); Vector n = v3.cross(v2); n.normalize(); glNormal3f(n.x, n.y, n.z); } //} for(int j = 0; j < 3;j++){ Vector tmp=object.Faces[j+i]; //glTexCoord2f(tx[i], ty[i]); glVertex3f( tmp.x, tmp.y, tmp.z ); } } glEnd(); glPopMatrix(); /*//Top face glColor3f(1.0f, 1.0f, 0.0f); glNormal3f(0.0, 1.0f, 0.0f); glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2); glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2); glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2); glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2); //Bottom face glColor3f(1.0f, 0.0f, 1.0f); glNormal3f(0.0, -1.0f, 0.0f); glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2); glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2); glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2); glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2); //Left face glNormal3f(-1.0, 0.0f, 0.0f); glColor3f(0.0f, 1.0f, 1.0f); glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2); glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2); glColor3f(0.0f, 0.0f, 1.0f); glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2); glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2); //Right face glNormal3f(1.0, 0.0f, 0.0f); glColor3f(1.0f, 0.0f, 0.0f); glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2); glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2); glColor3f(0.0f, 1.0f, 0.0f); glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2); glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2); glEnd(); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, _textureId); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glColor3f(1.0f, 1.0f, 1.0f); glBegin(GL_QUADS); //Front face glNormal3f(0.0, 0.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2); glTexCoord2f(1.0f, 0.0f); glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2); glTexCoord2f(1.0f, 1.0f); glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2); glTexCoord2f(0.0f, 1.0f); glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2); //Back face glNormal3f(0.0, 0.0f, -1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2); glTexCoord2f(1.0f, 0.0f); glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2); glTexCoord2f(1.0f, 1.0f); glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2); glTexCoord2f(0.0f, 1.0f); glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2); glEnd(); glDisable(GL_TEXTURE_2D);*/ glutSwapBuffers(); }