// renders the console and frames per second to the screen void GameBase::renderConsoleAndFPS() { gConsole.render(); // render FPS information if (m_renderInfo) renderInfo(); }
void Postmortem::runInfo() { int topElement = 0; renderInfo(topElement); //Read keys bool done = false; while(done == false) { const KeyboardReadReturnData& d = eng->input->readKeysUntilFound(); if(d.sfmlKey_ == sf::Keyboard::Down || d.key_ == '2') { topElement = max(0, min(topElement + static_cast<int>(MAP_Y_CELLS / 5), static_cast<int>(postmortemLines.size()) - static_cast<int>(MAP_Y_CELLS))); renderInfo(topElement); } else if(d.sfmlKey_ == sf::Keyboard::Up || d.key_ == '8') { topElement = max(0, min(topElement - static_cast<int>(MAP_Y_CELLS / 5), static_cast<int>(postmortemLines.size()) - static_cast<int>(MAP_Y_CELLS))); renderInfo(topElement); } else if(d.sfmlKey_ == sf::Keyboard::Space || d.sfmlKey_ == sf::Keyboard::Escape) { done = true; } } }
//------------------------------------------------------- ChilliSource::RenderInfo RenderInfoFactory::CreateRenderInfo() noexcept { bool areHighPrecFragmentsSupported = true; bool areMapBuffersSupported = true; bool areVAOsSupported = true; bool areDepthTexturesSupported = false; bool areShadowMapsSupported = false; u32 maxTextureSize = 0; u32 maxTextureUnits = 0; u32 maxVertexAttribs = 0; #ifdef CS_OPENGLVERSION_ES s32 fragmentHighRanges[2]; s32 fragmentHighPrecision; glGetShaderPrecisionFormat(GL_FRAGMENT_SHADER, GL_HIGH_FLOAT, fragmentHighRanges, &fragmentHighPrecision); areHighPrecFragmentsSupported = fragmentHighPrecision != 0 && fragmentHighRanges[0] != 0 && fragmentHighRanges[1] != 0; #ifdef CS_TARGETPLATFORM_ANDROID //Check for map buffer support areMapBuffersSupported = CheckForOpenGLExtension("GL_OES_mapbuffer"); areVAOsSupported = CheckForOpenGLExtension("GL_OES_vertex_array_object"); #endif #ifdef CS_TARGETPLATFORM_RPI areVAOsSupported = false; #endif #endif #ifdef CS_OPENGLVERSION_STANDARD areDepthTexturesSupported = CheckForOpenGLExtension("GL_ARB_depth_texture"); #elif defined(CS_OPENGLVERSION_ES) areDepthTexturesSupported = CheckForOpenGLExtension("GL_OES_depth_texture"); #endif areShadowMapsSupported = (areDepthTexturesSupported && areHighPrecFragmentsSupported); glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint*)&maxTextureSize); glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, (GLint*)&maxTextureUnits); glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, (GLint*)&maxVertexAttribs); CS_ASSERT_NOGLERROR("An OpenGL error occurred while getting render capabilities."); ChilliSource::RenderInfo renderInfo(areShadowMapsSupported, areDepthTexturesSupported, areMapBuffersSupported, areVAOsSupported, areHighPrecFragmentsSupported, maxTextureSize, maxTextureUnits, maxVertexAttribs); return renderInfo; }
void MD2Loader::renderFrame( int& index ) { if (NULL == _md2File) { return; } // if (_md2File->_header.ident != 844121161 || _md2File->_header.version != 8) { return; } if (index < 0 || index > _md2File->_header.num_frames - 1) { //return; index = 0; } // _renderSystem->setTexture(_md2File->_data.tex_id, _tex); /* Draw the model */ Data* pData = &_md2File->_data; frame* pframe = &pData->frames[index]; /* Draw each triangle */ for (int i = 0; i < _md2File->_header.num_tris; ++i) { // triangle* pTriangle = &pData->triangles[i]; // POSITION_NORMAL_TEXTURE s[3]; /* Draw each vertex */ for (int j = 0; j < 3; ++j) { vertex* pvert = &pframe->vs[pTriangle->v[j]]; // s[j]._pos.x = (pframe->scale[0] * pvert->v[0]) + pframe->translate[0]; s[j]._pos.z = (pframe->scale[1] * pvert->v[1]) + pframe->translate[1]; s[j]._pos.y = (pframe->scale[2] * pvert->v[2]) + pframe->translate[2]; // s[j]._normal.x = anorms_table[pvert->normalIndex][0]; s[j]._normal.z = anorms_table[pvert->normalIndex][1]; s[j]._normal.y = anorms_table[pvert->normalIndex][2]; /* Compute texture coordinates */ s[j]._tex.x = (float)(pData->texcoords[pTriangle->st[j]].s) / _md2File->_header.skinwidth; s[j]._tex.y = (float)(pData->texcoords[pTriangle->st[j]].t) / _md2File->_header.skinheight; } // _renderSystem->drawPrimitiveUP(D3DPT_TRIANGLELIST, 1, s, sizeof(POSITION_NORMAL_TEXTURE)); } // _currentIndex = index; // renderInfo(); }
void Main() { ResourceLoader resources; auto sampler = SamplerState(SamplerState::Default2D); sampler.filter = TextureFilter::MinMagMipPoint; Graphics2D::SetSamplerState(sampler); Window::Resize(320 * 2, 240 * 2); Window::SetTitle(L"まちへかえろう(仮)"); Array<HurdleObject> hurdles; Array<BuildingLayer> buildingLayers; Array<BuildingLayer2> buildingLayers2; Map::instance().init(40, 15); for (int i = 0; i < 40; i++) { Map::instance().set(i, 14, 5); Map::instance().set(i, 13, 5); Map::instance().set(i, 12, 4); Map::instance().set(i, 11, 3); Map::instance().set(i, 10, 3); Map::instance().set(i, 9, 2); Map::instance().set(i, 8, 1); } auto viewLeft = 0.0; auto mycharDead = false; ScreenState currentState = ScreenState::InTitle, prevState = currentState; bool prevSpacePressed = false; auto TitleTimer = TimerMillisec(); ScriptEngine asEngine; asEngine.RegisterMethod(L"int getAt(double x, double y)", &Map::getAt, Map::instance()); asEngine.RegisterProperty(L"double _viewX", &viewLeft); asEngine.RegisterProperty(L"bool _isGameOvered", &mycharDead); asEngine.RegisterFunction(L"void playJumpSound()", PlayJumpSound); auto context_mychar = asEngine.CreateContextFromScript(L"res/scripts/Mychar.as"); Record::instance().init(); int fc = 0; while (System::Update()) { bool spacePressedInFrame = !prevSpacePressed && Input::KeySpace.pressed; prevSpacePressed = Input::KeySpace.pressed; asEngine.setFrameCount(fc); switch (currentState) { case ScreenState::InTitle: if (!TitleTimer.isActive) TitleTimer.start(); renderBackgrounds(viewLeft, resources); renderBuildingLayers(buildingLayers, buildingLayers2, resources); renderMap(viewLeft, resources); renderTitle(TitleTimer.elapsed(), resources); renderCurrentMax(); if (spacePressedInFrame) { // GameInit SoundAsset(SoundResourceLoader::decide).play(); viewLeft = 0.0; mycharDead = false; context_mychar.Reenter(); buildingLayers.clear(); buildingLayers2.clear(); hurdles.clear(); currentState = ScreenState::Gaming; } break; case ScreenState::Gaming: // appear hurdles at random if (RandomBool(0.02)) { if (hurdles.empty() || hurdles.back().getPos().x - (viewLeft + 320.0f) < -48.0f) { // allocate space least 48 logical-pixels hurdles.emplace_back(HurdleObject(Vec2(viewLeft + 320.0f, 8.0f * 16.0f + 8.0f))); } } // appear building at random if (RandomBool(0.02 / 30.0)) { if (buildingLayers.empty() || buildingLayers.back().getPos().x < 0.0f) { buildingLayers.emplace_back(BuildingLayer(Vec2(320.0f, -60.0f))); } } if (RandomBool(0.01 / 30.0)) { if (buildingLayers2.empty() || buildingLayers2.back().getPos().x < 0.0f) { buildingLayers2.emplace_back(BuildingLayer2(Vec2(320.0f, -60.0f))); } } asEngine.setFrameCount(fc); context_mychar.Execute(); renderBackgrounds(viewLeft, resources); renderBuildingLayers(buildingLayers, buildingLayers2, resources); renderMap(viewLeft, resources); if (renderHurdlesAndHitTest(viewLeft, context_mychar.GetGlobalDoubleVec2(L"x", L"y"), hurdles, resources)) { if (!mycharDead) SoundAsset(SoundResourceLoader::died).play(); mycharDead = true; } renderPlayer(viewLeft, context_mychar.GetGlobalDouble(L"angle"), context_mychar.GetGlobalDoubleVec2(L"x", L"y"), resources); renderInfo(toScore(context_mychar.GetGlobalDouble(L"x"))); // Host Processes if (mycharDead && context_mychar.GetGlobalDouble(L"x") < viewLeft - 120.0f) { // update record Record::instance().recordScore(toScore(context_mychar.GetGlobalDouble(L"x"))); currentState = ScreenState::Result; } break; case ScreenState::Result: renderBackgrounds(viewLeft, resources); renderBuildingLayers(buildingLayers, buildingLayers2, resources); renderMap(viewLeft, resources); renderHurdlesAndHitTest(viewLeft, context_mychar.GetGlobalDoubleVec2(L"x", L"y"), hurdles, resources); renderResult(toScore(context_mychar.GetGlobalDouble(L"x")), Record::instance().isUpdated(), fc); if (spacePressedInFrame) { // GameInit SoundAsset(SoundResourceLoader::decide).play(); TitleTimer.reset(); currentState = ScreenState::InTitle; } break; } if (prevState != currentState) { fc = 0; } prevState = currentState; // Common Postprocesses fc++; viewLeft += 2.5f; } Map::instance().clean(); }
virtual void operator () (osg::GraphicsContext* context) { osg::RenderInfo renderInfo(context->getState(), 0); _gce->calibrate(renderInfo); }
int main(int argc, char** argv) { if (!glfwInit()) // 初始化glfw库 { std::cout << "Error::GLFW could not initialize GLFW!" << std::endl; return -1; } // 开启OpenGL 3.3 core profile std::cout << "Start OpenGL core profile version 3.3" << std::endl; glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); // 创建窗口 GLFWwindow* window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Demo of PBO(asynchronous DMA transfer)", NULL, NULL); if (!window) { std::cout << "Error::GLFW could not create winddow!" << std::endl; glfwTerminate(); return -1; } glfwSetWindowPos(window, 300, 100); // 创建的窗口的context指定为当前context glfwMakeContextCurrent(window); // 注册窗口键盘事件回调函数 glfwSetKeyCallback(window, key_callback); // 注册鼠标事件回调函数 glfwSetCursorPosCallback(window, mouse_move_callback); // 注册鼠标滚轮事件回调函数 glfwSetScrollCallback(window, mouse_scroll_callback); // 鼠标捕获 停留在程序内 glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); // 初始化GLEW 获取OpenGL函数 glewExperimental = GL_TRUE; // 让glew获取所有拓展函数 GLenum status = glewInit(); if (status != GLEW_OK) { std::cout << "Error::GLEW glew version:" << glewGetString(GLEW_VERSION) << " error string:" << glewGetErrorString(status) << std::endl; glfwTerminate(); return -1; } // 设置视口参数 glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); // Section1 准备顶点数据 setupQuadVAO(); preparePBO(); initColorBuffer(); // Section2 加载字体 FontResourceManager::getInstance().loadFont("arial", "../../resources/fonts/arial.ttf"); FontResourceManager::getInstance().loadASCIIChar("arial", 38, unicodeCharacters); // Section3 加载纹理 cubeTextId = TextureHelper::load2DTexture("../../resources/textures/wood.png"); initPixelText(); // Section4 准备着色器程序 Shader shader("scene.vertex", "scene.frag"); Shader textShader("text.vertex", "text.frag"); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // 开始游戏主循环 while (!glfwWindowShouldClose(window)) { GLfloat currentFrame = (GLfloat)glfwGetTime(); deltaTime = currentFrame - lastFrame; lastFrame = currentFrame; glfwPollEvents(); // 处理例如鼠标 键盘等事件 do_movement(); // 根据用户操作情况 更新相机属性 // 清除颜色缓冲区 重置为指定颜色 glClearColor(0.18f, 0.04f, 0.14f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glm::mat4 projection; glm::mat4 view; glm::mat4 model; // 这里填写场景绘制代码 // 先绘制纹理图片 shader.use(); glUniformMatrix4fv(glGetUniformLocation(shader.programId, "projection"), 1, GL_FALSE, glm::value_ptr(projection)); glUniformMatrix4fv(glGetUniformLocation(shader.programId, "view"), 1, GL_FALSE, glm::value_ptr(view)); model = glm::mat4(); glUniformMatrix4fv(glGetUniformLocation(shader.programId, "model"), 1, GL_FALSE, glm::value_ptr(model)); if (!isFirstRendered) { renderInitScene(shader); isFirstRendered = true; } else { renderScene(shader); } // 在右侧绘制信息文字 否则左侧文字会复制到右侧 textShader.use(); projection = glm::ortho(0.0f, (GLfloat)(SINGLE_SCREEN_WIDTH), 0.0f, (GLfloat)SINGLE_SCREEN_HEIGHT); view = glm::mat4(); glUniformMatrix4fv(glGetUniformLocation(textShader.programId, "projection"), 1, GL_FALSE, glm::value_ptr(projection)); glUniformMatrix4fv(glGetUniformLocation(textShader.programId, "view"), 1, GL_FALSE, glm::value_ptr(view)); model = glm::mat4(); glUniformMatrix4fv(glGetUniformLocation(textShader.programId, "model"), 1, GL_FALSE, glm::value_ptr(model)); renderInfo(textShader); printTransferRate(); glBindVertexArray(0); glUseProgram(0); glfwSwapBuffers(window); // 交换缓存 } // 释放资源 glDeleteVertexArrays(1, &quadVAOId); glDeleteBuffers(1, &quadVBOId); glDeleteVertexArrays(1, &textVAOId); glDeleteBuffers(1, &textVBOId); glDeleteBuffers(2, PBOIds); // 注意释放PBO releaseColorBuffer(); glfwTerminate(); return 0; }
/** Drawing main scene and bounding box */ inline void drawScene() { // [7]----[6] // / | /| // [3]----[2] | // | [4]--|-[5] // | / | / // [0]----[1] Vector3D vcenter(0,0,0); Vector3D vbox[8]; float s_v = 1 /(simulationScale);// = 1 m in simulation float order = 0; while(s_v >= 1){ s_v /= 10; if(s_v < 1) { s_v *= 10; break; } ++order; } vbox[0] = Vector3D(localConfig->xmin,localConfig->ymin,localConfig->zmin); vbox[1] = Vector3D(localConfig->xmax,localConfig->ymin,localConfig->zmin); vbox[2] = Vector3D(localConfig->xmax,localConfig->ymax,localConfig->zmin); vbox[3] = Vector3D(localConfig->xmin,localConfig->ymax,localConfig->zmin); vbox[4] = Vector3D(localConfig->xmin,localConfig->ymin,localConfig->zmax); vbox[5] = Vector3D(localConfig->xmax,localConfig->ymin,localConfig->zmax); vbox[6] = Vector3D(localConfig->xmax,localConfig->ymax,localConfig->zmax); vbox[7] = Vector3D(localConfig->xmin,localConfig->ymax,localConfig->zmax); // Display user interface if enabled bool displayInfos = true; if (displayInfos) { glDisable(GL_DEPTH_TEST); glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); // invert color glEnable(GL_BLEND); renderInfo(0, 0); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); } glBegin(GL_LINES); sc *=10; glColor3ub(255, 0, 0); glVertex3d(vcenter.x,vcenter.y,vcenter.z); glVertex3d(vcenter.x+sc,vcenter.y,vcenter.z); glColor3ub(0,255, 0); glVertex3d(vcenter.x,vcenter.y,vcenter.z); glVertex3d(vcenter.x,vcenter.y+sc,vcenter.z); glColor3ub(0, 0, 255); glVertex3d(vcenter.x,vcenter.y,vcenter.z); glVertex3d(vcenter.x,vcenter.y,vcenter.z+sc); sc /=10; vcenter = Vector3D(-(localConfig->xmin+localConfig->xmax)/2,-(localConfig->ymin+localConfig->ymax)/2,-(localConfig->zmin+localConfig->zmax)/2); vcenter *= sc; Vector3D v1,v2,v3,v4,v5,v6,v7,v8; v1 = Vector3D( -localConfig->xmax/2, -localConfig->ymax/2, -localConfig->zmax/2)*sc; v2 = Vector3D( localConfig->xmax/2, -localConfig->ymax/2, -localConfig->zmax/2)*sc; v3 = Vector3D( localConfig->xmax/2, localConfig->ymax/2, -localConfig->zmax/2)*sc; v4 = Vector3D( -localConfig->xmax/2, localConfig->ymax/2, -localConfig->zmax/2)*sc; v5 = Vector3D( -localConfig->xmax/2, -localConfig->ymax/2, localConfig->zmax/2)*sc; v6 = Vector3D( localConfig->xmax/2, -localConfig->ymax/2, localConfig->zmax/2)*sc; v7 = Vector3D( localConfig->xmax/2, localConfig->ymax/2, localConfig->zmax/2)*sc; v8 = Vector3D( -localConfig->xmax/2, localConfig->ymax/2, localConfig->zmax/2)*sc; glColor3ub(255,255,255);//yellow glVertex3d(v1.x,v1.y,v1.z); glVertex3d(v2.x,v2.y,v2.z); glColor3ub(255,255,255);//yellow glVertex3d(v2.x,v2.y,v2.z); glVertex3d(v3.x,v3.y,v3.z); glVertex3d(v3.x,v3.y,v3.z); glVertex3d(v4.x,v4.y,v4.z); glVertex3d(v4.x,v4.y,v4.z); //glColor3ub(0,255,0);//green glVertex3d(v1.x,v1.y,v1.z); //glColor3ub(0,0,255);//blue glVertex3d(v1.x,v1.y,v1.z); //glColor3ub(255,255,0);//yellow glVertex3d(v5.x,v5.y,v5.z); glVertex3d(v2.x,v2.y,v2.z); glVertex3d(v6.x,v6.y,v6.z); glVertex3d(v3.x,v3.y,v3.z); glVertex3d(v7.x,v7.y,v7.z); glVertex3d(v4.x,v4.y,v4.z); glVertex3d(v8.x,v8.y,v8.z); glVertex3d(v5.x,v5.y,v5.z); glVertex3d(v6.x,v6.y,v6.z); glVertex3d(v6.x,v6.y,v6.z); glVertex3d(v7.x,v7.y,v7.z); glVertex3d(v7.x,v7.y,v7.z); glVertex3d(v8.x + s_v*sc,v8.y,v8.z); glVertex3d(v8.x,v8.y,v8.z); glVertex3d(v5.x,v5.y,v5.z); glEnd(); // glBegin(GL_LINES); glColor3ub(0,0,0);//black Vector3D v_s = Vector3D( -localConfig->xmax/2 + s_v, localConfig->ymax/2, localConfig->zmax/2)*sc; glVertex3d(v_s.x, v_s.y, v_s.z); glVertex3d(v_s.x, v_s.y - 0.5f * sc , v_s.z); glLineWidth((GLfloat)10.0); glVertex3d( v8.x, v8.y, v8.z); glVertex3d(v_s.x, v_s.y, v_s.z); glEnd(); glLineWidth((GLfloat)1.0); void * m_font = GLUT_BITMAP_8_BY_13; std::stringstream ss; std::string s; ss << order; s = "1E-" + ss.str() + "m"; glPrint3D( (float)v8.x + 0.4f*sc , (float)v8.y - 2.f * sc, (float)v8.z, "0", m_font); glPrint3D( (float)v_s.x , (float)v_s.y - 2.f * sc, (float)v_s.z, s.c_str(), m_font); ss.str(""); while(v_s.x < localConfig->xmax/2*sc){ v_s.x += s_v * sc; if(v_s.x < localConfig->xmax/2*sc){ glBegin(GL_LINES); glVertex3d(v_s.x, v_s.y, v_s.z); glVertex3d(v_s.x, v_s.y - 0.5f * sc , v_s.z); glEnd(); } } }