Browse Source

first skeleton working (?)

master
Martin Klimeš 5 years ago
parent
commit
8144e44adb
4 changed files with 83 additions and 54 deletions
  1. +1
    -0
      .gitignore
  2. +31
    -54
      CMakeLists.txt
  3. +25
    -0
      shader/shader.frag
  4. +26
    -0
      shader/shader.vert

+ 1
- 0
.gitignore View File

@ -0,0 +1 @@
build

+ 31
- 54
CMakeLists.txt View File

@ -1,54 +1,31 @@
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
project(openglapp VERSION 0.1.0)
include(CTest)
enable_testing()
# Variables
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(PLATFORM_ARCH "64")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(PLATFORM_ARCH "32")
endif()
# Global
set(SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
set(INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
set(LIB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/lib")
# Includes
include_directories(${INCLUDE_DIR})
# Source
file(GLOB SOURCES "${SRC_DIR}/*.cpp")
add_executable(${PROJECT_NAME} ${SOURCES})
# GLAD
set(GLAD_DIR "${LIB_DIR}/glad")
add_library("glad" "${GLAD_DIR}/src/glad.c")
target_include_directories("glad" PRIVATE "${GLAD_DIR}/include")
target_include_directories(${PROJECT_NAME} PRIVATE "${GLAD_DIR}/include")
target_link_libraries(${PROJECT_NAME} "glad" "${CMAKE_DL_LIBS}")
# GLFW
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(GLFW_DIR "${LIB_DIR}/glfw-3.2.1")
add_subdirectory("${GLFW_DIR}")
target_include_directories(${PROJECT_NAME} PRIVATE "${GLFW_DIR}/include")
# GLM
set(GLM_TEST_ENABLE OFF CACHE BOOL "" FORCE)
set(GLM_DIR "${LIB_DIR}/glm")
add_subdirectory("${GLM_DIR}")
target_include_directories(${PROJECT_NAME} PRIVATE "${GLM_DIR}/glm")
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
target_link_libraries(${PROJECT_NAME} glfw)
target_link_libraries(${PROJECT_NAME} glm)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
# Projects Settings
cmake_minimum_required (VERSION 3.1)
project (opengl-skeleton)
# The main executable
add_executable(main
src/Application.cpp
src/Application.cpp
src/MyApplication.cpp
src/MyApplication.cpp
src/glError.hpp
src/glError.cpp
src/main.cpp
src/Shader.hpp
src/Shader.cpp
)
set_property(TARGET main PROPERTY CXX_STANDARD 11)
target_compile_options(main PRIVATE -Wall)
# glfw
add_subdirectory(lib/glfw EXCLUDE_FROM_ALL)
target_link_libraries(main PRIVATE glfw)
# glew
add_definitions(-DGLEW_STATIC)
add_subdirectory(lib/glew EXCLUDE_FROM_ALL)
target_link_libraries(main PRIVATE libglew_static)
# glm
add_subdirectory(lib/glm EXCLUDE_FROM_ALL)
target_link_libraries(main PRIVATE glm)

+ 25
- 0
shader/shader.frag View File

@ -0,0 +1,25 @@
#version 150
in vec4 fPosition;
in vec4 fColor;
in vec4 fLightPosition;
in vec3 fNormal;
// output
out vec4 color;
void main(void)
{
vec3 o =-normalize(fPosition.xyz);
vec3 n = normalize(fNormal);
vec3 r = reflect(o,n);
vec3 l = normalize(fLightPosition.xyz-fPosition.xyz);
float ambient = 0.1;
float diffus = 0.7*max(0.0,dot(n,l));
float specular = 0.6*pow(max(0.0,-dot(r,l)),4.0);
color = fColor * ( ambient + diffus + specular );
/*color = vec3(1,0,0);*/
}

+ 26
- 0
shader/shader.vert View File

@ -0,0 +1,26 @@
#version 150
in vec3 position;
in vec3 normal;
in vec4 color;
uniform mat4 projection;
uniform mat4 view;
out vec4 fPosition;
out vec4 fColor;
out vec4 fLightPosition;
out vec3 fNormal;
void main(void)
{
fPosition = view * vec4(position,1.0);
fLightPosition = view * vec4(0.0,0.0,1.0,1.0);
fColor = color;
fNormal = vec3(view * vec4(normal,0.0));
gl_Position = projection * fPosition;
/*gl_Position.x *= 1000.0f;*/
/*gl_Position.y = 0.0;*/
}

Loading…
Cancel
Save