Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,25 @@ The [License.txt](License.txt) file contains the licensing information for the m

In case you prefer Java to C++, Giuseppe Barbieri [created a Java port here](https://github.com/elect86/modern-jogl-examples).

## Building the tutorials
## Building the tutorials (non Mac)

- `apt-get install cmake`
- `mkdir build && cd build`
- `cmake ..`
- `cmake --build . --config Release`

## Building the tutorials (Mac)

See [freeglut instructions for Mac](https://github.com/freeglut/freeglut/blob/07a3e80780c289b51bc723415ef41cef6b026aed/README.macosx)

- `brew install cmake`
- `mkdir build && cd build`
- `cmake -DOPENGL_gl_LIBRARY=/usr/local/lib/libGL.dylib ..` (INTEL)
- `cmake -DOPENGL_gl_LIBRARY=/opt/homebrew/lib/libGL.dylib ..` (ARM)
- `cmake --build . --config Release`

* NOTE: you can specify -DFREEGLUT_COCOA=ON to use experimental [freeglut cocoa support](https://github.com/freeglut/freeglut/issues/195)

## Rebuilding the HTML Documentation

- `apt-get install lua-filesystem xsltproc docbook-xsl`
Expand Down
6 changes: 4 additions & 2 deletions Tut 01 Hello Triangle/Tut1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
#include <string>
#include <vector>
#include <stdio.h>
#include <glload/gl_3_2_comp.h>
#ifdef __APPLE__
#define FREEGLUT_NO_GL_INCLUDE
#include <OpenGL/gl3.h>
#endif
#include <GL/freeglut.h>


GLuint CreateShader(GLenum eShaderType, const std::string &strShaderFile)
{
GLuint shader = glCreateShader(eShaderType);
Expand Down
5 changes: 4 additions & 1 deletion Tut 02 Playing with Colors/FragPosition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
#include <vector>
#include <math.h>
#include <stdio.h>
#include <glload/gl_3_3.h>
#ifdef __APPLE__
#define FREEGLUT_NO_GL_INCLUDE
#include <OpenGL/gl3.h>
#endif
#include <GL/freeglut.h>
#include "../framework/framework.h"

Expand Down
5 changes: 4 additions & 1 deletion Tut 02 Playing with Colors/VertexColors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
#include <vector>
#include <math.h>
#include <stdio.h>
#include <glload/gl_3_3.h>
#ifdef __APPLE__
#define FREEGLUT_NO_GL_INCLUDE
#include <OpenGL/gl3.h>
#endif
#include <GL/freeglut.h>
#include "../framework/framework.h"

Expand Down
7 changes: 7 additions & 0 deletions framework/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# for apple support with our without cocoa so we know how to initialize opengl in framework.cpp
IF(FREEGLUT_COCOA)
ADD_DEFINITIONS(-DUSE_COCOA=1)
ENDIF()

file(GLOB framework_SRCS "*.cpp")
add_library(framework STATIC ${framework_SRCS})
target_include_directories(framework PUBLIC . ${CMAKE_SOURCE_DIR}/glsdk/glm)
# is this the best way? isn't there a way to add this to glsdk/CMakeLists.txt where we are `add_subdirectory(freeglut)`
target_include_directories(framework PUBLIC . ${CMAKE_SOURCE_DIR}/glsdk/freeglut/include)
target_link_libraries(framework
PUBLIC glload glimg glutil freeglut OpenGL::GL
)
Expand Down
6 changes: 4 additions & 2 deletions framework/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
#include <functional>
#include <algorithm>
#include <iostream>
#include <glload/gl_3_2_comp.h>
#include <glload/gl_load.h>
#ifdef __APPLE__
#define FREEGLUT_NO_GL_INCLUDE
#include <OpenGL/gl3.h>
#endif
#include <GL/freeglut.h>
#include "framework.h"
#include "Mesh.h"
Expand Down
1 change: 0 additions & 1 deletion framework/empty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ when/why they are called. You can copy this file and simply implement
these function.
***********************************************************************/

#include <glload/gl_3_2_comp.h>
#include <GL/freeglut.h>


Expand Down
146 changes: 78 additions & 68 deletions framework/framework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
#include <exception>
#include <stdexcept>
#include <string.h>
#include <glload/gl_3_3.h>
#include <glload/gl_load.hpp>
#include <glutil/Shader.h>
#ifdef __APPLE__
#define FREEGLUT_NO_GL_INCLUDE
#include <OpenGL/gl3.h>
#endif
#include <GL/freeglut.h>
#include <glutil/Shader.h>
#include "framework.h"
#include "directories.h"

Expand All @@ -32,7 +34,7 @@ namespace Framework
{
return glutil::CompileShader(eShaderType, shaderData.str());
}
catch(std::exception &e)
catch (std::exception &e)
{
fprintf(stderr, "%s\n", e.what());
throw;
Expand All @@ -47,7 +49,7 @@ namespace Framework
std::for_each(shaderList.begin(), shaderList.end(), glDeleteShader);
return prog;
}
catch(std::exception &e)
catch (std::exception &e)
{
std::for_each(shaderList.begin(), shaderList.end(), glDeleteShader);
fprintf(stderr, "%s\n", e.what());
Expand All @@ -61,108 +63,116 @@ namespace Framework
return fAngDeg * fDegToRad;
}

std::string FindFileOrThrow( const std::string &strBasename )
std::string FindFileOrThrow(const std::string &strBasename)
{
std::string strFilename = LOCAL_FILE_DIR + strBasename;
std::ifstream testFile(strFilename.c_str());
if(testFile.is_open())
if (testFile.is_open())
return strFilename;


strFilename = GLOBAL_FILE_DIR + strBasename;
testFile.open(strFilename.c_str());
if(testFile.is_open())
if (testFile.is_open())
return strFilename;

throw std::runtime_error("Could not find the file " + strBasename);
}
}


void init();
void display();
void reshape(int w, int h);
void keyboard(unsigned char key, int x, int y);

unsigned int defaults(unsigned int displayMode, int &width, int &height);

void APIENTRY DebugFunc(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length,
const GLchar* message, const GLvoid* userParam)
{
std::string srcName;
switch(source)
{
case GL_DEBUG_SOURCE_API_ARB: srcName = "API"; break;
case GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB: srcName = "Window System"; break;
case GL_DEBUG_SOURCE_SHADER_COMPILER_ARB: srcName = "Shader Compiler"; break;
case GL_DEBUG_SOURCE_THIRD_PARTY_ARB: srcName = "Third Party"; break;
case GL_DEBUG_SOURCE_APPLICATION_ARB: srcName = "Application"; break;
case GL_DEBUG_SOURCE_OTHER_ARB: srcName = "Other"; break;
}

std::string errorType;
switch(type)
{
case GL_DEBUG_TYPE_ERROR_ARB: errorType = "Error"; break;
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB: errorType = "Deprecated Functionality"; break;
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB: errorType = "Undefined Behavior"; break;
case GL_DEBUG_TYPE_PORTABILITY_ARB: errorType = "Portability"; break;
case GL_DEBUG_TYPE_PERFORMANCE_ARB: errorType = "Performance"; break;
case GL_DEBUG_TYPE_OTHER_ARB: errorType = "Other"; break;
}

std::string typeSeverity;
switch(severity)
{
case GL_DEBUG_SEVERITY_HIGH_ARB: typeSeverity = "High"; break;
case GL_DEBUG_SEVERITY_MEDIUM_ARB: typeSeverity = "Medium"; break;
case GL_DEBUG_SEVERITY_LOW_ARB: typeSeverity = "Low"; break;
}

printf("%s from %s,\t%s priority\nMessage: %s\n",
errorType.c_str(), srcName.c_str(), typeSeverity.c_str(), message);
}

int main(int argc, char** argv)
// void APIENTRY DebugFunc(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length,
// const GLchar* message, const GLvoid* userParam)
// {
// std::string srcName;
// switch(source)
// {
// case GL_DEBUG_SOURCE_API_ARB: srcName = "API"; break;
// case GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB: srcName = "Window System"; break;
// case GL_DEBUG_SOURCE_SHADER_COMPILER_ARB: srcName = "Shader Compiler"; break;
// case GL_DEBUG_SOURCE_THIRD_PARTY_ARB: srcName = "Third Party"; break;
// case GL_DEBUG_SOURCE_APPLICATION_ARB: srcName = "Application"; break;
// case GL_DEBUG_SOURCE_OTHER_ARB: srcName = "Other"; break;
// }

// std::string errorType;
// switch(type)
// {
// case GL_DEBUG_TYPE_ERROR_ARB: errorType = "Error"; break;
// case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB: errorType = "Deprecated Functionality"; break;
// case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB: errorType = "Undefined Behavior"; break;
// case GL_DEBUG_TYPE_PORTABILITY_ARB: errorType = "Portability"; break;
// case GL_DEBUG_TYPE_PERFORMANCE_ARB: errorType = "Performance"; break;
// case GL_DEBUG_TYPE_OTHER_ARB: errorType = "Other"; break;
// }

// std::string typeSeverity;
// switch(severity)
// {
// case GL_DEBUG_SEVERITY_HIGH_ARB: typeSeverity = "High"; break;
// case GL_DEBUG_SEVERITY_MEDIUM_ARB: typeSeverity = "Medium"; break;
// case GL_DEBUG_SEVERITY_LOW_ARB: typeSeverity = "Low"; break;
// }

// printf("%s from %s,\t%s priority\nMessage: %s\n",
// errorType.c_str(), srcName.c_str(), typeSeverity.c_str(), message);
// }

int main(int argc, char **argv)
{
glutInit(&argc, argv);

int width = 500;
int height = 500;
#if defined(__APPLE__) && !defined(USE_COCOA)
// if we are on apple an not using cocoa, MESA will be used at it does not support GLUT_STENCIL
unsigned int displayMode = GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH;
#else
unsigned int displayMode = GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH | GLUT_STENCIL;
glutInitContextVersion(3, 3);
#endif
displayMode = defaults(displayMode, width, height);

glutInitDisplayMode (displayMode);
glutInitContextVersion (3, 3);
glutInitDisplayMode(displayMode);
glutInitContextProfile(GLUT_CORE_PROFILE);
#ifdef DEBUG
glutInitContextFlags(GLUT_DEBUG);
#endif
glutInitWindowSize (width, height);
glutInitWindowPosition (300, 200);
int window = glutCreateWindow (argv[0]);
glutInitWindowSize(width, height);
glutInitWindowPosition(300, 200);
int window = glutCreateWindow(argv[0]);

glload::LoadFunctions();
// glload::LoadFunctions();

glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);

if(!glload::IsVersionGEQ(3, 3))
{
printf("Your OpenGL version is %i, %i. You must have at least OpenGL 3.3 to run this tutorial.\n",
glload::GetMajorVersion(), glload::GetMinorVersion());
glutDestroyWindow(window);
return 0;
}

if(glext_ARB_debug_output)
{
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
glDebugMessageCallbackARB(DebugFunc, (void*)15);
}
// if(!glload::IsVersionGEQ(3, 3))
// {
// printf("Your OpenGL version is %i, %i. You must have at least OpenGL 3.3 to run this tutorial.\n",
// glload::GetMajorVersion(), glload::GetMinorVersion());
// glutDestroyWindow(window);
// return 0;
// }

// if(glext_ARB_debug_output)
// {
// glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
// glDebugMessageCallbackARB(DebugFunc, (void*)15);
// }

printf("Renderer: %s\n", glGetString(GL_RENDERER));
printf("Vendor: %s\n", glGetString(GL_VENDOR));
printf("Version: %s\n", glGetString(GL_VERSION));
printf("GLSL Version: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));

init();

glutDisplayFunc(display);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
Expand Down
13 changes: 2 additions & 11 deletions glsdk/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
## freeglut
file(GLOB freeglut_SRCS freeglut/src/*.c)
add_library(freeglut STATIC ${freeglut_SRCS})
target_include_directories(freeglut PUBLIC freeglut/include freeglut)
target_compile_definitions(freeglut PUBLIC -DFREEGLUT_STATIC -DFREEGLUT_LIB_PRAGMAS=0)
if(UNIX)
target_compile_definitions(freeglut PRIVATE -DHAVE_CONFIG_H)
execute_process(COMMAND sh ./configure WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/freeglut)
else()
target_link_libraries(freeglut PRIVATE winmm)
endif()
add_subdirectory(freeglut)

## glload
add_library(glload STATIC
Expand All @@ -27,5 +18,5 @@ target_link_libraries(glimg PRIVATE glload)
## glutil
file(GLOB glutil_SRCS glutil/source/*.cpp)
add_library(glutil STATIC ${glutil_SRCS})
target_include_directories(glutil PUBLIC glutil/include glm)
target_include_directories(glutil PUBLIC glutil/include glm freeglut/include)
target_link_libraries(glutil PRIVATE glimg glload)
39 changes: 36 additions & 3 deletions glsdk/freeglut/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@

config.h
Makefile.in
Makefile
INSTALL
.deps
aclocal.m4
autom4te.cache
compile
config.guess
config.sub
configure
configure.cache
config.log
config.status
libtool
config.h
depcomp
install-sh
ltmain.sh
missing
stamp-h1
*.tar
*.tar.gz
*.tar.bz2
*.zip
*.o
*.a
*~
*.swp
cross-android
cross-woe
native
*.exe
*.dll
*.a
CMakeCache.txt
CMakeFiles/
cmake_install.cmake
freeglut.pc
freeglut.rc
FreeGLUT/
Loading
Loading