Skip to content

Commit 4c67133

Browse files
committed
Use GLAD for all OpenGL demos
1 parent 56ff406 commit 4c67133

File tree

34 files changed

+18584
-114
lines changed

34 files changed

+18584
-114
lines changed

.github/workflows/ccpp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- name: apt-update
1313
run: sudo apt-get update -qq
1414
- name: apt get demo-libs
15-
run: sudo apt-get install -y --no-install-recommends liballegro5-dev liballegro-image5-dev liballegro-ttf5-dev libglfw3 libglfw3-dev libglew-dev libsdl2-dev libwayland-dev libx11-dev libxft-dev wayland-protocols
15+
run: sudo apt-get install -y --no-install-recommends liballegro5-dev liballegro-image5-dev liballegro-ttf5-dev libglfw3 libglfw3-dev libsdl2-dev libwayland-dev libx11-dev libxft-dev wayland-protocols
1616
- name: build allegro5
1717
run: make -C demo/allegro5
1818
- name: build glfw_opengl2

demo/allegro5/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ OBJ = $(SRC:.c=.o)
1010
# TODO: Handle Windows build
1111
#ifeq ($(OS),Windows_NT)
1212
#BIN := $(BIN).exe
13-
#LIBS = -lglfw3 -lopengl32 -lm -lGLU32 -lGLEW32
13+
#LIBS = -lglfw3 -lm
1414
#else
1515
LIBS = -lallegro -lallegro_main -lallegro_image -lallegro_font \
1616
-lallegro_ttf -lallegro_primitives -lm

demo/common/glad.h

Lines changed: 18481 additions & 0 deletions
Large diffs are not rendered by default.

demo/glfw_opengl2/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ OBJ = $(SRC:.c=.o)
99

1010
ifeq ($(OS),Windows_NT)
1111
BIN := $(BIN).exe
12-
LIBS = -lglfw3 -lopengl32 -lm -lGLU32
12+
LIBS = -lglfw3 -lm
1313
else
1414
UNAME_S := $(shell uname -s)
1515
ifeq ($(UNAME_S),Darwin)
16-
LIBS := -lglfw3 -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo -lm -lGLEW -L/usr/local/lib
16+
LIBS := -lglfw3 -framework Cocoa -framework IOKit -framework CoreVideo -lm -L/usr/local/lib
1717
else
18-
LIBS = -lglfw -lGL -lm -lGLU
18+
LIBS = -lglfw -lm
1919
endif
2020
endif
2121

demo/glfw_opengl2/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include <limits.h>
1010
#include <time.h>
1111

12+
#define GLAD_GL_IMPLEMENTATION
13+
#include "../common/glad.h"
14+
1215
#include <GLFW/glfw3.h>
1316

1417
#define NK_INCLUDE_FIXED_TYPES
@@ -115,6 +118,8 @@ int main(void)
115118
glfwMakeContextCurrent(win);
116119
glfwGetWindowSize(win, &width, &height);
117120

121+
gladLoadGL((GLADloadfunc)glfwGetProcAddress);
122+
118123
/* GUI */
119124
ctx = nk_glfw3_init(win, NK_GLFW3_INSTALL_CALLBACKS);
120125
/* Load Fonts: if none of these are loaded a default font will be used */

demo/glfw_opengl3/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ OBJ = $(SRC:.c=.o)
99

1010
ifeq ($(OS),Windows_NT)
1111
BIN := $(BIN).exe
12-
LIBS = -lglfw3 -lopengl32 -lm -lGLU32 -lGLEW32
12+
LIBS = -lglfw3 -lm
1313
else
1414
UNAME_S := $(shell uname -s)
1515
GLFW3 := $(shell pkg-config --libs glfw3)
1616
ifeq ($(UNAME_S),Darwin)
17-
LIBS := $(GLFW3) -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo -lm -lGLEW -L/usr/local/lib
17+
LIBS := $(GLFW3) -framework Cocoa -framework IOKit -framework CoreVideo -lm -L/usr/local/lib
1818
else
19-
LIBS = $(GLFW3) -lGL -lm -lGLU -lGLEW
19+
LIBS = $(GLFW3) -lm
2020
endif
2121
endif
2222

demo/glfw_opengl3/main.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
#include <limits.h>
1010
#include <time.h>
1111

12-
#include <GL/glew.h>
12+
#define GLAD_GL_IMPLEMENTATION
13+
#include "../common/glad.h"
14+
1315
#include <GLFW/glfw3.h>
1416

1517
#define NK_INCLUDE_FIXED_TYPES
@@ -112,13 +114,10 @@ int main(void)
112114
glfwMakeContextCurrent(win);
113115
glfwGetWindowSize(win, &width, &height);
114116

117+
gladLoadGL((GLADloadfunc)glfwGetProcAddress);
118+
115119
/* OpenGL */
116120
glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
117-
glewExperimental = 1;
118-
if (glewInit() != GLEW_OK) {
119-
fprintf(stderr, "Failed to setup GLEW\n");
120-
exit(1);
121-
}
122121

123122
ctx = nk_glfw3_init(&glfw, win, NK_GLFW3_INSTALL_CALLBACKS);
124123
/* Load Fonts: if none of these are loaded a default font will be used */

demo/glfw_opengl4/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ OBJ = $(SRC:.c=.o)
99

1010
ifeq ($(OS),Windows_NT)
1111
BIN := $(BIN).exe
12-
LIBS = -lglfw3 -lopengl32 -lm -lGLU32 -lGLEW32
12+
LIBS = -lglfw3 -lm
1313
else
1414
UNAME_S := $(shell uname -s)
1515
GLFW3 := $(shell pkg-config --libs glfw3)
1616
ifeq ($(UNAME_S),Darwin)
17-
LIBS := $(GLFW3) -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo -lm -lGLEW -L/usr/local/lib
17+
LIBS := $(GLFW3) -framework Cocoa -framework IOKit -framework CoreVideo -lm -L/usr/local/lib
1818
else
19-
LIBS = $(GLFW3) -lGL -lm -lGLU -lGLEW
19+
LIBS = $(GLFW3) -lm
2020
endif
2121
endif
2222

demo/glfw_opengl4/main.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
#include <limits.h>
1010
#include <time.h>
1111

12-
#include <GL/glew.h>
12+
#define GLAD_GL_IMPLEMENTATION
13+
#include "../common/glad.h"
14+
1315
#include <GLFW/glfw3.h>
1416

1517
#define NK_INCLUDE_FIXED_TYPES
@@ -112,13 +114,10 @@ int main(void)
112114
glfwMakeContextCurrent(win);
113115
glfwGetWindowSize(win, &width, &height);
114116

117+
gladLoadGL((GLADloadfunc)glfwGetProcAddress);
118+
115119
/* OpenGL */
116120
glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
117-
glewExperimental = 1;
118-
if (glewInit() != GLEW_OK) {
119-
fprintf(stderr, "Failed to setup GLEW\n");
120-
exit(1);
121-
}
122121

123122
ctx = nk_glfw3_init(win, NK_GLFW3_INSTALL_CALLBACKS, MAX_VERTEX_BUFFER, MAX_ELEMENT_BUFFER);
124123
/* Load Fonts: if none of these are loaded a default font will be used */

demo/sdl_opengl2/Makefile

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,9 @@ OBJ = $(SRC:.c=.o)
99

1010
ifeq ($(OS),Windows_NT)
1111
BIN := $(BIN).exe
12-
LIBS = -lmingw32 -lSDL2main -lSDL2 -lopengl32 -lm -lGLU32
12+
LIBS = -lmingw32 -lSDL2main -lSDL2 -lm
1313
else
14-
UNAME_S := $(shell uname -s)
15-
ifeq ($(UNAME_S),Darwin)
16-
LIBS = -lSDL2 -framework OpenGL -lm
17-
else
18-
LIBS = -lSDL2 -lGL -lm -lGLU
19-
endif
14+
LIBS = -lSDL2 -lm
2015
endif
2116

2217
$(BIN):

demo/sdl_opengl2/main.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
#include <time.h>
1111

1212
#include <SDL2/SDL.h>
13-
#include <SDL2/SDL_opengl.h>
13+
14+
#define GLAD_GL_IMPLEMENTATION
15+
#include "../common/glad.h"
1416

1517
#define NK_INCLUDE_FIXED_TYPES
1618
#define NK_INCLUDE_STANDARD_IO
@@ -110,6 +112,8 @@ main(int argc, char *argv[])
110112
glContext = SDL_GL_CreateContext(win);
111113
SDL_GetWindowSize(win, &win_width, &win_height);
112114

115+
gladLoadGL((GLADloadfunc)SDL_GL_GetProcAddress);
116+
113117
/* GUI */
114118
ctx = nk_sdl_init(win);
115119
/* Load Fonts: if none of these are loaded a default font will be used */

demo/sdl_opengl3/Makefile

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,9 @@ OBJ = $(SRC:.c=.o)
99

1010
ifeq ($(OS),Windows_NT)
1111
BIN := $(BIN).exe
12-
LIBS = -lmingw32 -lSDL2main -lSDL2 -lopengl32 -lm -lGLU32 -lGLEW32
12+
LIBS = -lmingw32 -lSDL2main -lSDL2 -lm
1313
else
14-
UNAME_S := $(shell uname -s)
15-
ifeq ($(UNAME_S),Darwin)
16-
LIBS = -lSDL2 -framework OpenGL -lm -lGLEW
17-
else
18-
LIBS = -lSDL2 -lGL -lm -lGLU -lGLEW
19-
endif
14+
LIBS = -lSDL2 -lm
2015
endif
2116

2217
$(BIN):

demo/sdl_opengl3/main.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
#include <limits.h>
1010
#include <time.h>
1111

12-
#include <GL/glew.h>
1312
#include <SDL2/SDL.h>
14-
#include <SDL2/SDL_opengl.h>
13+
14+
#define GLAD_GL_IMPLEMENTATION
15+
#include "../common/glad.h"
1516

1617
#define NK_INCLUDE_FIXED_TYPES
1718
#define NK_INCLUDE_STANDARD_IO
@@ -113,13 +114,8 @@ int main(int argc, char *argv[])
113114
glContext = SDL_GL_CreateContext(win);
114115
SDL_GetWindowSize(win, &win_width, &win_height);
115116

116-
/* OpenGL setup */
117+
gladLoadGL((GLADloadfunc)SDL_GL_GetProcAddress);
117118
glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
118-
glewExperimental = 1;
119-
if (glewInit() != GLEW_OK) {
120-
fprintf(stderr, "Failed to setup GLEW\n");
121-
exit(1);
122-
}
123119

124120
ctx = nk_sdl_init(win);
125121
/* Load Fonts: if none of these are loaded a default font will be used */

demo/sdl_opengl3/nuklear_sdl_gl3.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#define NK_SDL_GL3_H_
1515

1616
#include <SDL2/SDL.h>
17-
#include <SDL2/SDL_opengl.h>
1817

1918
NK_API struct nk_context* nk_sdl_init(SDL_Window *win);
2019
NK_API void nk_sdl_font_stash_begin(struct nk_font_atlas **atlas);

demo/sdl_opengles2/Makefile

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@ CFLAGS += -std=c89 -Wall -Wextra -pedantic -DSDL_DISABLE_IMMINTRIN_H
77
SRC = main.c
88
OBJ = $(SRC:.c=.o)
99

10-
UNAME_S := $(shell uname -s)
11-
ifeq ($(UNAME_S),Darwin)
12-
LIBS = -lSDL2 -framework OpenGLES -lm
13-
else
14-
LIBS = -lSDL2 -lGLESv2 -lm
15-
endif
10+
LIBS = -lSDL2 -lm
1611

1712
$(BIN): prepare
1813
$(CC) $(SRC) $(CFLAGS) -o bin/$(BIN) $(LIBS)

demo/sdl_opengles2/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include <limits.h>
1010
#include <time.h>
1111

12+
#define GLAD_GL_IMPLEMENTATION
13+
#include "../common/glad.h"
14+
1215
#define NK_INCLUDE_FIXED_TYPES
1316
#define NK_INCLUDE_STANDARD_IO
1417
#define NK_INCLUDE_STANDARD_VARARGS
@@ -203,6 +206,8 @@ int main(int argc, char* argv[])
203206
WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_OPENGL|SDL_WINDOW_SHOWN|SDL_WINDOW_ALLOW_HIGHDPI);
204207
glContext = SDL_GL_CreateContext(win);
205208

209+
gladLoadGLES2((GLADloadfunc)SDL_GL_GetProcAddress);
210+
206211
/* OpenGL setup */
207212
glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
208213

demo/sdl_opengles2/nuklear_sdl_gles2.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#define NK_SDL_GLES2_H_
1717

1818
#include <SDL2/SDL.h>
19-
#include <SDL2/SDL_opengles2.h>
2019

2120

2221
NK_API struct nk_context* nk_sdl_init(SDL_Window *win);

demo/sdl_renderer/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ OBJ = $(SRC:.c=.o)
1111
ifeq ($(OS),Windows_NT)
1212
#TODO
1313
#BIN := $(BIN).exe
14-
#LIBS = -lmingw32 -lSDL2main -lSDL2 -lopengl32 -lm -lGLU32
14+
#LIBS = -lmingw32 -lSDL2main -lSDL2 -lm
1515
else
1616
UNAME_S := $(shell uname -s)
1717
ifeq ($(UNAME_S),Darwin)
18-
#TODO LIBS = -lSDL2 -framework OpenGL -lm
18+
#TODO LIBS = -lSDL2 -lm
1919
else
2020
LIBS += -lm -ldl `sdl2-config --libs`
2121
endif

demo/sfml_opengl2/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ ifeq ($(OS),Windows_NT)
1313
SFML_DIR = C:/Users/Ricky/MinGW-Libs/SFML
1414

1515
BIN := $(BIN).exe
16-
LIBS = -lmingw32 -DSFML_STATIC -lsfml-window-s -lsfml-system-s -lopengl32 -lwinmm -lgdi32
16+
LIBS = -lmingw32 -DSFML_STATIC -lsfml-window-s -lsfml-system-s -lwinmm -lgdi32
1717
else
1818
# Edit the line below to point to your SFML folder on Linux/MacOS
1919
SFML_DIR = /home/ricky/Libraries/SFML
2020

2121
UNAME_S := $(shell uname -s)
2222
ifeq ($(UNAME_S),Darwin)
23-
LIBS = -lsfml-window -lsfml-system -pthread -framework OpenGL
23+
LIBS = -lsfml-window -lsfml-system -pthread
2424
else
25-
LIBS = -DSFML_STATIC -lsfml-window-s -lsfml-system-s -pthread -ludev -lGL -lX11 -lXrandr
25+
LIBS = -DSFML_STATIC -lsfml-window-s -lsfml-system-s -pthread -ludev -lX11 -lXrandr
2626
endif
2727
endif
2828

demo/sfml_opengl2/main.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
#include <limits.h>
1010
#include <time.h>
1111

12-
#include <SFML/OpenGL.hpp>
12+
#define GLAD_GL_IMPLEMENTATION
13+
#include "../common/glad.h"
14+
1315
#include <SFML/Window.hpp>
1416

1517
#define NK_INCLUDE_FIXED_TYPES
@@ -82,6 +84,9 @@ int main(void)
8284
sf::Window win(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "Demo", sf::Style::Default, settings);
8385
win.setVerticalSyncEnabled(true);
8486
win.setActive(true);
87+
88+
gladLoadGL(sf::Context::getFunction);
89+
8590
glViewport(0, 0, win.getSize().x, win.getSize().y);
8691

8792
/* GUI */

demo/sfml_opengl3/Makefile

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,25 @@ SRC = main.cpp
99
OBJ = $(SRC:.cpp=.o)
1010

1111
ifeq ($(OS),Windows_NT)
12-
# Edit the line below to point to your SFML/GLAD folder on Windows
12+
# Edit the line below to point to your SFML folder on Windows
1313
SFML_DIR = C:/Users/Ricky/MinGW-Libs/SFML
14-
GLAD_DIR = C:/Users/Ricky/MinGW-Libs/GLAD
1514

1615
BIN := $(BIN).exe
17-
LIBS = -lmingw32 -DSFML_STATIC -lsfml-window-s -lsfml-system-s -lopengl32 -lwinmm -lgdi32
16+
LIBS = -lmingw32 -DSFML_STATIC -lsfml-window-s -lsfml-system-s -lwinmm -lgdi32
1817
else
19-
# Edit the line below to point to your SFML/GLAD folder on Linux/MacOS
18+
# Edit the line below to point to your SFML folder on Linux/MacOS
2019
SFML_DIR = /home/ricky/Libraries/SFML
21-
GLAD_DIR = /home/ricky/Libraries/GLAD
2220

2321
UNAME_S := $(shell uname -s)
2422
ifeq ($(UNAME_S),Darwin)
25-
LIBS = -lsfml-window -lsfml-system -pthread -framework OpenGL
23+
LIBS = -lsfml-window -lsfml-system -pthread
2624
else
27-
LIBS = -DSFML_STATIC -lsfml-window-s -lsfml-system-s -pthread -ludev -lGL -lX11 -lXrandr
25+
LIBS = -DSFML_STATIC -lsfml-window-s -lsfml-system-s -pthread -ludev -lX11 -lXrandr
2826
endif
2927
endif
3028

3129
SFML_INC = -I $(SFML_DIR)/include
3230
SFML_LIB = -L $(SFML_DIR)/lib
33-
GLAD_INC = -I $(GLAD_DIR)/include
34-
GLAD_SRC = $(GLAD_DIR)/src/glad.c
3531

3632
$(BIN):
37-
$(CC) $(GLAD_SRC) $(SRC) $(CFLAGS) $(GLAD_INC) $(SFML_INC) $(SFML_LIB) $(SFML_EXT) -o $(BIN) $(LIBS)
33+
$(CC) $(SRC) $(CFLAGS) $(SFML_INC) $(SFML_LIB) $(SFML_EXT) -o $(BIN) $(LIBS)

demo/sfml_opengl3/Readme.md

Lines changed: 1 addition & 3 deletions
Large diffs are not rendered by default.

demo/sfml_opengl3/main.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include <limits.h>
1010
#include <time.h>
1111

12+
#define GLAD_GL_IMPLEMENTATION
13+
#include "../common/glad.h"
14+
1215
#include <SFML/Window.hpp>
1316

1417
#define NK_INCLUDE_FIXED_TYPES
@@ -84,10 +87,9 @@ int main(void)
8487
sf::Window win(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "Demo", sf::Style::Default, settings);
8588
win.setVerticalSyncEnabled(true);
8689
win.setActive(true);
87-
if(!gladLoadGL()) { /* Load OpenGL extensions */
88-
printf("Failed to load OpenGL extensions!\n");
89-
return -1;
90-
}
90+
91+
gladLoadGL(sf::Context::getFunction);
92+
9193
glViewport(0, 0, win.getSize().x, win.getSize().y);
9294

9395
/* GUI */

0 commit comments

Comments
 (0)