Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma warning(disable:4996)
- #include "imgui/imgui.h"
- #include "imgui/imgui_impl_sdl_gl3.h"
- #include <glew.h>
- #include <SDL_opengl.h>
- #include <steam_api.h>
- #include <SDL.h>
- #include <iostream>
- #include <string>
- int main(int argc, char *argv[]) {
- if (SteamAPI_Init() == false) {
- std::cout << "cant init steamAPI" << std::endl;
- }
- SDL_Init(SDL_INIT_VIDEO);
- SDL_Init(SDL_INIT_EVENTS);
- // gl attributes
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
- SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
- SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
- SDL_Window *window = SDL_CreateWindow("Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
- SDL_GLContext glcontext = SDL_GL_CreateContext(window);
- SDL_GL_SetSwapInterval(1);
- glewExperimental = GL_TRUE;
- if (GLEW_OK != glewInit()) {
- std::cout << "Cant init glew!" << std::endl;
- }
- glViewport(0, 0, 800, 600);
- // ImGui binding setup
- IMGUI_CHECKVERSION();
- ImGui::CreateContext();
- ImGuiIO& io = ImGui::GetIO(); (void)io;
- io.ConfigFlags = ImGuiConfigFlags_NavEnableKeyboard;
- ImGui_ImplSdlGL3_Init(window);
- // Style setup
- ImGui::StyleColorsDark();
- float col[3] = { 0.2f, 0.3f, 0.3f };
- bool isRunning = true;
- SDL_Event ev;
- while (isRunning) {
- while (SDL_PollEvent(&ev) != 0) {
- ImGui_ImplSdlGL3_ProcessEvent(&ev);
- if (ev.type == SDL_QUIT) {
- isRunning = false;
- }
- }
- ImGui_ImplSdlGL3_NewFrame(window);
- {
- static float f = 0.0f;
- static int counter = 0;
- ImGui::Text("Hello, world!");
- if (ImGui::Button("Button"))
- counter++;
- ImGui::SameLine();
- ImGui::Text("counter = %d", counter);
- ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
- }
- glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT);
- ImGui::Render();
- ImGui_ImplSdlGL3_RenderDrawData(ImGui::GetDrawData());
- // draw here
- SDL_GL_SwapWindow(window);
- }
- ImGui_ImplSdlGL3_Shutdown();
- ImGui::DestroyContext();
- SDL_DestroyWindow(window);
- SDL_GL_DeleteContext(glcontext);
- SDL_Quit();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement