void CGameServer::Render() { TPROF("CGameServer::Render"); if (!GetCameraManager()) return; GetCameraManager()->Think(); GameWindow()->GetGameRenderer()->Render(); }
void CToyEditor::MouseMotion(int x, int y) { if (m_bRotatingPreview) { int lx, ly; if (GameWindow()->GetLastMouse(lx, ly)) { m_angPreview.y += (float)(x-lx); m_angPreview.p -= (float)(y-ly); } } }
int main(int argc, char** argv) { std::cerr << "Startup..." << std::endl; try { GameWindow window = GameWindow(640, 400, false); InputManager* input_manager = window.get_input_manager(); window.use_context(); glClearColor(0.25f, 0.50f, 1.0f, 1.0f); float r, g, b; r = g = b = 0.0f; while (window.check_close() == false) { // Little basic colour change test. r += 0.001; g += 0.01; b += 0.1; if (r >= 1.0f) r = 0.0f; if (g >= 1.0f) g = 0.0f; if (b >= 1.0f) b = 0.0f; glClearColor(r, g, b, 0.8f); glClear(GL_COLOR_BUFFER_BIT); window.swap_buffers(); SDL_Delay(0); GameWindow::update(); if (input_manager->is_key_down(SDLK_ESCAPE) && input_manager->is_key_down(SDLK_LSHIFT)) { std::cerr << "Shift+Escape pressed!" << std::endl; break; } } } catch (GameWindow::InitException e) { std::cerr << e.what() << std::endl; } std::cerr << "Terminate" << std::endl; return 0; }
void CSystemInstance::Render(CGameRenderingContext* c) { for (size_t i = 0; i < m_apChildren.size(); i++) m_apChildren[i]->Render(c); CGameRenderer* pRenderer = GameWindow()->GetGameRenderer(); Vector vecForward, vecRight, vecUp; pRenderer->GetCameraVectors(&vecForward, &vecRight, &vecUp); if (m_pSystem->GetMaterial()) c->UseMaterial(m_pSystem->GetMaterial()); c->SetBlend(m_pSystem->GetBlend()); for (size_t i = 0; i < m_aParticles.size(); i++) { CParticle* pParticle = &m_aParticles[i]; if (!pParticle->m_bActive) continue; if (m_pSystem->GetModel()) { c->SetUniform("flAlpha", pParticle->m_flAlpha); if (m_bColorOverride) c->SetColor(m_clrOverride); else c->SetColor(m_pSystem->GetColor()); c->Translate(pParticle->m_vecOrigin); c->Rotate(-pParticle->m_angAngles.y, Vector(0, 1, 0)); c->Rotate(pParticle->m_angAngles.p, Vector(0, 0, 1)); c->Rotate(pParticle->m_angAngles.r, Vector(1, 0, 0)); c->Scale(pParticle->m_flRadius, pParticle->m_flRadius, pParticle->m_flRadius); c->RenderModel(m_pSystem->GetModel()); c->ResetTransformations(); } else { float flRadius = pParticle->m_flRadius; Vector vecOrigin = pParticle->m_vecOrigin; Vector vecParticleUp, vecParticleRight; if (fabs(pParticle->m_flBillboardYaw) > 0.01f) { float flYaw = pParticle->m_flBillboardYaw*M_PI/180; float flSin = sin(flYaw); float flCos = cos(flYaw); vecParticleUp = (flCos*vecUp + flSin*vecRight)*flRadius; vecParticleRight = (flCos*vecRight - flSin*vecUp)*flRadius; } else { vecParticleUp = vecUp*flRadius; vecParticleRight = vecRight*flRadius; } Vector vecTL = vecOrigin - vecParticleRight + vecParticleUp; Vector vecTR = vecOrigin + vecParticleRight + vecParticleUp; Vector vecBL = vecOrigin - vecParticleRight - vecParticleUp; Vector vecBR = vecOrigin + vecParticleRight - vecParticleUp; c->SetUniform("flAlpha", pParticle->m_flAlpha); if (m_bColorOverride) c->SetColor(m_clrOverride); else c->SetColor(m_pSystem->GetColor()); c->BeginRenderTriFan(); c->TexCoord(0.0f, 1.0f); c->Vertex(vecTL); c->TexCoord(0.0f, 0.0f); c->Vertex(vecBL); c->TexCoord(1.0f, 0.0f); c->Vertex(vecBR); c->TexCoord(1.0f, 1.0f); c->Vertex(vecTR); c->EndRender(); } } }
void CSystemInstance::Render(CGameRenderingContext* c, bool bTransparent) { for (size_t i = 0; i < m_apChildren.size(); i++) m_apChildren[i]->Render(c, bTransparent); if (m_pSystem->GetBlend() == BLEND_NONE && bTransparent) return; if (m_pSystem->GetBlend() != BLEND_NONE && !bTransparent) return; CGameRenderer* pRenderer = GameWindow()->GetGameRenderer(); if (particles_debug.GetBool()) { CRenderingContext c(pRenderer, true); c.UseProgram("debug"); c.SetUniform("vecColor", Color(1.0, 1.0, 1.0, 1.0f)); c.ResetTransformations(); c.RenderWireBox(m_aabbBounds); } if (!pRenderer->IsSphereInFrustum(m_aabbBounds.Center(), m_aabbBounds.Size().Length() / 2)) return; Vector vecForward, vecLeft, vecUp; pRenderer->GetCameraVectors(&vecForward, &vecLeft, &vecUp); if (m_pSystem->GetMaterial()) c->UseMaterial(m_pSystem->GetMaterial()); c->SetBlend(m_pSystem->GetBlend()); Color clrParticle = m_pSystem->GetColor(); if (m_bColorOverride) clrParticle = m_clrOverride; if (m_pSystem->GetModel()) { int iRadius = c->GetUniform("flRadius"); for (size_t i = 0; i < m_aParticles.size(); i++) { CParticle* pParticle = &m_aParticles[i]; if (!pParticle->m_bActive) continue; c->SetUniform(iRadius, pParticle->m_flAlpha); c->SetColor(clrParticle); c->Translate(pParticle->m_vecOrigin); c->Rotate(-pParticle->m_angAngles.y, Vector(0, 0, 1)); c->Rotate(pParticle->m_angAngles.p, Vector(0, 1, 0)); c->Rotate(pParticle->m_angAngles.r, Vector(1, 0, 0)); c->Scale(pParticle->m_flRadius, pParticle->m_flRadius, pParticle->m_flRadius); c->RenderModel(m_pSystem->GetModel()); c->ResetTransformations(); } } else { c->SetUniform("vecCameraPosition", GameServer()->GetRenderer()->GetCameraPosition()); size_t iQuadVBO = CParticleSystemLibrary::Get()->GetQuadVBO(); size_t iQuadVBOSize = CParticleSystemLibrary::Get()->GetQuadVBOSize(); int iOrigin = c->GetUniform("vecOrigin"); int iAlpha = c->GetUniform("flAlpha"); int iRadius = c->GetUniform("flRadius"); int iYaw = c->GetUniform("flYaw"); int iColor = c->GetUniform("vecColor"); for (size_t i = 0; i < m_aParticles.size(); i++) { CParticle* pParticle = &m_aParticles[i]; if (!pParticle->m_bActive) continue; c->SetUniform(iOrigin, pParticle->m_vecOrigin); c->SetUniform(iAlpha, pParticle->m_flAlpha); c->SetUniform(iRadius, pParticle->m_flRadius); c->SetUniform(iYaw, (float)(pParticle->m_flBillboardYaw*M_PI/180)); c->SetUniform(iColor, clrParticle); c->BeginRenderVertexArray(iQuadVBO); c->SetPositionBuffer(0u, 20); c->SetTexCoordBuffer(12, 20); c->EndRenderVertexArray(iQuadVBOSize); } } }
int main(int argc, char** argv) { std::cerr << "Startup..." << std::endl; try { GameWindow window = GameWindow(640, 400, false); InputManager* input_manager = window.get_input_manager(); window.use_context(); glClearColor(0.25f, 0.50f, 1.0f, 1.0f); float r, g, b; r = g = b = 0.0f; Callback<void, KeyboardInputEvent> release_callback([&] (KeyboardInputEvent event) { callback_function(".#.", event); }); Callback<void, KeyboardInputEvent> down_callback([&] (KeyboardInputEvent event) { callback_function("...", event); }); Callback<void, KeyboardInputEvent> type_callback([&] (KeyboardInputEvent event) { callback_function(".*.", event); }); Callback<void, KeyboardInputEvent> press_callback([&] (KeyboardInputEvent event) { if (event.key_code == SDLK_ESCAPE) { release_callback.unregister_everywhere(); down_callback.unregister_everywhere(); type_callback.unregister_everywhere(); press_callback.unregister_everywhere(); } else { callback_function("._.", event); } }); { Lifeline press_lifeline = input_manager->register_key_press_handler([&] (KeyboardInputEvent event) { callback_function("!!!", event); }); } input_manager->register_key_release_handler(release_callback); input_manager->register_key_down_handler(down_callback); input_manager->register_key_type_handler(type_callback); input_manager->register_key_press_handler(press_callback); Typeface typeface("font.ttf"); TextFont font(typeface, 12); Text text(&window, font, true); text.move(100, 1000); // text.set_text("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n\nThis_line_is_supposedly_very_long_and_should_not_render_properly! A B C"); text.set_text(load_file("UTF-8-test.txt")); // for (int i = 0; i < 1000; i++) { // text.resize(500, 400 + (i % 2)); // text.display(); // } text.resize(800, 1000); text.display(); TextFont big_font(typeface, 50); Text cursor(&window, big_font, true); cursor.move(100, 100); cursor.resize(50, 60); // Can ya tell what it is yet? cursor.set_text({0xe2, 0x99, 0x98, 0x0}); // Lifeline mouse_lifeline = input_manager->register_mouse_handler(&mouse_callback_function); Lifeline mouse_button_lifeline = input_manager->register_mouse_handler(filter({MOUSE_CLICKED}, &mouse_callback_function)); Lifeline cursor_lifeline = input_manager->register_mouse_handler(filter({MOUSE_MOVE}, [&] (MouseInputEvent event) {cursor.move(event.to.x, event.to.y);})); while (window.check_close() == false) { // Little basic colour change test. r += 0.001; g += 0.01; b += 0.1; if (r >= 1.0f) r = 0.0f; if (g >= 1.0f) g = 0.0f; if (b >= 1.0f) b = 0.0f; glViewport(0, 0, window.get_size().first, window.get_size().second); glClearColor(r, g, b, 0.8f); glClear(GL_COLOR_BUFFER_BIT); text.display(); cursor.display(); window.swap_buffers(); SDL_Delay(0); GameWindow::update(); if (input_manager->is_key_down(SDLK_ESCAPE) && input_manager->is_key_down(SDLK_LSHIFT)) { std::cerr << "Shift+Escape pressed!" << std::endl; break; } } release_callback.unregister_everywhere(); down_callback.unregister_everywhere(); type_callback.unregister_everywhere(); press_callback.unregister_everywhere(); } catch (GameWindow::InitException e) { std::cerr << e.what() << std::endl; } std::cerr << "Terminate" << std::endl; return 0; }
CGameRenderer* CGameServer::GetRenderer() { return static_cast<CGameRenderer*>(GameWindow()->GetRenderer()); }