Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.52 KB | None | 0 0
  1. #pragma warning(disable:4996)
  2.  
  3. #include "imgui/imgui.h"
  4. #include "imgui/imgui_impl_sdl_gl3.h"
  5. #include <glew.h>
  6. #include <SDL_opengl.h>
  7. #include <steam_api.h>
  8. #include <SDL.h>
  9. #include <iostream>
  10. #include <string>
  11.  
  12.  
  13. int main(int argc, char *argv[]) {
  14.  
  15.     if (SteamAPI_Init() == false) {
  16.         std::cout << "cant init steamAPI" << std::endl;
  17.     }
  18.  
  19.     SDL_Init(SDL_INIT_VIDEO);
  20.     SDL_Init(SDL_INIT_EVENTS);
  21.    
  22.     // gl attributes
  23.  
  24.     SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);
  25.     SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
  26.     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
  27.     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
  28.     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
  29.     SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
  30.     SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
  31.    
  32.    
  33.     SDL_Window *window = SDL_CreateWindow("Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
  34.     SDL_GLContext glcontext = SDL_GL_CreateContext(window);
  35.  
  36.     SDL_GL_SetSwapInterval(1);
  37.    
  38.     glewExperimental = GL_TRUE;
  39.  
  40.     if (GLEW_OK != glewInit()) {
  41.         std::cout << "Cant init glew!" << std::endl;
  42.     }
  43.  
  44.     glViewport(0, 0, 800, 600);
  45.  
  46.     // ImGui binding setup
  47.  
  48.     IMGUI_CHECKVERSION();
  49.     ImGui::CreateContext();
  50.     ImGuiIO& io = ImGui::GetIO(); (void)io;
  51.     io.ConfigFlags = ImGuiConfigFlags_NavEnableKeyboard;
  52.     ImGui_ImplSdlGL3_Init(window);
  53.  
  54.  
  55.     // Style setup
  56.     ImGui::StyleColorsDark();
  57.  
  58.     float col[3] = { 0.2f, 0.3f, 0.3f };
  59.    
  60.  
  61.     bool isRunning = true;
  62.     SDL_Event ev;
  63.  
  64.     while (isRunning) {
  65.  
  66.        
  67.        
  68.         while (SDL_PollEvent(&ev) != 0) {
  69.  
  70.             ImGui_ImplSdlGL3_ProcessEvent(&ev);
  71.            
  72.             if (ev.type == SDL_QUIT) {
  73.                 isRunning = false;
  74.             }
  75.         }
  76.  
  77.         ImGui_ImplSdlGL3_NewFrame(window);
  78.  
  79.         {
  80.             static float f = 0.0f;
  81.             static int counter = 0;
  82.             ImGui::Text("Hello, world!");  
  83.  
  84.             if (ImGui::Button("Button"))                            
  85.                 counter++;
  86.             ImGui::SameLine();
  87.             ImGui::Text("counter = %d", counter);
  88.  
  89.             ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
  90.         }
  91.  
  92.  
  93.         glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
  94.         glClear(GL_COLOR_BUFFER_BIT);
  95.  
  96.  
  97.         ImGui::Render();
  98.         ImGui_ImplSdlGL3_RenderDrawData(ImGui::GetDrawData());
  99.        
  100.  
  101.         // draw here
  102.  
  103.         SDL_GL_SwapWindow(window);
  104.  
  105.     }
  106.  
  107.  
  108.     ImGui_ImplSdlGL3_Shutdown();
  109.     ImGui::DestroyContext();
  110.  
  111.     SDL_DestroyWindow(window);
  112.     SDL_GL_DeleteContext(glcontext);
  113.     SDL_Quit();
  114.    
  115.    
  116.     return 0;
  117.  
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement