Guest User

Untitled

a guest
Feb 21st, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.23 KB | None | 0 0
  1. #include <Scene/Scene.h>
  2. #include <Input/Input.h>
  3. #include <Scene/ComponentMeshRenderer.h>
  4. #include <Graphics/OpenGL/DeviceOpenGL.h>
  5. #include <Graphics/OpenGL/WindowOpenGLSDL.h>
  6.  
  7. #include <Editor/Editor.h>
  8. #include <Profiling/Profiling.h>
  9.  
  10. #include <Input/EventSystem.h>
  11.  
  12. //#include <Graphics/Vulkan/InstanceVulkan.h>
  13.  
  14. using namespace Columbus;
  15.  
  16. #include <imgui/imgui.h>
  17. #include <imgui/examples/imgui_impl_opengl3.h>
  18. #include <imgui/examples/imgui_impl_sdl.h>
  19. #include <ImGuizmo/ImGuizmo.h>
  20.  
  21. #include <Windows.h>
  22. #include <Lib\GLEW\include\GL\wglew.h>
  23.  
  24. #include <Graphics/OpenGL/ShaderOpenGL.h>
  25.  
  26. #ifdef PLATFORM_WINDOWS
  27. //Hint to the driver to use discrete GPU
  28. extern "C"
  29. {
  30.     //NVIDIA
  31.     __declspec(dllexport) int NvOptimusEnablement = 1;
  32.     //AMD
  33.     __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
  34. }
  35. #endif
  36.  
  37. //#define COLUMBUS_EDITOR
  38.  
  39. HWND hwnd;
  40. HDC hdc;
  41. HGLRC hrc;
  42.  
  43. bool quit = false;
  44. const char* class_name = "Columbus Engine Window Class";
  45.  
  46. LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wparam, LPARAM lparam)
  47. {
  48.     switch (msg)
  49.     {
  50.     default:
  51.         DefWindowProc(hWnd, msg, wparam, lparam);
  52.     }
  53.  
  54.     return 0;
  55. }
  56.  
  57. #define main main
  58. int main(int argc, char** argv)
  59. {
  60.     HINSTANCE hInstance = GetModuleHandle(0);
  61.  
  62.     WNDCLASS wc = { 0 };
  63.     wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
  64.     wc.lpfnWndProc = WndProc;
  65.     wc.cbClsExtra = 0;
  66.     wc.cbWndExtra = 0;
  67.     wc.hInstance = hInstance;
  68.     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  69.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  70.     wc.lpszMenuName = NULL;
  71.     wc.lpszClassName = class_name;
  72.     if (!RegisterClass(&wc))
  73.         COLUMBUS_ASSERT(false);
  74.  
  75.     hwnd = CreateWindow(class_name, "Columbus Engine", WS_OVERLAPPEDWINDOW, 0, 0, 640, 480, 0, 0, hInstance, 0);
  76.  
  77.     PIXELFORMATDESCRIPTOR pfd;
  78.     memset(&pfd, 0, sizeof(pfd));
  79.     pfd.nSize = sizeof(pfd);
  80.     pfd.nVersion = 1;
  81.     pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
  82.     pfd.iPixelType = PFD_TYPE_RGBA;
  83.     pfd.cColorBits = 32;
  84.     pfd.cDepthBits = 24;
  85.     pfd.cStencilBits = 8;
  86.     pfd.iLayerType = PFD_MAIN_PLANE;
  87.  
  88.     hdc = GetDC(hwnd);
  89.  
  90.     int fmt = ChoosePixelFormat(hdc, &pfd);
  91.     COLUMBUS_ASSERT(fmt != 0);
  92.     if (SetPixelFormat(hdc, fmt, &pfd) != TRUE) COLUMBUS_ASSERT(false);
  93.  
  94.     hrc = wglCreateContext(hdc);
  95.     wglMakeCurrent(hdc, hrc);
  96.  
  97.     printf("%s\n", glGetString(GL_VERSION));
  98.  
  99.     SetWindowLongA(hwnd, GWLP_WNDPROC, (LONG)&WndProc);
  100.     ShowWindow(hwnd, SW_NORMAL);
  101.  
  102.     glewInit();
  103.     gDevice = new DeviceOpenGL();
  104.     gDevice->Initialize();
  105.  
  106.     auto tex = gDevice->CreateTexture();
  107.     tex->Load("Data/Skyboxes/Dawn.exr");
  108.     auto sky = new Skybox(tex);
  109.  
  110.     ScreenQuad q;
  111.     MSG msg;
  112.     while (!quit)
  113.     {
  114.         if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
  115.         {
  116.             TranslateMessage(&msg);
  117.             DispatchMessage(&msg);
  118.             if (msg.message == WM_QUIT) quit = true;
  119.         }
  120.         else
  121.         {
  122.             glClearColor(1, 0, 0, 1);
  123.             glClear(GL_COLOR_BUFFER_BIT);
  124.  
  125.             /*glBegin(GL_TRIANGLES);
  126.                 glVertex2f(-1, 0);
  127.                 glVertex2f(1, 0);
  128.                 glVertex2f(0, 1);
  129.             glEnd();*/
  130.  
  131.             glViewport(0, 0, 640, 480);
  132.             //((TextureOpenGL*)tex)->Bind();
  133.             //asd->Bind()
  134.             Camera cam;
  135.             cam.Perspective(60, 640.0f / 480.0f, 0.1, 1000);
  136.             cam.Update();
  137.             sky->SetCamera(cam);
  138.             sky->Render();
  139.  
  140.             SwapBuffers(hdc);
  141.         }
  142.     }
  143.  
  144.     return 0;
  145. }
Advertisement
Add Comment
Please, Sign In to add comment