Skip to content

Commit a3470ad

Browse files
committed
build for mac testing tutorials 1 and 2
1 parent e586421 commit a3470ad

11 files changed

Lines changed: 167 additions & 199 deletions

File tree

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,25 @@ The [License.txt](License.txt) file contains the licensing information for the m
1111

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

14-
## Building the tutorials
14+
## Building the tutorials (non Mac)
1515

1616
- `apt-get install cmake`
1717
- `mkdir build && cd build`
1818
- `cmake ..`
1919
- `cmake --build . --config Release`
2020

21+
## Building the tutorials (Mac)
22+
23+
See [freeglut instructions for Mac](https://github.com/freeglut/freeglut/blob/07a3e80780c289b51bc723415ef41cef6b026aed/README.macosx)
24+
25+
- `brew install cmake`
26+
- `mkdir build && cd build`
27+
- `cmake -DOPENGL_gl_LIBRARY=/usr/local/lib/libGL.dylib ..` (INTEL)
28+
- `cmake -DOPENGL_gl_LIBRARY=/opt/homebrew/lib/libGL.dylib ..` (ARM)
29+
- `cmake --build . --config Release`
30+
31+
* NOTE: you can specify -DFREEGLUT_COCOA=ON to use experimental [freeglut cocoa support](https://github.com/freeglut/freeglut/issues/195)
32+
2133
## Rebuilding the HTML Documentation
2234

2335
- `apt-get install lua-filesystem xsltproc docbook-xsl`

Tut 01 Hello Triangle/Tut1.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
#include <string>
44
#include <vector>
55
#include <stdio.h>
6-
#include <glload/gl_3_2_comp.h>
6+
#ifdef __APPLE__
7+
#define FREEGLUT_NO_GL_INCLUDE
8+
#include <OpenGL/gl3.h>
9+
#endif
710
#include <GL/freeglut.h>
811

9-
1012
GLuint CreateShader(GLenum eShaderType, const std::string &strShaderFile)
1113
{
1214
GLuint shader = glCreateShader(eShaderType);

Tut 02 Playing with Colors/FragPosition.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
#include <vector>
44
#include <math.h>
55
#include <stdio.h>
6-
#include <glload/gl_3_3.h>
6+
#ifdef __APPLE__
7+
#define FREEGLUT_NO_GL_INCLUDE
8+
#include <OpenGL/gl3.h>
9+
#endif
710
#include <GL/freeglut.h>
811
#include "../framework/framework.h"
912

Tut 02 Playing with Colors/VertexColors.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
#include <vector>
44
#include <math.h>
55
#include <stdio.h>
6-
#include <glload/gl_3_3.h>
6+
#ifdef __APPLE__
7+
#define FREEGLUT_NO_GL_INCLUDE
8+
#include <OpenGL/gl3.h>
9+
#endif
710
#include <GL/freeglut.h>
811
#include "../framework/framework.h"
912

framework/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
# for apple support with our without cocoa so we know how to initialize opengl in framework.cpp
2+
IF(FREEGLUT_COCOA)
3+
ADD_DEFINITIONS(-DUSE_COCOA=1)
4+
ENDIF()
5+
16
file(GLOB framework_SRCS "*.cpp")
27
add_library(framework STATIC ${framework_SRCS})
38
target_include_directories(framework PUBLIC . ${CMAKE_SOURCE_DIR}/glsdk/glm)
9+
# is this the best way? isn't there a way to add this to glsdk/CMakeLists.txt where we are `add_subdirectory(freeglut)`
10+
target_include_directories(framework PUBLIC . ${CMAKE_SOURCE_DIR}/glsdk/freeglut/include)
411
target_link_libraries(framework
512
PUBLIC glload glimg glutil freeglut OpenGL::GL
613
)

framework/Mesh.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
#include <functional>
1010
#include <algorithm>
1111
#include <iostream>
12-
#include <glload/gl_3_2_comp.h>
13-
#include <glload/gl_load.h>
12+
#ifdef __APPLE__
13+
#define FREEGLUT_NO_GL_INCLUDE
14+
#include <OpenGL/gl3.h>
15+
#endif
1416
#include <GL/freeglut.h>
1517
#include "framework.h"
1618
#include "Mesh.h"

framework/empty.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ when/why they are called. You can copy this file and simply implement
44
these function.
55
***********************************************************************/
66

7-
#include <glload/gl_3_2_comp.h>
87
#include <GL/freeglut.h>
98

109

framework/framework.cpp

Lines changed: 78 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
#include <exception>
88
#include <stdexcept>
99
#include <string.h>
10-
#include <glload/gl_3_3.h>
11-
#include <glload/gl_load.hpp>
12-
#include <glutil/Shader.h>
10+
#ifdef __APPLE__
11+
#define FREEGLUT_NO_GL_INCLUDE
12+
#include <OpenGL/gl3.h>
13+
#endif
1314
#include <GL/freeglut.h>
15+
#include <glutil/Shader.h>
1416
#include "framework.h"
1517
#include "directories.h"
1618

@@ -32,7 +34,7 @@ namespace Framework
3234
{
3335
return glutil::CompileShader(eShaderType, shaderData.str());
3436
}
35-
catch(std::exception &e)
37+
catch (std::exception &e)
3638
{
3739
fprintf(stderr, "%s\n", e.what());
3840
throw;
@@ -47,7 +49,7 @@ namespace Framework
4749
std::for_each(shaderList.begin(), shaderList.end(), glDeleteShader);
4850
return prog;
4951
}
50-
catch(std::exception &e)
52+
catch (std::exception &e)
5153
{
5254
std::for_each(shaderList.begin(), shaderList.end(), glDeleteShader);
5355
fprintf(stderr, "%s\n", e.what());
@@ -61,108 +63,116 @@ namespace Framework
6163
return fAngDeg * fDegToRad;
6264
}
6365

64-
std::string FindFileOrThrow( const std::string &strBasename )
66+
std::string FindFileOrThrow(const std::string &strBasename)
6567
{
6668
std::string strFilename = LOCAL_FILE_DIR + strBasename;
6769
std::ifstream testFile(strFilename.c_str());
68-
if(testFile.is_open())
70+
if (testFile.is_open())
6971
return strFilename;
7072

71-
7273
strFilename = GLOBAL_FILE_DIR + strBasename;
7374
testFile.open(strFilename.c_str());
74-
if(testFile.is_open())
75+
if (testFile.is_open())
7576
return strFilename;
7677

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

81-
8282
void init();
8383
void display();
8484
void reshape(int w, int h);
8585
void keyboard(unsigned char key, int x, int y);
8686

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

89-
void APIENTRY DebugFunc(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length,
90-
const GLchar* message, const GLvoid* userParam)
91-
{
92-
std::string srcName;
93-
switch(source)
94-
{
95-
case GL_DEBUG_SOURCE_API_ARB: srcName = "API"; break;
96-
case GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB: srcName = "Window System"; break;
97-
case GL_DEBUG_SOURCE_SHADER_COMPILER_ARB: srcName = "Shader Compiler"; break;
98-
case GL_DEBUG_SOURCE_THIRD_PARTY_ARB: srcName = "Third Party"; break;
99-
case GL_DEBUG_SOURCE_APPLICATION_ARB: srcName = "Application"; break;
100-
case GL_DEBUG_SOURCE_OTHER_ARB: srcName = "Other"; break;
101-
}
102-
103-
std::string errorType;
104-
switch(type)
105-
{
106-
case GL_DEBUG_TYPE_ERROR_ARB: errorType = "Error"; break;
107-
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB: errorType = "Deprecated Functionality"; break;
108-
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB: errorType = "Undefined Behavior"; break;
109-
case GL_DEBUG_TYPE_PORTABILITY_ARB: errorType = "Portability"; break;
110-
case GL_DEBUG_TYPE_PERFORMANCE_ARB: errorType = "Performance"; break;
111-
case GL_DEBUG_TYPE_OTHER_ARB: errorType = "Other"; break;
112-
}
113-
114-
std::string typeSeverity;
115-
switch(severity)
116-
{
117-
case GL_DEBUG_SEVERITY_HIGH_ARB: typeSeverity = "High"; break;
118-
case GL_DEBUG_SEVERITY_MEDIUM_ARB: typeSeverity = "Medium"; break;
119-
case GL_DEBUG_SEVERITY_LOW_ARB: typeSeverity = "Low"; break;
120-
}
121-
122-
printf("%s from %s,\t%s priority\nMessage: %s\n",
123-
errorType.c_str(), srcName.c_str(), typeSeverity.c_str(), message);
124-
}
125-
126-
int main(int argc, char** argv)
89+
// void APIENTRY DebugFunc(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length,
90+
// const GLchar* message, const GLvoid* userParam)
91+
// {
92+
// std::string srcName;
93+
// switch(source)
94+
// {
95+
// case GL_DEBUG_SOURCE_API_ARB: srcName = "API"; break;
96+
// case GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB: srcName = "Window System"; break;
97+
// case GL_DEBUG_SOURCE_SHADER_COMPILER_ARB: srcName = "Shader Compiler"; break;
98+
// case GL_DEBUG_SOURCE_THIRD_PARTY_ARB: srcName = "Third Party"; break;
99+
// case GL_DEBUG_SOURCE_APPLICATION_ARB: srcName = "Application"; break;
100+
// case GL_DEBUG_SOURCE_OTHER_ARB: srcName = "Other"; break;
101+
// }
102+
103+
// std::string errorType;
104+
// switch(type)
105+
// {
106+
// case GL_DEBUG_TYPE_ERROR_ARB: errorType = "Error"; break;
107+
// case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB: errorType = "Deprecated Functionality"; break;
108+
// case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB: errorType = "Undefined Behavior"; break;
109+
// case GL_DEBUG_TYPE_PORTABILITY_ARB: errorType = "Portability"; break;
110+
// case GL_DEBUG_TYPE_PERFORMANCE_ARB: errorType = "Performance"; break;
111+
// case GL_DEBUG_TYPE_OTHER_ARB: errorType = "Other"; break;
112+
// }
113+
114+
// std::string typeSeverity;
115+
// switch(severity)
116+
// {
117+
// case GL_DEBUG_SEVERITY_HIGH_ARB: typeSeverity = "High"; break;
118+
// case GL_DEBUG_SEVERITY_MEDIUM_ARB: typeSeverity = "Medium"; break;
119+
// case GL_DEBUG_SEVERITY_LOW_ARB: typeSeverity = "Low"; break;
120+
// }
121+
122+
// printf("%s from %s,\t%s priority\nMessage: %s\n",
123+
// errorType.c_str(), srcName.c_str(), typeSeverity.c_str(), message);
124+
// }
125+
126+
int main(int argc, char **argv)
127127
{
128128
glutInit(&argc, argv);
129129

130130
int width = 500;
131131
int height = 500;
132+
#if defined(__APPLE__) && !defined(USE_COCOA)
133+
// if we are on apple an not using cocoa, MESA will be used at it does not support GLUT_STENCIL
134+
unsigned int displayMode = GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH;
135+
#else
132136
unsigned int displayMode = GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH | GLUT_STENCIL;
137+
glutInitContextVersion(3, 3);
138+
#endif
133139
displayMode = defaults(displayMode, width, height);
134140

135-
glutInitDisplayMode (displayMode);
136-
glutInitContextVersion (3, 3);
141+
glutInitDisplayMode(displayMode);
137142
glutInitContextProfile(GLUT_CORE_PROFILE);
138143
#ifdef DEBUG
139144
glutInitContextFlags(GLUT_DEBUG);
140145
#endif
141-
glutInitWindowSize (width, height);
142-
glutInitWindowPosition (300, 200);
143-
int window = glutCreateWindow (argv[0]);
146+
glutInitWindowSize(width, height);
147+
glutInitWindowPosition(300, 200);
148+
int window = glutCreateWindow(argv[0]);
144149

145-
glload::LoadFunctions();
150+
// glload::LoadFunctions();
146151

147152
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);
148153

149-
if(!glload::IsVersionGEQ(3, 3))
150-
{
151-
printf("Your OpenGL version is %i, %i. You must have at least OpenGL 3.3 to run this tutorial.\n",
152-
glload::GetMajorVersion(), glload::GetMinorVersion());
153-
glutDestroyWindow(window);
154-
return 0;
155-
}
156-
157-
if(glext_ARB_debug_output)
158-
{
159-
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
160-
glDebugMessageCallbackARB(DebugFunc, (void*)15);
161-
}
154+
// if(!glload::IsVersionGEQ(3, 3))
155+
// {
156+
// printf("Your OpenGL version is %i, %i. You must have at least OpenGL 3.3 to run this tutorial.\n",
157+
// glload::GetMajorVersion(), glload::GetMinorVersion());
158+
// glutDestroyWindow(window);
159+
// return 0;
160+
// }
161+
162+
// if(glext_ARB_debug_output)
163+
// {
164+
// glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
165+
// glDebugMessageCallbackARB(DebugFunc, (void*)15);
166+
// }
167+
168+
printf("Renderer: %s\n", glGetString(GL_RENDERER));
169+
printf("Vendor: %s\n", glGetString(GL_VENDOR));
170+
printf("Version: %s\n", glGetString(GL_VERSION));
171+
printf("GLSL Version: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
162172

163173
init();
164174

165-
glutDisplayFunc(display);
175+
glutDisplayFunc(display);
166176
glutReshapeFunc(reshape);
167177
glutKeyboardFunc(keyboard);
168178
glutMainLoop();

glsdk/CMakeLists.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
## freeglut
2-
file(GLOB freeglut_SRCS freeglut/src/*.c)
3-
add_library(freeglut STATIC ${freeglut_SRCS})
4-
target_include_directories(freeglut PUBLIC freeglut/include freeglut)
5-
target_compile_definitions(freeglut PUBLIC -DFREEGLUT_STATIC -DFREEGLUT_LIB_PRAGMAS=0)
6-
if(UNIX)
7-
target_compile_definitions(freeglut PRIVATE -DHAVE_CONFIG_H)
8-
execute_process(COMMAND sh ./configure WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/freeglut)
9-
else()
10-
target_link_libraries(freeglut PRIVATE winmm)
11-
endif()
2+
add_subdirectory(freeglut)
123

134
## glload
145
add_library(glload STATIC

glsdk/freeglut/CMakeLists.txt

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -699,67 +699,6 @@ IF(FREEGLUT_BUILD_STATIC_LIBS)
699699
ENDIF()
700700
INSTALL(FILES ${FREEGLUT_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/GL COMPONENT Devel)
701701

702-
########################
703-
# DEMOS
704-
########################
705-
706-
# Optionally build demos, on by default.
707-
option( FREEGLUT_BUILD_DEMOS "Build FreeGLUT demos." ON )
708-
709-
if (FREEGLUT_BUILD_DEMOS)
710-
if (OPENGL_GLU_FOUND)
711-
list(APPEND DEMO_LIBS ${OPENGL_glu_LIBRARY})
712-
else()
713-
message(FATAL_ERROR "Failed to find the GLU library which is required to build the demos.")
714-
endif()
715-
endif()
716-
717-
MACRO(ADD_DEMO name)
718-
IF( FREEGLUT_BUILD_DEMOS )
719-
IF(FREEGLUT_BUILD_SHARED_LIBS)
720-
ADD_EXECUTABLE(${name} ${ARGN})
721-
TARGET_LINK_LIBRARIES(${name} ${DEMO_LIBS} freeglut)
722-
IF(WIN32 AND MSVC)
723-
SET_TARGET_PROPERTIES(${name} PROPERTIES DEBUG_POSTFIX d)
724-
ENDIF()
725-
ENDIF()
726-
IF(FREEGLUT_BUILD_STATIC_LIBS)
727-
ADD_EXECUTABLE(${name}_static ${ARGN})
728-
TARGET_LINK_LIBRARIES(${name}_static ${DEMO_LIBS} freeglut_static)
729-
IF(WIN32 AND MSVC)
730-
SET_TARGET_PROPERTIES(${name}_static PROPERTIES DEBUG_POSTFIX d)
731-
ENDIF()
732-
ENDIF()
733-
ENDIF()
734-
ENDMACRO()
735-
736-
ADD_DEMO(CallbackMaker progs/demos/CallbackMaker/CallbackMaker.c)
737-
ADD_DEMO(Fractals progs/demos/Fractals/fractals.c)
738-
ADD_DEMO(Fractals_random progs/demos/Fractals_random/fractals_random.c)
739-
ADD_DEMO(Lorenz progs/demos/Lorenz/lorenz.c)
740-
IF (NOT WIN32)
741-
ADD_DEMO(One progs/demos/One/one.c)
742-
ELSE()
743-
ADD_DEMO(One progs/demos/One/one.c
744-
progs/demos/One/one.rc)
745-
ENDIF()
746-
ADD_DEMO(resizer progs/demos/resizer/resizer.c)
747-
ADD_DEMO(multi-touch progs/demos/multi-touch/multi-touch.c)
748-
ADD_DEMO(shapes progs/demos/shapes/shapes.c
749-
progs/demos/shapes/glmatrix.h
750-
progs/demos/shapes/glmatrix.c)
751-
ADD_DEMO(smooth_opengl3 progs/demos/smooth_opengl3/smooth_opengl3.c)
752-
ADD_DEMO(spaceball progs/demos/spaceball/spaceball.c
753-
progs/demos/spaceball/vmath.c
754-
progs/demos/spaceball/vmath.h)
755-
ADD_DEMO(joystick progs/demos/joystick/joystick.c)
756-
ADD_DEMO(subwin progs/demos/subwin/subwin.c)
757-
ADD_DEMO(timer progs/demos/timer/timer.c)
758-
ADD_DEMO(timer_callback progs/demos/timer_callback/timer.c)
759-
ADD_DEMO(keyboard progs/demos/keyboard/keyboard.c)
760-
ADD_DEMO(indexed_color progs/demos/indexed_color/idxcol.c)
761-
ADD_DEMO(3dview progs/demos/3dview/3dview.c)
762-
763702
#######################
764703
# INSTALLATION
765704
#######################

0 commit comments

Comments
 (0)