Added windows support for the OpenGL example cube

This commit is contained in:
Benjamin Kyd
2019-02-12 13:25:14 +00:00
parent 3a6a7bb0c7
commit 29de71a827
3 changed files with 157 additions and 13 deletions

View File

@@ -9,18 +9,37 @@ set(executable cube.a)
set(SrcDIR ./src)
set(IncludeDIR ./include)
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
find_package(PNG REQUIRED)
find_package(JPEG REQUIRED)
if (UNIX)
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
find_package(PNG REQUIRED)
find_package(JPEG REQUIRED)
endif(UNIX)
if (WIN32)
SET(CMAKE_CXX_FLAGS "-IC:/dev/SDL2/include/ -LC:/dev/SDL2/lib/x64/")
SET(CMAKE_CXX_FLAGS "-IC:/dev/SDL2_image/include/ -LC:/dev/SDL2_image/lib/x64/")
SET(CMAKE_CXX_FLAGS "-IC:/dev/glm")
include_directories(${executable}
"C:/dev/glm"
"C:/dev/SDL2/include/"
"C:/dev/SDL2_image/include/"
)
endif (WIN32)
set(THREADS_PREFER_PTHREAD_FLAD ON)
find_package(Threads REQUIRED)
find_package(OpenGL REQUIRED)
if (UNIX)
include_directories(${executable}
${SDL2_INCLUDE_DIR}
${SDL2_IMAGE_INCLUDE_DIR}
)
endif (UNIX)
include_directories(${executable}
${SDL2_INCLUDE_DIR}
${SDL2_IMAGE_INCLUDE_DIR}
${PNG_INCLUDE_DIR}
${JPEG_INCLUDE_DIR}
${IncludeDIR}
@@ -37,13 +56,28 @@ set_target_properties(${executable} PROPERTIES
CXX_EXTENSIONS OFF
)
if (UNIX)
target_link_libraries(${executable}
SDL2
SDL2_image
PNG::PNG
JPEG::JPEG
OpenGL::OpenGL
OpenGL::GL
Threads::Threads
)
endif (UNIX)
if (WIN32)
target_link_libraries(${executable}
"C:/dev/SDL2/lib/x64/SDL2.lib"
"C:/dev/SDL2/lib/x64/SDL2main.lib"
"C:/dev/SDL2/lib/x64/SDL2test.lib"
"C:/dev/SDL2_image/lib/x64/SDL2_image.lib"
${WinSDK}
)
endif (WIN32)
target_link_libraries(${executable}
${CMAKE_DL_LIBS}
OpenGL::OpenGL
OpenGL::GL
SDL2
SDL2_image
PNG::PNG
JPEG::JPEG
Threads::Threads
)

View File

@@ -1,7 +1,12 @@
#include <iostream>
#include <glad/glad.h>
#ifdef _WIN32
#include <SDL.h>
#include <SDL_image.h>
#else
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#endif
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
@@ -158,6 +163,7 @@ int main(int argc, char** argv) {
}
// Set up a GL texture
GLuint tex;
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
// Set mag and min filtering levels
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);