Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rossning92 committed Aug 30, 2020
0 parents commit c0a82a2
Show file tree
Hide file tree
Showing 38 changed files with 1,949 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build
.vscode
33 changes: 33 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
cmake_minimum_required(VERSION 2.7)


set(PROJECT_NAME main)

project(${PROJECT_NAME})

find_package(imgui CONFIG REQUIRED)
find_package(glfw3 CONFIG REQUIRED)
find_package(GLEW REQUIRED)
find_package(glm CONFIG REQUIRED)
find_path(STB_INCLUDE_DIRS "stb.h")

include_directories(${PROJECT_SOURCE_DIR})
include_directories(${GLFW_INCLUDE_DIR})

file(GLOB SRC_FILES
"${PROJECT_SOURCE_DIR}/*.h"
"${PROJECT_SOURCE_DIR}/*.cpp"
"${PROJECT_SOURCE_DIR}/*.c"
"${PROJECT_SOURCE_DIR}/*.cc"
)

add_executable(main
${SRC_FILES}
)

target_link_libraries(main PRIVATE imgui::imgui)
target_link_libraries(main PRIVATE glfw)
target_link_libraries(main PRIVATE GLEW::GLEW)
target_link_libraries(main PRIVATE glm)
target_include_directories(main PRIVATE ${STB_INCLUDE_DIRS})
target_compile_features(main PRIVATE cxx_std_17)
153 changes: 153 additions & 0 deletions GLDebugMessageCallback.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// This is free and unencumbered software released into the public domain.
//
// Anyone is free to copy, modify, publish, use, compile, sell, or distribute
// this software, either in source code form or as a compiled binary, for any
// purpose, commercial or non-commercial, and by any means.
//
// In jurisdictions that recognize copyright laws, the author or authors of this
// software dedicate any and all copyright interest in the software to the
// public domain. We make this dedication for the benefit of the public at large
// and to the detriment of our heirs and successors. We intend this dedication
// to be an overt act of relinquishment in perpetuity of all present and future
// rights to this software under copyright law.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// For more information, please refer to <http://unlicense.org/>

// =============== How to use ================
// The following function calls should be made directly after OpenGL
// initialization.

// Enable the debugging layer of OpenGL
//
// GL_DEBUG_OUTPUT - Faster version but not useful for breakpoints
// GL_DEBUG_OUTPUT_SYNCHRONUS - Callback is in sync with errors, so a breakpoint
// can be placed on the callback in order to get a stacktrace for the GL error. (enable together with GL_DEBUG_OUTPUT !)

// glEnable(GL_DEBUG_OUTPUT);
// glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);

// Set the function that will be triggered by the callback, the second parameter
// is the data parameter of the callback, it can be useful for different
// contexts but isn't necessary for our simple use case.
// glDebugMessageCallback(GLDebugMessageCallback, nullptr);

// REQUIREMENTS: OpenGL version with the KHR_debug extension available.
// modified for C++ by Plasmoxy [7. 5. 2020], I'm using: GLEW and GLFW3, OpenGL 4.6
// original gist: https://gist.github.com/liam-middlebrook/c52b069e4be2d87a6d2f

#include "GLDebugMessageCallback.h"

// Callback function for printing debug statements
void APIENTRY GLDebugMessageCallback(GLenum source, GLenum type, GLuint id,
GLenum severity, GLsizei length,
const GLchar* msg, const void* data)
{
const char* _source;
const char* _type;
const char* _severity;

switch (source) {
case GL_DEBUG_SOURCE_API:
_source = "API";
break;

case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
_source = "WINDOW SYSTEM";
break;

case GL_DEBUG_SOURCE_SHADER_COMPILER:
_source = "SHADER COMPILER";
break;

case GL_DEBUG_SOURCE_THIRD_PARTY:
_source = "THIRD PARTY";
break;

case GL_DEBUG_SOURCE_APPLICATION:
_source = "APPLICATION";
break;

case GL_DEBUG_SOURCE_OTHER:
_source = "UNKNOWN";
break;

default:
_source = "UNKNOWN";
break;
}

switch (type) {
case GL_DEBUG_TYPE_ERROR:
_type = "ERROR";
break;

case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
_type = "DEPRECATED BEHAVIOR";
break;

case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
_type = "UDEFINED BEHAVIOR";
break;

case GL_DEBUG_TYPE_PORTABILITY:
_type = "PORTABILITY";
break;

case GL_DEBUG_TYPE_PERFORMANCE:
_type = "PERFORMANCE";
break;

case GL_DEBUG_TYPE_OTHER:
_type = "OTHER";
break;

case GL_DEBUG_TYPE_MARKER:
_type = "MARKER";
break;

default:
_type = "UNKNOWN";
break;
}

switch (severity) {
case GL_DEBUG_SEVERITY_HIGH:
_severity = "HIGH";
break;

case GL_DEBUG_SEVERITY_MEDIUM:
_severity = "MEDIUM";
break;

case GL_DEBUG_SEVERITY_LOW:
_severity = "LOW";
break;

case GL_DEBUG_SEVERITY_NOTIFICATION:
_severity = "NOTIFICATION";
break;

default:
_severity = "UNKNOWN";
break;
}

// ignore notification severity (you can add your own ignores)
// + Adds __debugbreak if _DEBUG is defined (automatic in visual studio)
// note: __debugbreak is specific for MSVC, won't work with gcc/clang
// -> in that case remove it and manually set breakpoints
if (_severity != "NOTIFICATION") {
printf("OpenGL error [%d]: %s of %s severity, raised from %s: %s\n",
id, _type, _severity, _source, msg);
#ifdef _DEBUG
__debugbreak();
#endif
}
}
11 changes: 11 additions & 0 deletions GLDebugMessageCallback.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Header for GLDebugMessageCallback by Plasmoxy 2020
// Feel free to use this in any way.
#pragma once

#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>

void APIENTRY GLDebugMessageCallback(GLenum source, GLenum type, GLuint id,
GLenum severity, GLsizei length,
const GLchar* msg, const void* data);
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Real-time Black Hole Rendering in OpenGL

_(WIP: refactoring, cleaning up and documenting the code)_

![Screenshot](docs/screenshot.jpg)

## Prerequisite

- cmake
- I used [vcpkg](https://github.com/microsoft/vcpkg) to install the following necessary C++ libraries for this project:
- glew
- glfw3
- glm
- imgui
- stb

## Build the code

```
cmake \
-DCMAKE_TOOLCHAIN_FILE=<vcpkg_dir>/scripts/buildsystems/vcpkg.cmake \
-B build -S .
```

## Acknowledgements
Binary file added assets/color_map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/skybox_nebula_dark/back.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/skybox_nebula_dark/bottom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/skybox_nebula_dark/front.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/skybox_nebula_dark/left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/skybox_nebula_dark/right.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/skybox_nebula_dark/top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/skybox_test/back.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/skybox_test/bottom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/skybox_test/front.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/skybox_test/left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/skybox_test/right.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/skybox_test/top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/uv_checker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshot.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit c0a82a2

Please sign in to comment.