Modified CMake to now find and link GLEW
Slight tweaks to how CMake interacts with VS Added small OpenGL testing class which draws over the raycasted image Going to use Gl to start helping with debug / enabling hybrid rendering
This commit is contained in:
@@ -1,13 +1,14 @@
|
|||||||
# Check versions
|
# Check versions
|
||||||
message(STATUS "CMake version: ${CMAKE_VERSION}")
|
message(STATUS "CMake version: ${CMAKE_VERSION}")
|
||||||
cmake_minimum_required(VERSION 3.1)
|
cmake_minimum_required(VERSION 3.1)
|
||||||
|
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||||
# Set the project name
|
# Set the project name
|
||||||
set(PNAME Game)
|
set(PNAME Game)
|
||||||
project(${PNAME})
|
project(${PNAME})
|
||||||
|
|
||||||
# Set up variables, and find SFML
|
# Set up variables, and find SFML
|
||||||
#set(SFML_ROOT root CACHE STRING "User specified path")
|
set(SFML_ROOT root CACHE STRING "User specified path")
|
||||||
|
set(SFML_INCLUDE_DIR ${SFML_ROOT}/include)
|
||||||
set(SFML_COMPONENTS graphics window system network audio)
|
set(SFML_COMPONENTS graphics window system network audio)
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
find_package(SFML 2.1 COMPONENTS ${SFML_COMPONENTS} REQUIRED)
|
find_package(SFML 2.1 COMPONENTS ${SFML_COMPONENTS} REQUIRED)
|
||||||
@@ -17,6 +18,10 @@ message(STATUS "SFML found: ${SFML_FOUND}")
|
|||||||
find_package( OpenCL REQUIRED )
|
find_package( OpenCL REQUIRED )
|
||||||
message(STATUS "OpenCL found: ${OPENCL_FOUND}")
|
message(STATUS "OpenCL found: ${OPENCL_FOUND}")
|
||||||
|
|
||||||
|
# Find GLEW
|
||||||
|
find_package(GLEW REQUIRED)
|
||||||
|
message(STATUS "GLEW found: ${GLEW_FOUND}")
|
||||||
|
|
||||||
# Find OpenGL
|
# Find OpenGL
|
||||||
find_package( OpenGL REQUIRED)
|
find_package( OpenGL REQUIRED)
|
||||||
message(STATUS "OpenGL found: ${OPENGL_FOUND}")
|
message(STATUS "OpenGL found: ${OPENGL_FOUND}")
|
||||||
@@ -27,17 +32,27 @@ include_directories(${OpenCL_INCLUDE_DIRS})
|
|||||||
include_directories(${OpenGL_INCLUDE_DIRS})
|
include_directories(${OpenGL_INCLUDE_DIRS})
|
||||||
include_directories(include)
|
include_directories(include)
|
||||||
|
|
||||||
# Set the sources, allows VS to filter them properly
|
# Glob all thr sources into their values
|
||||||
file(GLOB SOURCES "src/*.cpp")
|
file(GLOB_RECURSE SOURCES "src/*.cpp")
|
||||||
file(GLOB HEADERS "include/*.h" "include/*.hpp")
|
file(GLOB_RECURSE HEADERS "include/*.h" "include/*.hpp")
|
||||||
file(GLOB KERNELS "kernels/*.cl")
|
file(GLOB_RECURSE KERNELS "kernels/*.cl")
|
||||||
|
file(GLOB_RECURSE SHADERS "shaders/*.vert" "shaders/*.tesc" "shaders/*.tese" "shaders/*.geom" "shaders/*.frag" "shaders/*.comp")
|
||||||
|
|
||||||
|
|
||||||
|
add_executable(${PNAME} ${SOURCES} ${HEADERS} ${KERNELS} ${SHADERS})
|
||||||
|
|
||||||
|
# put all the sources into their own filter folders
|
||||||
|
SOURCE_GROUP("kernels" FILES ${KERNELS})
|
||||||
|
SOURCE_GROUP("headers" FILES ${HEADERS})
|
||||||
|
SOURCE_GROUP("sources" FILES ${SOURCES})
|
||||||
|
SOURCE_GROUP("shaders" FILES ${SHADERS})
|
||||||
|
|
||||||
add_executable(${PNAME} ${SOURCES} ${HEADERS} ${KERNELS})
|
|
||||||
|
|
||||||
# Link CL, GL, and SFML
|
# Link CL, GL, and SFML
|
||||||
target_link_libraries (${PNAME} ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
|
target_link_libraries (${PNAME} ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
|
||||||
target_link_libraries (${PNAME} ${OpenCL_LIBRARY})
|
target_link_libraries (${PNAME} ${OpenCL_LIBRARY})
|
||||||
target_link_libraries (${PNAME} ${OPENGL_LIBRARIES})
|
target_link_libraries (${PNAME} ${OPENGL_LIBRARIES})
|
||||||
|
target_link_libraries (${PNAME} ${GLEW_LIBRARIES})
|
||||||
|
|
||||||
# Setup to use C++11
|
# Setup to use C++11
|
||||||
set_property(TARGET ${PNAME} PROPERTY CXX_STANDARD 11) # Use C++11
|
set_property(TARGET ${PNAME} PROPERTY CXX_STANDARD 11) # Use C++11
|
||||||
|
|||||||
29
include/GL_Testing.h
Normal file
29
include/GL_Testing.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
#include <util.hpp>
|
||||||
|
#define GLEW_STATIC
|
||||||
|
#include <GL/glew.h>
|
||||||
|
|
||||||
|
class GL_Testing
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GL_Testing();
|
||||||
|
~GL_Testing(){};
|
||||||
|
|
||||||
|
|
||||||
|
enum Shader_Type {VERTEX, FRAGMENT};
|
||||||
|
void compile_shader(std::string file_path, Shader_Type t);
|
||||||
|
void create_program();
|
||||||
|
void create_buffers();
|
||||||
|
void draw();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
GLuint VBO; //raw points
|
||||||
|
GLuint EBO; //link triangles
|
||||||
|
GLuint VAO;
|
||||||
|
GLuint vertex_shader;
|
||||||
|
GLuint fragment_shader;
|
||||||
|
GLuint shader_program;
|
||||||
|
};
|
||||||
|
|
||||||
@@ -10,7 +10,6 @@ const double PI = 3.141592653589793238463;
|
|||||||
const float PI_F = 3.14159265358979f;
|
const float PI_F = 3.14159265358979f;
|
||||||
|
|
||||||
struct Light {
|
struct Light {
|
||||||
#pragma pack(1)
|
|
||||||
sf::Vector4f rgbi;
|
sf::Vector4f rgbi;
|
||||||
|
|
||||||
// I believe that Vector3's get padded to Vector4's. Give them a non-garbage value
|
// I believe that Vector3's get padded to Vector4's. Give them a non-garbage value
|
||||||
@@ -163,7 +162,7 @@ inline std::string read_file(std::string file_name){
|
|||||||
|
|
||||||
if (!input_file.is_open()){
|
if (!input_file.is_open()){
|
||||||
std::cout << file_name << " could not be opened" << std::endl;
|
std::cout << file_name << " could not be opened" << std::endl;
|
||||||
return nullptr;
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::stringstream buf;
|
std::stringstream buf;
|
||||||
|
|||||||
8
shaders/passthrough.frag
Normal file
8
shaders/passthrough.frag
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#version 330 core
|
||||||
|
|
||||||
|
out vec4 color;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
color = vec4(0.0f, 0.5f, 0.2f, 1.0f);
|
||||||
|
|
||||||
|
}
|
||||||
8
shaders/passthrough.vert
Normal file
8
shaders/passthrough.vert
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#version 330 core
|
||||||
|
|
||||||
|
layout (location = 0) in vec3 position;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
gl_Position = vec4(position.x, position.y, position.z, 1.0);
|
||||||
|
|
||||||
|
}
|
||||||
118
src/GL_Testing.cpp
Normal file
118
src/GL_Testing.cpp
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
#include "GL_Testing.h"
|
||||||
|
|
||||||
|
GL_Testing::GL_Testing() {
|
||||||
|
|
||||||
|
GLint err = glewInit();
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
std::cout << "error initializing glew" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void GL_Testing::compile_shader(std::string file_path, Shader_Type t) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Load in the source and cstring it
|
||||||
|
const char* source;
|
||||||
|
std::string tmp;
|
||||||
|
|
||||||
|
tmp = read_file(file_path);
|
||||||
|
source = tmp.c_str();
|
||||||
|
|
||||||
|
GLint success;
|
||||||
|
GLchar log[512];
|
||||||
|
|
||||||
|
if (t == Shader_Type::VERTEX) {
|
||||||
|
|
||||||
|
vertex_shader = glCreateShader(GL_VERTEX_SHADER);
|
||||||
|
glShaderSource(vertex_shader, 1, &source, NULL);
|
||||||
|
glCompileShader(vertex_shader);
|
||||||
|
|
||||||
|
glGetShaderiv(vertex_shader, GL_COMPILE_STATUS, &success);
|
||||||
|
|
||||||
|
if (!success) {
|
||||||
|
glGetShaderInfoLog(vertex_shader, 512, NULL, log);
|
||||||
|
std::cout << "Vertex shader failed compilation: " << log << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (t == Shader_Type::FRAGMENT) {
|
||||||
|
|
||||||
|
fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||||
|
glShaderSource(fragment_shader, 1, &source, NULL);
|
||||||
|
glCompileShader(fragment_shader);
|
||||||
|
|
||||||
|
glGetShaderiv(fragment_shader, GL_COMPILE_STATUS, &success);
|
||||||
|
|
||||||
|
if (!success) {
|
||||||
|
glGetShaderInfoLog(fragment_shader, 512, NULL, log);
|
||||||
|
std::cout << "Vertex shader failed compilation: " << log << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GL_Testing::create_program() {
|
||||||
|
|
||||||
|
GLint success;
|
||||||
|
GLchar log[512];
|
||||||
|
|
||||||
|
shader_program = glCreateProgram();
|
||||||
|
glAttachShader(shader_program, vertex_shader);
|
||||||
|
glAttachShader(shader_program, fragment_shader);
|
||||||
|
glLinkProgram(shader_program);
|
||||||
|
|
||||||
|
|
||||||
|
glGetProgramiv(shader_program, GL_LINK_STATUS, &success);
|
||||||
|
|
||||||
|
if (!success) {
|
||||||
|
glGetProgramInfoLog(shader_program, 512, NULL, log);
|
||||||
|
std::cout << "Failed to link shaders into program: " << log << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
glDeleteShader(vertex_shader);
|
||||||
|
glDeleteShader(fragment_shader);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GL_Testing::create_buffers() {
|
||||||
|
|
||||||
|
GLfloat vertices[] = {
|
||||||
|
0.5f, 0.5f, 0.0f, // Top Right
|
||||||
|
0.5f, -0.5f, 0.0f, // Bottom Right
|
||||||
|
-0.5f, -0.5f, 0.0f, // Bottom Left
|
||||||
|
-0.5f, 0.5f, 0.0f // Top Left
|
||||||
|
};
|
||||||
|
GLuint indices[] = { // Note that we start from 0!
|
||||||
|
0, 1, 3 // First Triangle
|
||||||
|
// Second Triangle
|
||||||
|
};
|
||||||
|
|
||||||
|
glGenVertexArrays(1, &VAO);
|
||||||
|
glGenBuffers(1, &VBO);
|
||||||
|
glGenBuffers(1, &EBO);
|
||||||
|
// Bind the Vertex Array Object first, then bind and set vertex buffer(s) and attribute pointer(s).
|
||||||
|
glBindVertexArray(VAO);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
||||||
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0);
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0); // Note that this is allowed, the call to glVertexAttribPointer registered VBO as the currently bound vertex buffer object so afterwards we can safely unbind
|
||||||
|
|
||||||
|
glBindVertexArray(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GL_Testing::draw() {
|
||||||
|
|
||||||
|
glUseProgram(shader_program);
|
||||||
|
glBindVertexArray(VAO);
|
||||||
|
//glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
|
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, 0);
|
||||||
|
glBindVertexArray(0);
|
||||||
|
}
|
||||||
|
//
|
||||||
26
src/main.cpp
26
src/main.cpp
@@ -1,15 +1,14 @@
|
|||||||
#ifdef linux
|
#include "GL_Testing.h"
|
||||||
|
|
||||||
|
#ifdef linux
|
||||||
#include <CL/cl.h>
|
#include <CL/cl.h>
|
||||||
#include <CL/opencl.h>
|
#include <CL/opencl.h>
|
||||||
|
|
||||||
#elif defined _WIN32
|
#elif defined _WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <CL/cl_gl.h>
|
|
||||||
#include <CL/cl.h>
|
#include <CL/cl.h>
|
||||||
#include <CL/opencl.h>
|
#include <CL/opencl.h>
|
||||||
|
|
||||||
#include <windows.h>
|
|
||||||
|
|
||||||
#elif defined TARGET_OS_MAC
|
#elif defined TARGET_OS_MAC
|
||||||
#include <OpenGL/gl.h>
|
#include <OpenGL/gl.h>
|
||||||
# include <OpenGL/OpenGL.h>
|
# include <OpenGL/OpenGL.h>
|
||||||
@@ -24,6 +23,8 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
#include "Old_Map.h"
|
#include "Old_Map.h"
|
||||||
#include "util.hpp"
|
#include "util.hpp"
|
||||||
@@ -33,6 +34,7 @@
|
|||||||
#include <Camera.h>
|
#include <Camera.h>
|
||||||
#include "Software_Caster.h"
|
#include "Software_Caster.h"
|
||||||
|
|
||||||
|
|
||||||
const int WINDOW_X = 1920;
|
const int WINDOW_X = 1920;
|
||||||
const int WINDOW_Y = 1080;
|
const int WINDOW_Y = 1080;
|
||||||
const int WORK_SIZE = WINDOW_X * WINDOW_Y;
|
const int WORK_SIZE = WINDOW_X * WINDOW_Y;
|
||||||
@@ -66,6 +68,12 @@ int main() {
|
|||||||
|
|
||||||
sf::RenderWindow window(sf::VideoMode(WINDOW_X, WINDOW_Y), "SFML");
|
sf::RenderWindow window(sf::VideoMode(WINDOW_X, WINDOW_Y), "SFML");
|
||||||
|
|
||||||
|
GL_Testing t;
|
||||||
|
t.compile_shader("../shaders/passthrough.frag", GL_Testing::Shader_Type::FRAGMENT);
|
||||||
|
t.compile_shader("../shaders/passthrough.vert", GL_Testing::Shader_Type::VERTEX);
|
||||||
|
t.create_program();
|
||||||
|
t.create_buffers();
|
||||||
|
|
||||||
// Initialize the raycaster hardware, compat, or software
|
// Initialize the raycaster hardware, compat, or software
|
||||||
RayCaster *rc = new Hardware_Caster();
|
RayCaster *rc = new Hardware_Caster();
|
||||||
//RayCaster *rc = new Software_Caster();
|
//RayCaster *rc = new Software_Caster();
|
||||||
@@ -190,7 +198,7 @@ int main() {
|
|||||||
if (deltas != sf::Vector2i(0, 0) && mouse_enabled == true) {
|
if (deltas != sf::Vector2i(0, 0) && mouse_enabled == true) {
|
||||||
|
|
||||||
// Mouse movement
|
// Mouse movement
|
||||||
//sf::Mouse::setPosition(fixed);
|
sf::Mouse::setPosition(fixed);
|
||||||
prev_pos = sf::Mouse::getPosition();
|
prev_pos = sf::Mouse::getPosition();
|
||||||
camera->slew_camera(sf::Vector2f(
|
camera->slew_camera(sf::Vector2f(
|
||||||
deltas.y / 300.0f,
|
deltas.y / 300.0f,
|
||||||
@@ -221,6 +229,14 @@ int main() {
|
|||||||
rc->compute();
|
rc->compute();
|
||||||
rc->draw(&window);
|
rc->draw(&window);
|
||||||
|
|
||||||
|
window.popGLStates();
|
||||||
|
|
||||||
|
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||||
|
t.draw();
|
||||||
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
|
|
||||||
|
window.pushGLStates();
|
||||||
|
|
||||||
// Give the frame counter the frame time and draw the average frame time
|
// Give the frame counter the frame time and draw the average frame time
|
||||||
fps.frame(delta_time);
|
fps.frame(delta_time);
|
||||||
fps.draw(&window);
|
fps.draw(&window);
|
||||||
|
|||||||
Reference in New Issue
Block a user