bool CObjectView::saveEPS(const char *fileName){ SELECT_CONTEXT(); // to use GL2PS FILE *f = fopen(fileName, "w"); if (!f) return false; int buffsize = 0, state = GL2PS_OVERFLOW; while( state == GL2PS_OVERFLOW ){ buffsize += 1024*1024; TRACE("bufferSize set to %d\n", buffsize); gl2psBeginPage("GRB", "GRB", GL2PS_BSP_SORT /*GL2PS_SIMPLE_SORT*/, GL2PS_NONE /*GL2PS_OCCLUSION_CULL*/, GL_RGBA, 0, NULL, buffsize, f); gl2psLineWidth(1); gl2psPointSize(1); setupPerspective(); drawScene(NULL, -1); state = gl2psEndPage(); } fclose(f); UNSELECT_CONTEXT(); return true; }
bool CObjectView::save(const char *file){ RECT rc; GetClientRect(&rc); int w = rc.right - rc.left; int h = rc.bottom - rc.top; GL_DIB_Info inf; createGLDIB(&inf, w, h); // only works because bitmap is same size as window setupPerspective(); // do draw (need to save stuff from old context) GLuint tmpTex = -1; if (textureFile.GetLength()) loadTexture(textureFile, &tmpTex); drawScene(NULL, tmpTex); CProgressMeter pm(this); pm.init(); char *err; bool saved = saveGL(file, &err, &pm); if (!saved) AfxMessageBox(err, MB_OK | MB_ICONSTOP); destroyGLDIB(inf); return saved; }
void MainWindow::init() { Log("Window initializing..."); setupOpenGLState(); setupPerspective(); scene.setup(); mainLoop(); }
void CameraManipulator::setupCamera(){ cameraPosition = glm::vec3(0.0, 0.0, zoom); cameraTarget = glm::vec3(0.0f, 0.0f, 1.0f); cameraUp = glm::vec3(0.0f, 1.0f, 0.0f); //view /*view = glm::lookAt(glm::vec3(0.0f, 0.0f, 10.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));*/ view = glm::lookAt(cameraPosition, cameraTarget, cameraUp); // Projection setupPerspective(20.0f, width, height, 0.01f, 100.0f); model = glm::mat4(1); //model = glm::translate(model, glm::vec3(0.0, 0.0, 0.0)); GLfloat angle = 20.0f; //model = glm::rotate(model, angle, glm::vec3(1.0f, 0.3f, 0.5f)); }
void CScene::paint(void) { if (!dxInit) return; if( g_pD3DDevice == NULL ) { return; } //Clear the backbuffer to black g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); //Begin the scene g_pD3DDevice->BeginScene(); //Setup the rotation, camera, and perspective matrices setupRotation(); setupCamera(); setupPerspective(); // Call paint on objects for (objects_vec::iterator it = m_Objects.begin(); it != m_Objects.end(); ++it) { CGameObject *obj = *it; if (obj->isDead()) continue; obj->paint(); } //End the scene g_pD3DDevice->EndScene(); //Filp the back and front buffers so that whatever has been rendered on the back buffer //will now be visible on screen (front buffer). g_pD3DDevice->Present(NULL, NULL, NULL, NULL); }
bool LittleBombers::init(float width, float height) { _characterX = 0; _characterTargetX = 0; _characterRotationY = 90; _cameraZ = 0; _cameraTargetZ = 0; _controlX = 0; // ★★★★★★★★★★★ Load resources ★★★★★★★★★★★ // Background music mBackgroundMusic.reset(new (nothrow) BackgroundMusic); if (mBackgroundMusic) { if (!mBackgroundMusic->init("City Night Crowd.mp4")) { DEBUG_LOG("[LittleBombers] Can't start background music…"); return false; } mBackgroundMusic->playbackEndedSignal.connect(boost::bind(&LittleBombers::restartMusic, this)); restartMusic(); } else { DEBUG_LOG("[LittleBombers] Can't alloc background music…"); } for (int i=0; i<10; ++i) if (!mStageModel[i].init("Stage1a.md2")) return false; for (int i=0; i<8; ++i) { if (!mCharacterModel[i].init("megaman.md2")) return false; mCharacterModel[i].setAnimation(ModelT::ANIM_WAVE); } if (!mStageTexture.init("Stage1a_Grid.pvr")) return false; if (!mCharacterTexture.init("megaman.pvr")) return false; if (!mFX.init("Crickets.ogg", true)) return false; setupPerspective(.1f, 1000.f, 60.f, width, height); // Setup opengl glEnableClientState( GL_VERTEX_ARRAY); glEnableClientState( GL_TEXTURE_COORD_ARRAY); glEnableClientState( GL_NORMAL_ARRAY); // glEnable( GL_BLEND); // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normals are encoded as bytes whose value is -127..+127, // so we need them to be normalized: glEnable(GL_NORMALIZE); // Scale the texture matrix so that -32767..+32767 gets normalized to -1..+1: glMatrixMode(GL_TEXTURE); glLoadIdentity(); const float fiou = 1.f/32767.f; glScalef(fiou, fiou, 1.f); glMatrixMode(GL_MODELVIEW); glEnable( GL_TEXTURE_2D); glCullFace(GL_BACK); externalAudio.connect(boost::bind(&LittleBombers::externalAudioHandler, this, _1)); touchesBegan.connect(boost::bind(&LittleBombers::touchesBeganHandler, this, _1)); touchesEnded.connect(boost::bind(&LittleBombers::touchesEndedHandler, this, _1)); touchesMoved.connect(boost::bind(&LittleBombers::touchesMovedHandler, this, _1)); GLint alphaBits; glGetIntegerv(GL_ALPHA_BITS, &alphaBits); return true; }
///////////////////////////////////////////////////////////////////////////// // CObjectView interaction void CObjectView::OnLButtonDown(UINT nFlags, CPoint point) { if (mode == POINT){ selID = -1; SELECT_CONTEXT(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // setup select mode GLuint selBuf[1024]; glSelectBuffer(1024, selBuf); glRenderMode(GL_SELECT); glInitNames(); glPushName(~0); // save projection matrix glMatrixMode(GL_PROJECTION); glPushMatrix(); setupPerspective(true, point.x, point.y); glMatrixMode(GL_MODELVIEW); setupModelView(); // draw scene for selection drawObject(true); int sI = glRenderMode(GL_RENDER); if (sI){ // find closest hit /* GLint minZ = 1000000; for (int l = 0; l < sI; l++){ GLint z = selBuf[4*l+1]; if (z < minZ){ minZ = z; selID = selBuf[4*l+3]; } }*/ selID = selBuf[4*(sI-1)+3]; TRACE("selID = %d\n", selID); clearDisplayList(); InvalidateRect(NULL); } else{ selID = -1; TRACE("No Hit\n"); clearDisplayList(); InvalidateRect(NULL); } // restore matrix glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); UNSELECT_CONTEXT(); } else if (mode != ZOOM){ // record starting point and hook mouse lastPt = point; SetCapture(); RedrawWindow(); } else{ scale *= 2.0f; // zoom in RedrawWindow(); } CView ::OnLButtonDown(nFlags, point); }
void CObjectView::OnDraw(CDC* pDC) { SELECT_CONTEXT(); setupPerspective(); drawScene(&dList, tex); // turn off lighting glDisable(GL_LIGHTING); // draw tracker ball if ((mode == ROTATE || mode == LIGHT)&& GetCapture() == this){ // do overlay glEnable(GL_CULL_FACE); glClear(GL_DEPTH_BUFFER_BIT); glDisable(GL_STENCIL_TEST); // work out size of tracker float rad = 0.85f; // setup transform glMatrixMode(GL_MODELVIEW); if (mode == LIGHT) glLoadMatrixf(mL); else glLoadMatrixf(m); // mesh glPolygonMode(GL_FRONT, GL_LINE); glLineWidth(1); // draw light if (mode == LIGHT){ // get position Vector3D v = {1.0f, 1.0f, 1.0f}; v.norm(); v.scale(rad); // setup dot size GLint dotSize; glGetIntegerv(GL_POINT_SIZE, &dotSize); glPointSize(3); // draw light glColor3f(1.0f, 1.0f, 0.0f); glBegin(GL_POINTS); glVertex3f(v.x, v.y, v.z); glEnd(); glBegin(GL_LINES); glVertex3f(0.0f, 0.0f, 0.0f); glVertex3f(v.x, v.y, v.z); glEnd(); // restore dot size glPointSize(dotSize); } // draw sphere glColor3f(1, 0, 1); glRotatef(90, 1, 0, 0); GLUquadricObj *q = gluNewQuadric(); gluSphere(q, rad, 10, 10); gluDeleteQuadric(q); } // clean up and show picture glFlush(); SwapBuffers(hDC); UNSELECT_CONTEXT(); }