Humble beginnings - Simple window!
This commit is contained in:
parent
5373b02853
commit
b1a5bf2fe4
|
@ -0,0 +1,6 @@
|
||||||
|
CMakeFiles
|
||||||
|
CMakeCache.txt
|
||||||
|
cmake_install.cmake
|
||||||
|
Makefile
|
||||||
|
/bin/universium
|
||||||
|
/build
|
|
@ -0,0 +1,50 @@
|
||||||
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
project(universium-engine)
|
||||||
|
|
||||||
|
# Modules
|
||||||
|
#SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake/Modules ${CMAKE_MODULE_PATH})
|
||||||
|
|
||||||
|
# Enable compiler warning.
|
||||||
|
string(APPEND CMAKE_CXX_FLAGS " -Wall")
|
||||||
|
string(APPEND CMAKE_CXX_FLAGS " -Werror")
|
||||||
|
string(APPEND CMAKE_CXX_FLAGS " -Wextra")
|
||||||
|
string(APPEND CMAKE_CXX_FLAGS " -Wno-reorder")
|
||||||
|
string(APPEND CMAKE_CXX_FLAGS " -Wno-unused-parameter")
|
||||||
|
|
||||||
|
# Sources and headers
|
||||||
|
include_directories(${PROJECT_SOURCE_DIR}/src)
|
||||||
|
file(GLOB_RECURSE SOURCES ${PROJECT_SOURCE_DIR}/src/*)
|
||||||
|
|
||||||
|
# Executable output
|
||||||
|
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
|
||||||
|
|
||||||
|
# System-specific options
|
||||||
|
# TODO: this
|
||||||
|
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||||
|
set(UNIVERSIUM_EXECUTABLE "universium")
|
||||||
|
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||||
|
set(UNIVERSIUM_EXECUTABLE "universium")
|
||||||
|
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
||||||
|
set(UNIVERSIUM_EXECUTABLE "universium.exe")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_executable(${UNIVERSIUM_EXECUTABLE} ${SOURCES})
|
||||||
|
|
||||||
|
# Include GL
|
||||||
|
find_package(OpenGL REQUIRED)
|
||||||
|
include_directories(${OPENGL_INCLUDE_DIR})
|
||||||
|
target_link_libraries(${UNIVERSIUM_EXECUTABLE} ${OPENGL_LIBRARIES})
|
||||||
|
|
||||||
|
# Include GLEW
|
||||||
|
find_package(GLEW REQUIRED)
|
||||||
|
include_directories(${GLEW_INCLUDE_PATH})
|
||||||
|
target_link_libraries(${UNIVERSIUM_EXECUTABLE} ${GLEW_LIBRARY})
|
||||||
|
|
||||||
|
# Include SDL
|
||||||
|
INCLUDE(FindPkgConfig)
|
||||||
|
|
||||||
|
PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2)
|
||||||
|
PKG_SEARCH_MODULE(SDL2IMAGE REQUIRED SDL2_image>=2.0.0)
|
||||||
|
|
||||||
|
include_directories(${SDL2_INCLUDE_DIRS} ${SDL2IMAGE_INCLUDE_DIRS})
|
||||||
|
target_link_libraries(${UNIVERSIUM_EXECUTABLE} ${SDL2_LIBRARIES} ${SDL2IMAGE_LIBRARIES})
|
|
@ -0,0 +1,102 @@
|
||||||
|
#include "Application.h"
|
||||||
|
|
||||||
|
Application::Application()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Application::~Application()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::Initialize()
|
||||||
|
{
|
||||||
|
if (SDL_Init(SDL_INIT_VIDEO) < 0)
|
||||||
|
{
|
||||||
|
std::cout << "Failed to init SDL\n";
|
||||||
|
printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create our window centered at 1080x720 resolution
|
||||||
|
m_window = SDL_CreateWindow(
|
||||||
|
"Universium",
|
||||||
|
SDL_WINDOWPOS_CENTERED,
|
||||||
|
SDL_WINDOWPOS_CENTERED,
|
||||||
|
1080,
|
||||||
|
720,
|
||||||
|
SDL_WINDOW_OPENGL
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!m_window)
|
||||||
|
{
|
||||||
|
printf("Window could not be created! SDL_Error: %s\n", SDL_GetError());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set GL Attributes
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||||
|
|
||||||
|
SDL_GLContext glContext = SDL_GL_CreateContext(m_window);
|
||||||
|
|
||||||
|
if(glContext == NULL)
|
||||||
|
{
|
||||||
|
printf("OpenGL context could not be created! SDL Error: %s\n", SDL_GetError());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize GLEW
|
||||||
|
glewInit();
|
||||||
|
|
||||||
|
// Run the engine
|
||||||
|
Run();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::Run()
|
||||||
|
{
|
||||||
|
m_run = true;
|
||||||
|
|
||||||
|
while (m_run)
|
||||||
|
{
|
||||||
|
while(SDL_PollEvent(&m_event) != 0)
|
||||||
|
{
|
||||||
|
// Close button is pressed
|
||||||
|
if(m_event.type == SDL_QUIT)
|
||||||
|
{
|
||||||
|
m_run = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Render();
|
||||||
|
|
||||||
|
// Set background color as cornflower blue
|
||||||
|
glClearColor(0.39f, 0.58f, 0.93f, 1.f);
|
||||||
|
|
||||||
|
// Clear color buffer
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
// Update window with OpenGL rendering
|
||||||
|
SDL_GL_SwapWindow(m_window);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Destroy window
|
||||||
|
SDL_DestroyWindow(m_window);
|
||||||
|
m_window = NULL;
|
||||||
|
|
||||||
|
//Quit SDL subsystems
|
||||||
|
SDL_Quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::Update(GLfloat dtime)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::Render()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
#ifndef __APPLICATION_H__
|
||||||
|
#define __APPLICATION_H__
|
||||||
|
#include "Common.h"
|
||||||
|
|
||||||
|
class Application
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Application();
|
||||||
|
~Application();
|
||||||
|
|
||||||
|
void Initialize();
|
||||||
|
private:
|
||||||
|
SDL_Window* m_window;
|
||||||
|
SDL_Event m_event;
|
||||||
|
bool m_run;
|
||||||
|
|
||||||
|
void Run();
|
||||||
|
void Render();
|
||||||
|
void Update(GLfloat dtime);
|
||||||
|
};
|
||||||
|
#endif // __APPLICATION_H__
|
|
@ -0,0 +1,18 @@
|
||||||
|
#ifndef __COMMON_H__
|
||||||
|
#define __COMMON_H__
|
||||||
|
|
||||||
|
#include <GL/glew.h>
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include <SDL2/SDL_opengl.h>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
#endif // __COMMON_H__
|
|
@ -0,0 +1,8 @@
|
||||||
|
#include "Application.h"
|
||||||
|
|
||||||
|
int main(int argc, char const *argv[])
|
||||||
|
{
|
||||||
|
Application app;
|
||||||
|
app.Initialize();
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue