Skip to content

Use GLAD for all OpenGL demos #777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: apt-update
run: sudo apt-get update -qq
- name: apt get demo-libs
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
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
- name: build allegro5
run: make -C demo/allegro5
- name: build glfw_opengl2
Expand Down
2 changes: 1 addition & 1 deletion demo/allegro5/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ OBJ = $(SRC:.c=.o)
# TODO: Handle Windows build
#ifeq ($(OS),Windows_NT)
#BIN := $(BIN).exe
#LIBS = -lglfw3 -lopengl32 -lm -lGLU32 -lGLEW32
#LIBS = -lglfw3 -lm
#else
LIBS = -lallegro -lallegro_main -lallegro_image -lallegro_font \
-lallegro_ttf -lallegro_primitives -lm
Expand Down
18,481 changes: 18,481 additions & 0 deletions demo/common/glad.h

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions demo/glfw_opengl2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ OBJ = $(SRC:.c=.o)

ifeq ($(OS),Windows_NT)
BIN := $(BIN).exe
LIBS = -lglfw3 -lopengl32 -lm -lGLU32
LIBS = -lglfw3 -lm
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
LIBS := -lglfw3 -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo -lm -lGLEW -L/usr/local/lib
LIBS := -lglfw3 -framework Cocoa -framework IOKit -framework CoreVideo -lm -L/usr/local/lib
else
LIBS = -lglfw -lGL -lm -lGLU
LIBS = -lglfw -lm
endif
endif

Expand Down
5 changes: 5 additions & 0 deletions demo/glfw_opengl2/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include <limits.h>
#include <time.h>

#define GLAD_GL_IMPLEMENTATION
#include "../common/glad.h"

#include <GLFW/glfw3.h>

#define NK_INCLUDE_FIXED_TYPES
Expand Down Expand Up @@ -115,6 +118,8 @@ int main(void)
glfwMakeContextCurrent(win);
glfwGetWindowSize(win, &width, &height);

gladLoadGL((GLADloadfunc)glfwGetProcAddress);

/* GUI */
ctx = nk_glfw3_init(win, NK_GLFW3_INSTALL_CALLBACKS);
/* Load Fonts: if none of these are loaded a default font will be used */
Expand Down
6 changes: 3 additions & 3 deletions demo/glfw_opengl3/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ OBJ = $(SRC:.c=.o)

ifeq ($(OS),Windows_NT)
BIN := $(BIN).exe
LIBS = -lglfw3 -lopengl32 -lm -lGLU32 -lGLEW32
LIBS = -lglfw3 -lm
else
UNAME_S := $(shell uname -s)
GLFW3 := $(shell pkg-config --libs glfw3)
ifeq ($(UNAME_S),Darwin)
LIBS := $(GLFW3) -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo -lm -lGLEW -L/usr/local/lib
LIBS := $(GLFW3) -framework Cocoa -framework IOKit -framework CoreVideo -lm -L/usr/local/lib
else
LIBS = $(GLFW3) -lGL -lm -lGLU -lGLEW
LIBS = $(GLFW3) -lm
endif
endif

Expand Down
11 changes: 5 additions & 6 deletions demo/glfw_opengl3/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
#include <limits.h>
#include <time.h>

#include <GL/glew.h>
#define GLAD_GL_IMPLEMENTATION
#include "../common/glad.h"

#include <GLFW/glfw3.h>

#define NK_INCLUDE_FIXED_TYPES
Expand Down Expand Up @@ -112,13 +114,10 @@ int main(void)
glfwMakeContextCurrent(win);
glfwGetWindowSize(win, &width, &height);

gladLoadGL((GLADloadfunc)glfwGetProcAddress);

/* OpenGL */
glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
glewExperimental = 1;
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to setup GLEW\n");
exit(1);
}

ctx = nk_glfw3_init(&glfw, win, NK_GLFW3_INSTALL_CALLBACKS);
/* Load Fonts: if none of these are loaded a default font will be used */
Expand Down
6 changes: 3 additions & 3 deletions demo/glfw_opengl4/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ OBJ = $(SRC:.c=.o)

ifeq ($(OS),Windows_NT)
BIN := $(BIN).exe
LIBS = -lglfw3 -lopengl32 -lm -lGLU32 -lGLEW32
LIBS = -lglfw3 -lm
else
UNAME_S := $(shell uname -s)
GLFW3 := $(shell pkg-config --libs glfw3)
ifeq ($(UNAME_S),Darwin)
LIBS := $(GLFW3) -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo -lm -lGLEW -L/usr/local/lib
LIBS := $(GLFW3) -framework Cocoa -framework IOKit -framework CoreVideo -lm -L/usr/local/lib
else
LIBS = $(GLFW3) -lGL -lm -lGLU -lGLEW
LIBS = $(GLFW3) -lm
endif
endif

Expand Down
11 changes: 5 additions & 6 deletions demo/glfw_opengl4/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
#include <limits.h>
#include <time.h>

#include <GL/glew.h>
#define GLAD_GL_IMPLEMENTATION
#include "../common/glad.h"

#include <GLFW/glfw3.h>

#define NK_INCLUDE_FIXED_TYPES
Expand Down Expand Up @@ -112,13 +114,10 @@ int main(void)
glfwMakeContextCurrent(win);
glfwGetWindowSize(win, &width, &height);

gladLoadGL((GLADloadfunc)glfwGetProcAddress);

/* OpenGL */
glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
glewExperimental = 1;
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to setup GLEW\n");
exit(1);
}

ctx = nk_glfw3_init(win, NK_GLFW3_INSTALL_CALLBACKS, MAX_VERTEX_BUFFER, MAX_ELEMENT_BUFFER);
/* Load Fonts: if none of these are loaded a default font will be used */
Expand Down
9 changes: 2 additions & 7 deletions demo/sdl_opengl2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@ OBJ = $(SRC:.c=.o)

ifeq ($(OS),Windows_NT)
BIN := $(BIN).exe
LIBS = -lmingw32 -lSDL2main -lSDL2 -lopengl32 -lm -lGLU32
LIBS = -lmingw32 -lSDL2main -lSDL2 -lm
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
LIBS = -lSDL2 -framework OpenGL -lm
else
LIBS = -lSDL2 -lGL -lm -lGLU
endif
LIBS = -lSDL2 -lm
endif

$(BIN):
Expand Down
6 changes: 5 additions & 1 deletion demo/sdl_opengl2/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#include <time.h>

#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>

#define GLAD_GL_IMPLEMENTATION
#include "../common/glad.h"

#define NK_INCLUDE_FIXED_TYPES
#define NK_INCLUDE_STANDARD_IO
Expand Down Expand Up @@ -110,6 +112,8 @@ main(int argc, char *argv[])
glContext = SDL_GL_CreateContext(win);
SDL_GetWindowSize(win, &win_width, &win_height);

gladLoadGL((GLADloadfunc)SDL_GL_GetProcAddress);

/* GUI */
ctx = nk_sdl_init(win);
/* Load Fonts: if none of these are loaded a default font will be used */
Expand Down
9 changes: 2 additions & 7 deletions demo/sdl_opengl3/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@ OBJ = $(SRC:.c=.o)

ifeq ($(OS),Windows_NT)
BIN := $(BIN).exe
LIBS = -lmingw32 -lSDL2main -lSDL2 -lopengl32 -lm -lGLU32 -lGLEW32
LIBS = -lmingw32 -lSDL2main -lSDL2 -lm
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
LIBS = -lSDL2 -framework OpenGL -lm -lGLEW
else
LIBS = -lSDL2 -lGL -lm -lGLU -lGLEW
endif
LIBS = -lSDL2 -lm
endif

$(BIN):
Expand Down
12 changes: 4 additions & 8 deletions demo/sdl_opengl3/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
#include <limits.h>
#include <time.h>

#include <GL/glew.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>

#define GLAD_GL_IMPLEMENTATION
#include "../common/glad.h"

#define NK_INCLUDE_FIXED_TYPES
#define NK_INCLUDE_STANDARD_IO
Expand Down Expand Up @@ -113,13 +114,8 @@ int main(int argc, char *argv[])
glContext = SDL_GL_CreateContext(win);
SDL_GetWindowSize(win, &win_width, &win_height);

/* OpenGL setup */
gladLoadGL((GLADloadfunc)SDL_GL_GetProcAddress);
glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
glewExperimental = 1;
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to setup GLEW\n");
exit(1);
}

ctx = nk_sdl_init(win);
/* Load Fonts: if none of these are loaded a default font will be used */
Expand Down
1 change: 0 additions & 1 deletion demo/sdl_opengl3/nuklear_sdl_gl3.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#define NK_SDL_GL3_H_

#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>

NK_API struct nk_context* nk_sdl_init(SDL_Window *win);
NK_API void nk_sdl_font_stash_begin(struct nk_font_atlas **atlas);
Expand Down
7 changes: 1 addition & 6 deletions demo/sdl_opengles2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ CFLAGS += -std=c89 -Wall -Wextra -pedantic -DSDL_DISABLE_IMMINTRIN_H
SRC = main.c
OBJ = $(SRC:.c=.o)

UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
LIBS = -lSDL2 -framework OpenGLES -lm
else
LIBS = -lSDL2 -lGLESv2 -lm
endif
LIBS = -lSDL2 -lm

$(BIN): prepare
$(CC) $(SRC) $(CFLAGS) -o bin/$(BIN) $(LIBS)
Expand Down
5 changes: 5 additions & 0 deletions demo/sdl_opengles2/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include <limits.h>
#include <time.h>

#define GLAD_GL_IMPLEMENTATION
#include "../common/glad.h"

#define NK_INCLUDE_FIXED_TYPES
#define NK_INCLUDE_STANDARD_IO
#define NK_INCLUDE_STANDARD_VARARGS
Expand Down Expand Up @@ -203,6 +206,8 @@ int main(int argc, char* argv[])
WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_OPENGL|SDL_WINDOW_SHOWN|SDL_WINDOW_ALLOW_HIGHDPI);
glContext = SDL_GL_CreateContext(win);

gladLoadGLES2((GLADloadfunc)SDL_GL_GetProcAddress);

/* OpenGL setup */
glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);

Expand Down
1 change: 0 additions & 1 deletion demo/sdl_opengles2/nuklear_sdl_gles2.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#define NK_SDL_GLES2_H_

#include <SDL2/SDL.h>
#include <SDL2/SDL_opengles2.h>


NK_API struct nk_context* nk_sdl_init(SDL_Window *win);
Expand Down
4 changes: 2 additions & 2 deletions demo/sdl_renderer/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ OBJ = $(SRC:.c=.o)
ifeq ($(OS),Windows_NT)
#TODO
#BIN := $(BIN).exe
#LIBS = -lmingw32 -lSDL2main -lSDL2 -lopengl32 -lm -lGLU32
#LIBS = -lmingw32 -lSDL2main -lSDL2 -lm
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
#TODO LIBS = -lSDL2 -framework OpenGL -lm
#TODO LIBS = -lSDL2 -lm
else
LIBS += -lm -ldl `sdl2-config --libs`
endif
Expand Down
6 changes: 3 additions & 3 deletions demo/sfml_opengl2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ ifeq ($(OS),Windows_NT)
SFML_DIR = C:/Users/Ricky/MinGW-Libs/SFML

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

UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
LIBS = -lsfml-window -lsfml-system -pthread -framework OpenGL
LIBS = -lsfml-window -lsfml-system -pthread
else
LIBS = -DSFML_STATIC -lsfml-window-s -lsfml-system-s -pthread -ludev -lGL -lX11 -lXrandr
LIBS = -DSFML_STATIC -lsfml-window-s -lsfml-system-s -pthread -ludev -lX11 -lXrandr
endif
endif

Expand Down
7 changes: 6 additions & 1 deletion demo/sfml_opengl2/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
#include <limits.h>
#include <time.h>

#include <SFML/OpenGL.hpp>
#define GLAD_GL_IMPLEMENTATION
#include "../common/glad.h"

#include <SFML/Window.hpp>

#define NK_INCLUDE_FIXED_TYPES
Expand Down Expand Up @@ -82,6 +84,9 @@ int main(void)
sf::Window win(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "Demo", sf::Style::Default, settings);
win.setVerticalSyncEnabled(true);
win.setActive(true);

gladLoadGL(sf::Context::getFunction);

glViewport(0, 0, win.getSize().x, win.getSize().y);

/* GUI */
Expand Down
16 changes: 6 additions & 10 deletions demo/sfml_opengl3/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,25 @@ SRC = main.cpp
OBJ = $(SRC:.cpp=.o)

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

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

UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
LIBS = -lsfml-window -lsfml-system -pthread -framework OpenGL
LIBS = -lsfml-window -lsfml-system -pthread
else
LIBS = -DSFML_STATIC -lsfml-window-s -lsfml-system-s -pthread -ludev -lGL -lX11 -lXrandr
LIBS = -DSFML_STATIC -lsfml-window-s -lsfml-system-s -pthread -ludev -lX11 -lXrandr
endif
endif

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

$(BIN):
$(CC) $(GLAD_SRC) $(SRC) $(CFLAGS) $(GLAD_INC) $(SFML_INC) $(SFML_LIB) $(SFML_EXT) -o $(BIN) $(LIBS)
$(CC) $(SRC) $(CFLAGS) $(SFML_INC) $(SFML_LIB) $(SFML_EXT) -o $(BIN) $(LIBS)
4 changes: 1 addition & 3 deletions demo/sfml_opengl3/Readme.md

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions demo/sfml_opengl3/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include <limits.h>
#include <time.h>

#define GLAD_GL_IMPLEMENTATION
#include "../common/glad.h"

#include <SFML/Window.hpp>

#define NK_INCLUDE_FIXED_TYPES
Expand Down Expand Up @@ -84,10 +87,9 @@ int main(void)
sf::Window win(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "Demo", sf::Style::Default, settings);
win.setVerticalSyncEnabled(true);
win.setActive(true);
if(!gladLoadGL()) { /* Load OpenGL extensions */
printf("Failed to load OpenGL extensions!\n");
return -1;
}

gladLoadGL(sf::Context::getFunction);

glViewport(0, 0, win.getSize().x, win.getSize().y);

/* GUI */
Expand Down
Loading