void GameObject::Draw() { if (this->visible) { this->transform->Draw(); #if USING_RUNTIME_COMPUTED_BONE_MATRICES // TODO [Cleanup] Cache the Armature, maybe Armature* armature = this->GetComponent<Armature>(); if (armature != nullptr) { armature->Bind(); } #elif USING_BAKED_BONE_MATRICES // TODO [Cleanup] Cache the BakedSkeletalAnimation component, maybe BakedSkeletalAnimation* bakedSkeletalAnimation = this->GetComponent<BakedSkeletalAnimation>(); if (bakedSkeletalAnimation != nullptr) { bakedSkeletalAnimation->Bind(); } #endif // TODO [Cleanup] Cache the Renderer, maybe Renderer* renderer = this->GetComponent<Renderer>(); if (renderer != nullptr) { renderer->Draw(); } } }
void Entity2D::drawAABB(Renderer& rkRenderer) const { static ColorVertex s_akAABBVertices[5]; static bool s_bIsInitialized = false; if(!s_bIsInitialized){ s_bIsInitialized = true; s_akAABBVertices[0].x = -0.5; s_akAABBVertices[0].y = -0.5; s_akAABBVertices[0].z = 0.0; s_akAABBVertices[0].color =Inaba_COLOR_RGB(255,50,50); s_akAABBVertices[1].x = -0.5; s_akAABBVertices[1].y = 0.5; s_akAABBVertices[1].z = 0.0; s_akAABBVertices[1].color = Inaba_COLOR_RGB(255,70,70); s_akAABBVertices[2].x = 0.5; s_akAABBVertices[2].y = 0.5; s_akAABBVertices[2].z = 0.0; s_akAABBVertices[2].color = Inaba_COLOR_RGB(255,30,30); s_akAABBVertices[3].x = 0.5; s_akAABBVertices[3].y = -0.5; s_akAABBVertices[3].z = 0.0; s_akAABBVertices[3].color = Inaba_COLOR_RGB(255,15,15); s_akAABBVertices[4].x = -0.5; s_akAABBVertices[4].y = -0.5; s_akAABBVertices[4].z = 0.0; s_akAABBVertices[4].color = Inaba_COLOR_RGB(255,95,90); } rkRenderer.setCurrentTexture(NoTexture); rkRenderer.setMatrix(World, _transformationMatrix ); rkRenderer.Draw(s_akAABBVertices, Inaba::LineStrip, 5); }
//---------------------------------------------------------------------------- Int main(Int argc, Char** argv) { Main::Initialize(); PdrRendererInput input; const Bool useVSync = true; // window width/height and windowed mode not supported on the Wii Renderer* pRenderer = WIRE_NEW Renderer(input, 0, 0, true, useVSync); // Renderer must be created before calling PADInit PADInit(); RenderObjectPtr spCube = StandardMesh::CreateCube8(/* RGB(A) channels */ 4); Vector3F cameraLocation(0.0F, 0.0F, 10.0F); Vector3F viewDirection(0.0F, 0.0F, -1.0F); Vector3F up(0.0F, 1.0F, 0.0F); CameraPtr spCamera = WIRE_NEW Camera(cameraLocation, viewDirection, up); do { Transformation transformation; Matrix34F rotate(Vector3F(0.2F, 0.7F, 0.1F), MathF::FMod( static_cast<Float>(System::GetTime()), MathF::TWO_PI)); transformation.SetRotate(rotate); pRenderer->ClearBuffers(); pRenderer->PreDraw(spCamera); pRenderer->Draw(spCube, transformation); pRenderer->PostDraw(); pRenderer->DisplayBackBuffer(); WPAD_ScanPads(); } while (!(WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME)); // dereference (i.e. destroy) before destroying the renderer spCamera = NULL; spCube = NULL; WIRE_DELETE pRenderer; Main::Terminate(); return 0; }
//---------------------------------------------------------------------------- void Node::Draw (Renderer& rkRenderer, bool bNoCull) { if (m_spkEffect == 0) { for (int i = 0; i < m_kChild.GetQuantity(); i++) { Spatial* pkChild = m_kChild[i]; if (pkChild) { pkChild->OnDraw(rkRenderer,bNoCull); } } } else { // A "global" effect might require multipass rendering, so the Node // must be passed to the renderer for special handling. rkRenderer.Draw(this); } }
int CALLBACK WinMain(HINSTANCE _hInstance, HINSTANCE _hPrevInstance, LPSTR _lpCmdLine, int _nCmdShow) { Window Window; Window.Initialize(_hInstance, _nCmdShow); Window.Create(Platform::Window::eWindow_Mode_Normal, L"FTL Engine", 0, 0, 1024, 768); RendererDLL rendererDLL; Renderer* pRenderer; rendererDLL.Create(&pRenderer); { Graphics::Renderer::Settings Settings; Settings.nWidth = 1024; Settings.nHeight = 768; Settings.nRefreshRate = 0; Settings.nMSAASamples = 1; Settings.nSampleQuality = 0; Settings.nBufferCount = 1; Settings.eDriverMode = Graphics::Renderer::eDriverMode_Hardware; Settings.hOutput = Window.GetHandle(); Settings.bDebugMode = true; pRenderer->Initialize(Settings); pRenderer->Startup(); { // Shaders Graphics::HShader VertexShader = pRenderer->CompileFromFile(L"Source/Shader.hlsl", "VShader", Graphics::Shader::eSHADER_TYPE_VERTEX); Graphics::HShader PixelShader = pRenderer->CompileFromFile(L"Source/Shader.hlsl", "PShader", Graphics::Shader::eSHADER_TYPE_PIXEL); // Vertex Format Graphics::VertexFormat::VertDataPair VertFormat[2] = { { Graphics::VertexFormat::eSEMANTICS_POSITION, Graphics::VertexFormat::eDATASIZES_FLOAT3}, { Graphics::VertexFormat::eSEMANTICS_COLOR, Graphics::VertexFormat::eDATASIZES_FLOAT4}, }; Graphics::HVertexFormat hVertexFormat = pRenderer->CreateVertexFormat(VertFormat, 2); // Vertex Buffer Vertex VertexBuffer[] = { { 0.00f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f}, { 0.45f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, {-0.45f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f}, }; Graphics::HVertexBuffer hVertexBuffer = pRenderer->CreateVertexBuffer(3, &VertexBuffer, hVertexFormat); // Index Buffer uint32 IntexBuffer[] = { 0, 1, 2, }; Graphics::HIndexBuffer hIndexBuffer = pRenderer->CreateIndexBuffer(3, IntexBuffer); // Activate Settings VertexShader->SetShaderActive(); PixelShader->SetShaderActive(); hVertexBuffer->SetBufferActive(); hIndexBuffer->SetBufferActive(); pRenderer->SetPrimitiveTopology(Graphics::Primitive::eTOPOLOGY_TRIANGLELIST); //while(Window.Update()) Window.Update(); { float Color[4] = {0.33f, 0.33f, 0.33f, 1.00f}; pRenderer->ClearBackBuffer(Color); pRenderer->Draw(3, 0, 0); pRenderer->Present(); } Window.Update(); } pRenderer->Shutdown(); } rendererDLL.Release(); return NULL; }
void Quad::Draw(Renderer& renderer) const { renderer.setCurrentTexture(NoTexture); renderer.setMatrix(World,_transformationMatrix); renderer.Draw(_vertex,Inaba::TriangleStrip, 4); }
int main() { glfwInit(); // Initialisoidaan GLFW // GLFW perusasetukset glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); // asetetaan OpenGL- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); // versio 2.1 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE); // määritellään OpenGL profiili käytettäväksi glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); // ikkunan kokoa ei voi muuttaa // luodaan ikkuna GLFWwindow GLFWwindow* window = glfwCreateWindow(width, height, "EPELIROOTTORI", nullptr, nullptr); glfwMakeContextCurrent(window); glfwSetKeyCallback(window, key_callback); glewExperimental = GL_TRUE; glewInit(); // Initialisoidaan GLEW glViewport(0, 0, width, height); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); Renderer renderer = { glm::vec2(width, height) }; Renderer renderer2 = { glm::vec2(width * 2, height * 2) }; Renderer renderer3 = { glm::vec2(width * 4, height * 4) }; AnimationManager anima; TextManager tex; tex.LoadFont("..//data/fonts/arial.ttf"); tex.SetText("0"); tex.SetCharacterSize(30); tex.SetPosition(glm::vec2(10, 0)); tex.SetColor(glm::vec3(0.0, 0.0, 1.0)); TextManager tex2; tex2.LoadFont("..//data/fonts/arial.ttf"); tex2.SetText("0"); tex2.SetCharacterSize(30); tex2.SetPosition(glm::vec2(width - tex2.GetGlobalBounds().x, 0)); tex2.SetColor(glm::vec3(0.0, 1.0, 0.0)); TextManager tex3; tex3.LoadFont("..//data/fonts/Arctik5.ttf"); tex3.SetText("Pong"); tex3.SetCharacterSize(30); tex3.SetPosition(glm::vec2(width / 2.5, 0)); tex3.SetColor(glm::vec3(0.0, 0.0, 0.0)); Sprite typhlosion; typhlosion.SetAnimation("../data/animations/Typhlosion2.png", glm::vec2(234, 250), 0.2); typhlosion.SetPosition(glm::vec2((width - typhlosion.GetBounds().x) / 2, (height - typhlosion.GetBounds().y) / 2)); typhlosion.SetScale(glm::vec2(0.5, 0.5)); Sprite kisse; kisse.SetTexture("../data/textures/kisse.png"); kisse.SetColor(glm::vec3(0.0, 0.0, 1.0)); kisse.SetPosition(glm::vec2(0, (height - kisse.GetBounds().y) / 2)); Sprite kisse2; kisse2.SetTexture("../data/textures/kisse.png"); kisse2.SetColor(glm::vec3(0.0, 1.0, 0.0)); kisse2.SetPosition(glm::vec2(width - kisse.GetBounds().x, (height - kisse.GetBounds().y) / 2)); Sprite animation; animation.SetAnimation("../data/animations/gems.png", "../data/animations/anim_gems.xml"); animation.SetPosition(glm::vec2((width / 2), 250)); animation.SetScale(glm::vec2(2, 2)); renderer2.camera->SetPosition(glm::vec2(1, 1)); renderer3.camera->SetPosition(glm::vec2(1.5, 1.5)); glm::vec2 dir = { 2.0, 2.0 }, dir2 = { 0.0, 1.0 }, dir3 = { 0.0, -1.0 }; int score1 = 0, score2 = 0; glm::vec3 color = { 0.01, 0.01, 0.01 }; Polygon polygon(300, 200, 1, 0, 350, 350, 1.0f, 0.4f, 0.3f, "../data/textures/planet.png"); Polygon polygon2(4, 100, 1, 0, 850, 350, 1.0f, 0.4f, 0.3f, "../data/textures/kisse.png"); Timer time; time.Start(); while (!glfwWindowShouldClose(window)) { glfwPollEvents(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearColor(0.0f, 0.2f, 0.2f, 1.0f); // Typhlosion koskettaa vasenta tai oikeaa seinää if (typhlosion.GetPosition().x > width) { typhlosion.SetPosition(glm::vec2((width - typhlosion.GetBounds().x) / 2, (height - typhlosion.GetBounds().y) / 2)); dir.x = -2.0; score1++; tex.SetText(std::to_string(score1)); } if (typhlosion.GetPosition().x + typhlosion.GetGlobalBounds().x < 0) { typhlosion.SetPosition(glm::vec2((width - typhlosion.GetBounds().x) / 2, (height - typhlosion.GetBounds().y) / 2)); dir.x = 2.0; score2++; tex2.SetText(std::to_string(score2)); tex2.SetPosition(glm::vec2(width - tex2.GetGlobalBounds().x, 0)); } // Typhlosion kimpoaa katosta ja lattiasta if (typhlosion.GetPosition().y + typhlosion.GetGlobalBounds().y > height) { dir.y = -2.0; } if (typhlosion.GetPosition().y < 0) { dir.y = 2.0; } // Typhlosion törmää kisseien sivuihin // kisse1 if (kisse.GetPosition().y + kisse.GetGlobalBounds().y > typhlosion.GetPosition().y && kisse.GetPosition().y + kisse.GetGlobalBounds().y - 5 < typhlosion.GetPosition().y && kisse.GetPosition().x < typhlosion.GetPosition().x && kisse.GetPosition().x + kisse.GetGlobalBounds().x > typhlosion.GetPosition().x || kisse.GetPosition().y + kisse.GetGlobalBounds().y > typhlosion.GetPosition().y && kisse.GetPosition().y + kisse.GetGlobalBounds().y - 5 < typhlosion.GetPosition().y && kisse.GetPosition().x < typhlosion.GetPosition().x + typhlosion.GetGlobalBounds().x && kisse.GetPosition().x + kisse.GetGlobalBounds().x > typhlosion.GetPosition().x + typhlosion.GetGlobalBounds().x) { dir.y = 2.0; } else if (kisse.GetPosition().y < typhlosion.GetPosition().y + typhlosion.GetGlobalBounds().y && kisse.GetPosition().y + 5 > typhlosion.GetPosition().y + typhlosion.GetGlobalBounds().y && kisse.GetPosition().x < typhlosion.GetPosition().x && kisse.GetPosition().x + kisse.GetGlobalBounds().x > typhlosion.GetPosition().x || kisse.GetPosition().y < typhlosion.GetPosition().y + typhlosion.GetGlobalBounds().y && kisse.GetPosition().y + 5 > typhlosion.GetPosition().y + typhlosion.GetGlobalBounds().y && kisse.GetPosition().x < typhlosion.GetPosition().x + typhlosion.GetGlobalBounds().x && kisse.GetPosition().x + kisse.GetGlobalBounds().x > typhlosion.GetPosition().x + typhlosion.GetGlobalBounds().x) { dir.y = -2.0; } else if (kisse.GetPosition().x + kisse.GetGlobalBounds().x > typhlosion.GetPosition().x && kisse.GetPosition().y < typhlosion.GetPosition().y && kisse.GetPosition().y + kisse.GetGlobalBounds().y > typhlosion.GetPosition().y || kisse.GetPosition().x + kisse.GetGlobalBounds().x > typhlosion.GetPosition().x && kisse.GetPosition().y < typhlosion.GetPosition().y + typhlosion.GetGlobalBounds().y && kisse.GetPosition().y + kisse.GetGlobalBounds().y > typhlosion.GetPosition().y + typhlosion.GetGlobalBounds().y) { dir.x = 2.0; } // Typhlosion törmää kisseien sivuihin // kisse2 if (kisse2.GetPosition().y + kisse2.GetGlobalBounds().y > typhlosion.GetPosition().y && kisse2.GetPosition().y + kisse2.GetGlobalBounds().y - 5 < typhlosion.GetPosition().y && kisse2.GetPosition().x < typhlosion.GetPosition().x && kisse2.GetPosition().x + kisse2.GetGlobalBounds().x > typhlosion.GetPosition().x || kisse2.GetPosition().y + kisse2.GetGlobalBounds().y > typhlosion.GetPosition().y && kisse2.GetPosition().y + kisse2.GetGlobalBounds().y - 5 < typhlosion.GetPosition().y && kisse2.GetPosition().x < typhlosion.GetPosition().x + typhlosion.GetGlobalBounds().x && kisse2.GetPosition().x + kisse2.GetGlobalBounds().x > typhlosion.GetPosition().x + typhlosion.GetGlobalBounds().x) { dir.y = 2.0; } else if (kisse2.GetPosition().y < typhlosion.GetPosition().y + typhlosion.GetGlobalBounds().y && kisse2.GetPosition().y + 5 > typhlosion.GetPosition().y + typhlosion.GetGlobalBounds().y && kisse2.GetPosition().x < typhlosion.GetPosition().x && kisse2.GetPosition().x + kisse2.GetGlobalBounds().x > typhlosion.GetPosition().x || kisse2.GetPosition().y < typhlosion.GetPosition().y + typhlosion.GetGlobalBounds().y && kisse2.GetPosition().y + 5 > typhlosion.GetPosition().y + typhlosion.GetGlobalBounds().y && kisse2.GetPosition().x < typhlosion.GetPosition().x + typhlosion.GetGlobalBounds().x && kisse2.GetPosition().x + kisse2.GetGlobalBounds().x > typhlosion.GetPosition().x + typhlosion.GetGlobalBounds().x) { dir.y = -2.0; } else if (kisse2.GetPosition().x < typhlosion.GetPosition().x + typhlosion.GetGlobalBounds().x && kisse2.GetPosition().y < typhlosion.GetPosition().y && kisse2.GetPosition().y + kisse2.GetGlobalBounds().y > typhlosion.GetPosition().y || kisse2.GetPosition().x < typhlosion.GetPosition().x + typhlosion.GetGlobalBounds().x && kisse2.GetPosition().y < typhlosion.GetPosition().y + typhlosion.GetGlobalBounds().y && kisse2.GetPosition().y + kisse2.GetGlobalBounds().y > typhlosion.GetPosition().y + typhlosion.GetGlobalBounds().y) { dir.x = -2.0; } // kisse1 liikkumiset if (kisse.GetPosition().y < 0) { dir2 = { 0.0, 1.0 }; } if (kisse.GetPosition().y + kisse.GetGlobalBounds().y > height) { dir2 = { 0.0, -1.0 }; } // kisse2 liikkumiset if (kisse2.GetPosition().y < 0) { dir3 = { 0.0, 1.0 }; } if (kisse2.GetPosition().y + kisse2.GetGlobalBounds().y > height) { dir3 = { 0.0, -1.0 }; } if (tex3.GetColor().x < 0) { color = glm::vec3(0.01, 0.01, 0.01); } if (tex3.GetColor().x > 1) { color = glm::vec3(-0.01, -0.01, -0.01); } tex3.SetColor(tex3.GetColor() + color); polygon2.Rotate(1); polygon.DemoEffect(1); typhlosion.Rotate(1); typhlosion.Move(dir); kisse.Move(dir2); kisse2.Move(dir3); renderer.Draw(polygon); renderer.Draw(polygon2); renderer.Draw(typhlosion); renderer.Draw(kisse); renderer.Draw(kisse2); renderer.Draw(tex); renderer.Draw(tex2); renderer.Draw(tex3); renderer.Draw(animation); animation.GetAnimationManager()->UpdateAnimation(); typhlosion.GetAnimationManager()->UpdateAnimation(); glDisable(GL_TEXTURE_2D); glfwSwapBuffers(window); } }
void BaseDrawComponent::Draw(Renderer & renderer, const SceneNode * obj) { renderer.Draw(Renderer::SIMPLE_GL_OBJECT, obj->GetModelWorldMatrixScaled()); }
void Run(void *r) { Renderer* render = static_cast<Renderer*>(r); render->Draw(); }
int main() { Config::Init(); curl_global_init(CURL_GLOBAL_ALL); Network::Init(); sf::RenderWindow window(sf::VideoMode(Config::ScreenWidth(), Config::ScreenHeight(), 32), "TowerDefense"); srand(time(NULL)); const int tileSize = 32; Renderer r = Renderer(); SoundManager snd; snd.Init(); Level level(tileSize, sf::Vector2i(Config::ScreenWidth(), Config::ScreenHeight()), &r); Menu menu(&r, &window, &level, level.GetCam()); sf::Clock clock; float drawInterval = 0.0166f, updateInterval = 0.0043f; float drawTime = 0, updateTime = 0; bool ctrl = false, shft = false , alt = false; unsigned int modifierKeys = 0; while (window.isOpen()) { sf::Event Event; while (window.pollEvent(Event)) { if (Event.type == sf::Event::KeyPressed) { if (Event.key.code == sf::Keyboard::LControl || Event.key.code == sf::Keyboard::RControl) ctrl = true; else if (Event.key.code == sf::Keyboard::LShift || Event.key.code == sf::Keyboard::RShift) shft = true; else if (Event.key.code == sf::Keyboard::LAlt || Event.key.code == sf::Keyboard::RAlt) alt = true; } else if (Event.type == sf::Event::KeyReleased) { if (Event.key.code == sf::Keyboard::LControl || Event.key.code == sf::Keyboard::RControl) ctrl = false; else if (Event.key.code == sf::Keyboard::LShift || Event.key.code == sf::Keyboard::RShift) shft = false; else if (Event.key.code == sf::Keyboard::LAlt || Event.key.code == sf::Keyboard::RAlt) alt = false; } modifierKeys = (ctrl ? ModifierKeys::Control : 0) | (shft ? ModifierKeys::Shift : 0) | (alt ? ModifierKeys::Alt : 0); if (Event.type == sf::Event::Closed) window.close(); else if (Event.type == sf::Event::KeyPressed) { menu.ProcessInput(Event, modifierKeys); if (!menu.GamePaused()) level.ProcessInput(Event, modifierKeys); } else if (Event.type == sf::Event::MouseButtonPressed || Event.type == sf::Event::JoystickButtonPressed || Event.type == sf::Event::JoystickMoved || Event.type == sf::Event::MouseMoved) { if (!menu.ProcessInput(Event, modifierKeys)) level.ProcessInput(Event, modifierKeys); } else if (Event.type == sf::Event::KeyReleased || Event.type == sf::Event::MouseButtonReleased || Event.type == sf::Event::JoystickButtonReleased) { menu.ProcessInput(Event, modifierKeys); level.ProcessInput(Event, modifierKeys); } } float time = clock.getElapsedTime().asSeconds(); clock.restart(); drawTime += time; updateTime += time; menu.Update(); if (!menu.GamePaused()) { if (updateTime > updateInterval) { level.Update(time); level.CheckCollision(); updateTime = 0; } } if (drawTime > drawInterval) { window.clear(); level.Draw(&window); r.Draw(&window); window.display(); drawTime -= drawInterval; } } return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { //SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO); SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); SDL_Window *window = SDL_CreateWindow("Dungeon Crawler", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH, HEIGHT, SDL_WINDOW_OPENGL); if (window == nullptr) { std::cout << "Could not init Window " << SDL_GetError(); return 1; } bool running = true; //unsigned int frames = 0; // float frequency = (float) SDL_GetPerformanceFrequency(); // float totalTime = 0; // float dt = 0; Uint64 oldTime = SDL_GetPerformanceCounter(); Uint64 newTime; Renderer renderer; Game game; game.NewGame(); while (running) { //++frames; //newTime = SDL_GetPerformanceCounter(); //dt = (newTime - oldTime) / frequency; //totalTime += dt; //oldTime = newTime; SDL_Event event; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: running = false; break; default: break; } } bool const *keys = reinterpret_cast<bool const *>(SDL_GetKeyboardState(nullptr)); game.Update(keys); renderer.Draw(game); Render(window, renderer); SoundManager::Instance().Update(); #ifdef DEBUG if (frames % 100 == 0) { std::cout << "FPS: " << frames / totalTime << '\n'; } #endif SDL_Delay(2); } SDL_DestroyWindow(window); SDL_Quit(); return 0; }
//---------------------------------------------------------------------------- void Polyline::Draw (Renderer& rkRenderer) { Geometry::Draw(rkRenderer); rkRenderer.Draw(*this); }
//---------------------------------------------------------------------------- void Geometry::Draw (Renderer& rkRenderer, bool) { rkRenderer.Draw(this); }
int main() { using namespace icarus::graphics; using namespace icarus::maths; std::cout << "Hello World!" << std::endl; #if 0 std::cout << (1 - 0.3f) << std::endl; Vector4 vec(10, 10, 12, 5); Vector4 vec2(5, 5, 8, 9.3f); std::cout << vec << std::endl; std::cout << vec2 << std::endl; std::cout << vec + vec2 << std::endl; std::cout << vec * vec2 << std::endl; std::cout << vec * 2.5f << std::endl; std::cout << (vec == vec2) << std::endl; std::cout << "----------------------" << std::endl; std::cout << vec << std::endl; vec *= 5; std::cout << vec << std::endl; std::cout << (vec *= 2) << std::endl; std::cout << vec << std::endl; std::cout << "----------------------" << std::endl; Matrix4x4 mat = Matrix4x4::Identity(); Matrix4x4 mat2 = Matrix4x4::Identity(); std::cout << (mat * mat2) << std::endl; std::cout << "----------------------" << std::endl; Matrix4x4 position = Matrix4x4::Translate(2, 3, 4); std::cout << position << std::endl; Vector4& column = position.GetColumn(3); std::cout << column << std::endl; std::cout << position.elements[12] << std::endl; column.x++; std::cout << position.elements[12] << std::endl; #endif if (!glfwInit()) { return -1; } Window window("Game Engine", WIDTH, HEIGHT, true); std::cout << glGetString(GL_VERSION) << std::endl; { glClearColor(0.0f, 0.5f, 0.8f, 1.0f); GLfloat vertices[] = { //-0.5f, -0.5f, 0, //-0.5f, 0.5f, 0, // 0.5f, 0.5f, 0, // 0.5f, 0.5f, 0, // 0.5f, -0.5f, 0, //-0.5f, -0.5f, 0, 0, 0, 0, // 0 0, 3, 0, // 1 8, 3, 0, // 2 8, 0, 0, // 3 }; GLuint indicies[] = { 0, 1, 2, 2, 3, 0, }; VertexArray va; VertexBuffer vb(vertices, 4 * 3 * sizeof(GLfloat)); VertexBufferLayout layout; layout.Push<float>(3); va.AddBuffer(vb, layout); IndexBuffer ib(indicies, 6); Shader shader("src/shaders/Basic.shader"); Matrix4x4 model(1.0f); //model *= Matrix4x4::Rotate(45, 0, 0, 1); //model *= Matrix4x4::Scale(1, 0.5f, 1); //model *= Matrix4x4::Translate(4, 3, 0); //model = Matrix4x4::Identity(); Matrix4x4 view = Matrix4x4::Identity(); Matrix4x4 proj = Matrix4x4::Orthographic(0, 16, 0, 9, -1, 1); shader.Bind(); shader.SetUniformMat4f("u_MVP", proj * view * model); shader.SetUniform4f("u_Color", Vector4(0.2f, 0.3f, 0.8f, 1.0f)); shader.SetUniform2f("u_LightPos", Vector2(4, 1.5f)); Renderer renderer; ImGuiContext* imguiContext = ImGui::CreateContext(); ImGui_ImplGlfwGL3_Init(window.GetGLFWWindow(), false); ImGui::StyleColorsDark(); float r = 0.0f; float incrementR = 0.05f; float lightXPos = 4.0f; float incrementL = 0.05f; while (!window.ShouldClose()) { //std::cout << window.GetWidth() << std::endl; renderer.Clear(); ImGui_ImplGlfwGL3_NewFrame(); // 1. Show a simple window. // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug". { static float f = 0.0f; static int counter = 0; ImGui::Text("Hello, world!"); // Display some text (you can use a format string too) //ImGui::SliderFloat3("Translation", &translation.x, 0.0f, WIDTH); //ImGui::SliderFloat3("Camera", &camera.x, 0.0f, WIDTH); //ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color } shader.Bind(); model = Matrix4x4::Translate(4, 3, 0); shader.SetUniformMat4f("u_MVP", proj * view * model); shader.SetUniformMat4f("u_modelMat", model); shader.SetUniform4f("u_Color", Vector4(r, 0.3f, 0.8f, 1.0f)); double x, y; window.GetMousePosition(x, y); //shader.SetUniform2f("u_LightPos", Vector2(lightXPos, 1.5f)); shader.SetUniform2f("u_LightPos", Vector2((float)x * 16.0f / 960.0f, 9.0f - (float)y * 9.0f / 540.0f)); renderer.Draw(va, ib, shader); model = Matrix4x4::Translate(0, 0, 0); shader.SetUniformMat4f("u_MVP", proj * view * model); shader.SetUniformMat4f("u_modelMat", model); renderer.Draw(va, ib, shader); ImGui::Render(); ImGui_ImplGlfwGL3_RenderDrawData(ImGui::GetDrawData()); if (r > 1.0f) { incrementR = -0.05f; } else if (r < 0.0f) { incrementR = 0.05f; } r += incrementR; //if (lightXPos > 8.0f) { // incrementL = -0.05f; //} else if (lightXPos < 0.0f) { // incrementL = 0.05f; //} //lightXPos += incrementL; window.Update(); } } ImGui_ImplGlfwGL3_Shutdown(); ImGui::DestroyContext(); glfwTerminate(); return 0; }
void Sprite::draw(Renderer& r) const{ r.setCurrentTexture(s_Texture); r.setMatrix( World, _TrMatrix ); r.Draw(s_Vertex, DoMaRe::TriangleStrip, 4); }