Initial commit - some engine bugs stopping compiling
This commit is contained in:
76
third-party/glad/example/c/egl_gles2_glfw_emscripten.c
vendored
Normal file
76
third-party/glad/example/c/egl_gles2_glfw_emscripten.c
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <glad/egl.h>
|
||||
#include <glad/gles2.h>
|
||||
|
||||
#define GLFW_INCLUDE_NONE 1
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#else
|
||||
#define GLFW_EXPOSE_NATIVE_EGL 1
|
||||
#include <GLFW/glfw3native.h>
|
||||
#endif
|
||||
|
||||
const GLuint WIDTH = 800, HEIGHT = 600;
|
||||
|
||||
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode) {
|
||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
}
|
||||
|
||||
void render_frame(GLFWwindow *window) {
|
||||
glfwPollEvents();
|
||||
|
||||
glClearColor(0.7f, 0.9f, 0.1f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
glfwInit();
|
||||
srand(time(NULL));
|
||||
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
||||
glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
|
||||
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
|
||||
|
||||
GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "[glad] EGL with GLFW", NULL, NULL);
|
||||
glfwMakeContextCurrent(window);
|
||||
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
|
||||
#ifndef __EMSCRIPTEN__
|
||||
/* Load EGL */
|
||||
EGLDisplay display = glfwGetEGLDisplay();
|
||||
int egl_version = gladLoaderLoadEGL(display);
|
||||
printf("EGL %d.%d\n", GLAD_VERSION_MAJOR(egl_version), GLAD_VERSION_MINOR(egl_version));
|
||||
#endif
|
||||
|
||||
/* Load GLES */
|
||||
int gles_version = 0;
|
||||
if (rand() % 100 < 50) {
|
||||
printf("-> using GLFW to load GLES2\n");
|
||||
gles_version = gladLoadGLES2(glfwGetProcAddress);
|
||||
} else {
|
||||
printf("-> using GLAD loader to load GLES2\n");
|
||||
gles_version = gladLoaderLoadGLES2();
|
||||
}
|
||||
printf("GLES %d.%d\n", GLAD_VERSION_MAJOR(gles_version), GLAD_VERSION_MINOR(gles_version));
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop_arg((em_arg_callback_func) render_frame, window, 60, 1);
|
||||
#else
|
||||
while (!glfwWindowShouldClose(window)) { render_frame(window); }
|
||||
#endif
|
||||
|
||||
glfwTerminate();
|
||||
|
||||
return 0;
|
||||
}
|
||||
21
third-party/glad/example/c/egl_x11/CMakeLists.txt
vendored
Normal file
21
third-party/glad/example/c/egl_x11/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
project(glad_examples_c_egl_x11 C)
|
||||
|
||||
find_package(X11 REQUIRED)
|
||||
|
||||
set(GLAD_SOURCES_DIR "${PROJECT_SOURCE_DIR}/../../..")
|
||||
add_subdirectory("${GLAD_SOURCES_DIR}/cmake" glad_cmake)
|
||||
|
||||
glad_add_library(glad_egl_15_gles2_20 REPRODUCIBLE LOADER API egl=1.5 gles2=2.0)
|
||||
add_executable(egl_x11
|
||||
egl_x11.c
|
||||
)
|
||||
target_include_directories(egl_x11
|
||||
PUBLIC
|
||||
${X11_INCLUDE_DIR}
|
||||
)
|
||||
target_link_libraries(egl_x11
|
||||
PUBLIC
|
||||
glad_egl_15_gles2_20
|
||||
${X11_LIBRARIES}
|
||||
)
|
||||
163
third-party/glad/example/c/egl_x11/egl_x11.c
vendored
Normal file
163
third-party/glad/example/c/egl_x11/egl_x11.c
vendored
Normal file
@@ -0,0 +1,163 @@
|
||||
// gcc example/c/egl_x11.c -Ibuild/include build/src/*.c -ldl -lX11
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
#include <glad/egl.h>
|
||||
#include <glad/gles2.h>
|
||||
|
||||
|
||||
const int window_width = 800, window_height = 480;
|
||||
|
||||
|
||||
int main(void) {
|
||||
Display *display = XOpenDisplay(NULL);
|
||||
if (display == NULL) {
|
||||
printf("cannot connect to X server\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int screen = DefaultScreen(display);
|
||||
Window root = RootWindow(display, screen);
|
||||
Visual *visual = DefaultVisual(display, screen);
|
||||
|
||||
Colormap colormap = XCreateColormap(display, root, visual, AllocNone);
|
||||
|
||||
XSetWindowAttributes attributes;
|
||||
attributes.colormap = colormap;
|
||||
attributes.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask;
|
||||
|
||||
Window window =
|
||||
XCreateWindow(display, root, 0, 0, window_width, window_height, 0,
|
||||
DefaultDepth(display, screen), InputOutput, visual,
|
||||
CWColormap | CWEventMask, &attributes);
|
||||
|
||||
XFreeColormap(display, colormap);
|
||||
|
||||
XMapWindow(display, window);
|
||||
XStoreName(display, window, "[glad] EGL with X11");
|
||||
|
||||
if (!window) {
|
||||
printf("Unable to create window.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int egl_version = gladLoaderLoadEGL(NULL);
|
||||
if (!egl_version) {
|
||||
printf("Unable to load EGL.\n");
|
||||
return 1;
|
||||
}
|
||||
printf("Loaded EGL %d.%d on first load.\n",
|
||||
GLAD_VERSION_MAJOR(egl_version), GLAD_VERSION_MINOR(egl_version));
|
||||
|
||||
EGLDisplay egl_display = eglGetDisplay((EGLNativeDisplayType) display);
|
||||
if (egl_display == EGL_NO_DISPLAY) {
|
||||
printf("Got no EGL display.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!eglInitialize(egl_display, NULL, NULL)) {
|
||||
printf("Unable to initialize EGL\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
egl_version = gladLoaderLoadEGL(egl_display);
|
||||
if (!egl_version) {
|
||||
printf("Unable to reload EGL.\n");
|
||||
return 1;
|
||||
}
|
||||
printf("Loaded EGL %d.%d after reload.\n",
|
||||
GLAD_VERSION_MAJOR(egl_version), GLAD_VERSION_MINOR(egl_version));
|
||||
|
||||
EGLint attr[] = {
|
||||
EGL_BUFFER_SIZE, 16,
|
||||
EGL_RENDERABLE_TYPE,
|
||||
EGL_OPENGL_ES2_BIT,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
EGLConfig egl_config;
|
||||
EGLint num_config;
|
||||
if (!eglChooseConfig(egl_display, attr, &egl_config, 1, &num_config)) {
|
||||
printf("Failed to choose config (eglError: %d)\n", eglGetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (num_config != 1) {
|
||||
printf("Didn't get exactly one config, but %d\n", num_config);
|
||||
return 1;
|
||||
}
|
||||
|
||||
EGLSurface egl_surface =
|
||||
eglCreateWindowSurface(egl_display, egl_config, window, NULL);
|
||||
if (egl_surface == EGL_NO_SURFACE) {
|
||||
printf("Unable to create EGL surface (eglError: %d)\n",
|
||||
eglGetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
EGLint ctxattr[] = {
|
||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||||
EGL_NONE
|
||||
};
|
||||
EGLContext egl_context =
|
||||
eglCreateContext(egl_display, egl_config, EGL_NO_CONTEXT, ctxattr);
|
||||
if (egl_context == EGL_NO_CONTEXT) {
|
||||
printf("Unable to create EGL context (eglError: %d)\n",
|
||||
eglGetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
// activate context before loading GL functions using glad
|
||||
eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context);
|
||||
|
||||
int gles_version = gladLoaderLoadGLES2();
|
||||
if (!gles_version) {
|
||||
printf("Unable to load GLES.\n");
|
||||
return 1;
|
||||
}
|
||||
printf("Loaded GLES %d.%d.\n",
|
||||
GLAD_VERSION_MAJOR(gles_version), GLAD_VERSION_MINOR(gles_version));
|
||||
|
||||
XWindowAttributes gwa;
|
||||
XGetWindowAttributes(display, window, &gwa);
|
||||
glViewport(0, 0, gwa.width, gwa.height);
|
||||
|
||||
bool quit = false;
|
||||
while (!quit) {
|
||||
while (XPending(display)) {
|
||||
XEvent xev;
|
||||
XNextEvent(display, &xev);
|
||||
|
||||
if (xev.type == KeyPress) {
|
||||
quit = true;
|
||||
}
|
||||
}
|
||||
|
||||
glClearColor(0.8, 0.6, 0.7, 1.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
eglSwapBuffers(egl_display, egl_surface);
|
||||
|
||||
usleep(1000 * 10);
|
||||
}
|
||||
|
||||
gladLoaderUnloadGLES2();
|
||||
|
||||
eglDestroyContext(egl_display, egl_context);
|
||||
eglDestroySurface(egl_display, egl_surface);
|
||||
eglTerminate(egl_display);
|
||||
|
||||
gladLoaderUnloadEGL();
|
||||
|
||||
XDestroyWindow(display, window);
|
||||
XCloseDisplay(display);
|
||||
|
||||
return 0;
|
||||
}
|
||||
44
third-party/glad/example/c/gl_glfw.c
vendored
Normal file
44
third-party/glad/example/c/gl_glfw.c
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define GLAD_GL_IMPLEMENTATION // Necessary for headeronly version.
|
||||
#include <glad/gl.h>
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
|
||||
const GLuint WIDTH = 800, HEIGHT = 600;
|
||||
|
||||
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode) {
|
||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
glfwInit();
|
||||
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
|
||||
GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "[glad] GL with GLFW", NULL, NULL);
|
||||
glfwMakeContextCurrent(window);
|
||||
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
|
||||
int version = gladLoadGL(glfwGetProcAddress);
|
||||
printf("GL %d.%d\n", GLAD_VERSION_MAJOR(version), GLAD_VERSION_MINOR(version));
|
||||
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
glfwPollEvents();
|
||||
|
||||
glClearColor(0.7f, 0.9f, 0.1f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
|
||||
glfwTerminate();
|
||||
|
||||
return 0;
|
||||
}
|
||||
73
third-party/glad/example/c/gl_glfw_on_demand.c
vendored
Normal file
73
third-party/glad/example/c/gl_glfw_on_demand.c
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
// This example requires you to generate glad with the --on-demand option and optionally --loader and --debug.
|
||||
// gcc -o gl_glfw_on_demand example/c/gl_glfw_on_demand.c build/src/gl.c -Ibuild/include -ldl -lglfw
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <glad/gl.h>
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
|
||||
const GLuint WIDTH = 800, HEIGHT = 600;
|
||||
|
||||
|
||||
static void pre_call_gl_callback(const char *name, GLADapiproc apiproc, int len_args, ...) {
|
||||
printf("about to call gl func: %s\n", name);
|
||||
}
|
||||
|
||||
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode) {
|
||||
if (action != GLFW_PRESS) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (key == GLFW_KEY_ESCAPE) {
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
#ifdef GLAD_OPTION_GL_DEBUG
|
||||
} else if (key == GLFW_KEY_H) {
|
||||
printf("Installing glad debug function pointers\n");
|
||||
gladInstallGLDebug();
|
||||
} else if (key == GLFW_KEY_J) {
|
||||
printf("Uninstalling glad debug function pointers\n");
|
||||
gladUninstallGLDebug();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
glfwInit();
|
||||
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
|
||||
GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "[glad] GL with GLFW", NULL, NULL);
|
||||
glfwMakeContextCurrent(window);
|
||||
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
|
||||
// If glad is generated with the --loader and --on-demand option
|
||||
// you don't have to call any glad function.
|
||||
// It is recommended to use the loader provided by your context creation library
|
||||
// instead of the glad loader.
|
||||
#ifndef GLAD_GL_LOADER
|
||||
gladSetGLOnDemandLoader(glfwGetProcAddress);
|
||||
#endif
|
||||
|
||||
#ifdef GLAD_OPTION_GL_DEBUG
|
||||
gladUninstallGLDebug();
|
||||
gladSetGLPreCallback(pre_call_gl_callback);
|
||||
#endif
|
||||
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
glfwPollEvents();
|
||||
|
||||
glClearColor(0.7f, 0.9f, 0.1f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
|
||||
glfwTerminate();
|
||||
|
||||
return 0;
|
||||
}
|
||||
64
third-party/glad/example/c/gl_sdl2.c
vendored
Normal file
64
third-party/glad/example/c/gl_sdl2.c
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
// gcc example/c/gl_sdl2.c build/src/gl.c -Ibuild/include `sdl2-config --libs --cflags` -ldl
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <glad/gl.h>
|
||||
#include <SDL.h>
|
||||
#include <SDL_opengl.h>
|
||||
|
||||
|
||||
const GLuint WIDTH = 800, HEIGHT = 600;
|
||||
|
||||
int main(void) {
|
||||
// code without checking for errors
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||
|
||||
SDL_Window *window = SDL_CreateWindow(
|
||||
"[glad] GL with SDL",
|
||||
SDL_WINDOWPOS_CENTERED,
|
||||
SDL_WINDOWPOS_CENTERED,
|
||||
WIDTH, HEIGHT,
|
||||
SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN
|
||||
);
|
||||
|
||||
SDL_GLContext context = SDL_GL_CreateContext(window);
|
||||
|
||||
int version = gladLoadGL((GLADloadfunc) SDL_GL_GetProcAddress);
|
||||
printf("GL %d.%d\n", GLAD_VERSION_MAJOR(version), GLAD_VERSION_MINOR(version));
|
||||
|
||||
int exit = 0;
|
||||
while(!exit) {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch(event.type) {
|
||||
case SDL_QUIT:
|
||||
exit = 1;
|
||||
break;
|
||||
case SDL_KEYUP:
|
||||
if (event.key.keysym.sym == SDLK_ESCAPE) {
|
||||
exit = 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
glClearColor(0.7f, 0.9f, 0.1f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
SDL_GL_SwapWindow(window);
|
||||
SDL_Delay(1);
|
||||
}
|
||||
|
||||
SDL_GL_DeleteContext(context);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
55
third-party/glad/example/c/gles2_glfw_emscripten.c
vendored
Normal file
55
third-party/glad/example/c/gles2_glfw_emscripten.c
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <glad/gles2.h>
|
||||
|
||||
#define GLFW_INCLUDE_NONE 1
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
|
||||
const GLuint WIDTH = 800, HEIGHT = 600;
|
||||
|
||||
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode) {
|
||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
}
|
||||
|
||||
void render_frame(GLFWwindow *window) {
|
||||
glfwPollEvents();
|
||||
|
||||
glClearColor(0.7f, 0.9f, 0.1f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
glfwInit();
|
||||
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
||||
glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
|
||||
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
|
||||
|
||||
GLFWwindow *window = glfwCreateWindow(WIDTH, HEIGHT, "[glad] GLES2 with GLFW", NULL, NULL);
|
||||
glfwMakeContextCurrent(window);
|
||||
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
|
||||
/* Load GLES */
|
||||
int gles_version = gladLoadGLES2(glfwGetProcAddress);
|
||||
printf("GLES %d.%d\n", GLAD_VERSION_MAJOR(gles_version), GLAD_VERSION_MINOR(gles_version));
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop_arg((em_arg_callback_func) render_frame, window, 60, 1);
|
||||
#else
|
||||
while (!glfwWindowShouldClose(window)) { render_frame(window); }
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
78
third-party/glad/example/c/glut.c
vendored
Normal file
78
third-party/glad/example/c/glut.c
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <glad/gl.h>
|
||||
#ifdef __APPLE__
|
||||
#include <GLUT/glut.h>
|
||||
#else
|
||||
#include <GL/glut.h>
|
||||
#endif
|
||||
|
||||
// This file is a modified version of gl3w's test.c
|
||||
// https://github.com/skaslev/gl3w/blob/master/src/test.c
|
||||
|
||||
// Compile:
|
||||
// gcc example/c/simple.c -Ibuild/include build/src/glad.c -lglut -ldl
|
||||
|
||||
|
||||
static int width = 600, height = 600;
|
||||
|
||||
static void display(void)
|
||||
{
|
||||
glClearColor(1.0f, 0.2f, 0.7f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glutSwapBuffers();
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
static void reshape(int w, int h)
|
||||
{
|
||||
width = w > 1 ? w : 1;
|
||||
height = h > 1 ? h : 1;
|
||||
glViewport(0, 0, width, height);
|
||||
glClearDepth(1.0);
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
static void keyboard(unsigned char key, int x, int y)
|
||||
{
|
||||
switch (key) {
|
||||
case 27: // Escape key
|
||||
glutDestroyWindow(1);
|
||||
return;
|
||||
}
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
glutInit(&argc, argv);
|
||||
glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
|
||||
glutInitWindowSize(width, height);
|
||||
glutCreateWindow("cookie");
|
||||
|
||||
glutReshapeFunc(reshape);
|
||||
glutDisplayFunc(display);
|
||||
glutKeyboardFunc(keyboard);
|
||||
|
||||
// initialize glad after creating a context
|
||||
int version = gladLoaderLoadGL();
|
||||
if(version == 0) {
|
||||
printf("Something went wrong!\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
printf("OpenGL %d.%d\n", GLAD_VERSION_MAJOR(version), GLAD_VERSION_MINOR(version));
|
||||
if (!GLAD_GL_VERSION_2_0) {
|
||||
printf("Your system doesn't support OpenGL >= 2!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("OpenGL %s, GLSL %s\n",
|
||||
glGetString(GL_VERSION),
|
||||
glGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||
|
||||
glutMainLoop();
|
||||
|
||||
return 0;
|
||||
}
|
||||
98
third-party/glad/example/c/glx.c
vendored
Normal file
98
third-party/glad/example/c/glx.c
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
// gcc example/c/glx.c -o build/glx -Ibuild/include build/src/*.c -ldl -lX11
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
#include <glad/gl.h>
|
||||
#include <glad/glx.h>
|
||||
|
||||
|
||||
const int window_width = 800, window_height = 480;
|
||||
|
||||
|
||||
int main(void) {
|
||||
Display *display = XOpenDisplay(NULL);
|
||||
if (display == NULL) {
|
||||
printf("cannot connect to X server\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int screen = DefaultScreen(display);
|
||||
|
||||
int glx_version = gladLoaderLoadGLX(display, screen);
|
||||
if (!glx_version) {
|
||||
printf("Unable to load GLX.\n");
|
||||
return 1;
|
||||
}
|
||||
printf("Loaded GLX %d.%d\n", GLAD_VERSION_MAJOR(glx_version), GLAD_VERSION_MINOR(glx_version));
|
||||
|
||||
Window root = RootWindow(display, screen);
|
||||
|
||||
GLint visual_attributes[] = { GLX_RGBA, GLX_DOUBLEBUFFER, None };
|
||||
XVisualInfo *visual_info = glXChooseVisual(display, screen, visual_attributes);
|
||||
|
||||
Colormap colormap = XCreateColormap(display, root, visual_info->visual, AllocNone);
|
||||
|
||||
XSetWindowAttributes attributes;
|
||||
attributes.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask;
|
||||
attributes.colormap = colormap;
|
||||
|
||||
Window window =
|
||||
XCreateWindow(display, root, 0, 0, window_width, window_height, 0,
|
||||
visual_info->depth, InputOutput, visual_info->visual,
|
||||
CWColormap | CWEventMask, &attributes);
|
||||
|
||||
XMapWindow(display, window);
|
||||
XStoreName(display, window, "[glad] GLX with X11");
|
||||
|
||||
if (!window) {
|
||||
printf("Unable to create window.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
GLXContext context = glXCreateContext(display, visual_info, NULL, GL_TRUE);
|
||||
glXMakeCurrent(display, window, context);
|
||||
|
||||
int gl_version = gladLoaderLoadGL();
|
||||
if (!gl_version) {
|
||||
printf("Unable to load GL.\n");
|
||||
return 1;
|
||||
}
|
||||
printf("Loaded GL %d.%d\n", GLAD_VERSION_MAJOR(gl_version), GLAD_VERSION_MINOR(gl_version));
|
||||
|
||||
XWindowAttributes gwa;
|
||||
XGetWindowAttributes(display, window, &gwa);
|
||||
glViewport(0, 0, gwa.width, gwa.height);
|
||||
|
||||
bool quit = false;
|
||||
while (!quit) {
|
||||
while (XPending(display)) {
|
||||
XEvent xev;
|
||||
XNextEvent(display, &xev);
|
||||
|
||||
if (xev.type == KeyPress) {
|
||||
quit = true;
|
||||
}
|
||||
}
|
||||
|
||||
glClearColor(0.8, 0.6, 0.7, 1.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glXSwapBuffers(display, window);
|
||||
|
||||
usleep(1000 * 10);
|
||||
}
|
||||
|
||||
glXMakeCurrent(display, 0, 0);
|
||||
glXDestroyContext(display, context);
|
||||
|
||||
XDestroyWindow(display, window);
|
||||
XFreeColormap(display, colormap);
|
||||
XCloseDisplay(display);
|
||||
|
||||
gladLoaderUnloadGLX();
|
||||
}
|
||||
117
third-party/glad/example/c/glx_modern.c
vendored
Normal file
117
third-party/glad/example/c/glx_modern.c
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
// gcc example/c/glx.c -o build/glx -Ibuild/include build/src/*.c -ldl -lX11
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
#include <glad/gl.h>
|
||||
#include <glad/glx.h>
|
||||
|
||||
|
||||
const int window_width = 800, window_height = 480;
|
||||
|
||||
|
||||
int main(void) {
|
||||
Display *display = XOpenDisplay(NULL);
|
||||
if (display == NULL) {
|
||||
printf("cannot connect to X server\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int screen = DefaultScreen(display);
|
||||
Window root = RootWindow(display, screen);
|
||||
Visual *visual = DefaultVisual(display, screen);
|
||||
|
||||
Colormap colormap = XCreateColormap(display, root, visual, AllocNone);
|
||||
|
||||
XSetWindowAttributes attributes;
|
||||
attributes.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask;
|
||||
attributes.colormap = colormap;
|
||||
|
||||
Window window =
|
||||
XCreateWindow(display, root, 0, 0, window_width, window_height, 0,
|
||||
DefaultDepth(display, screen), InputOutput, visual,
|
||||
CWColormap | CWEventMask, &attributes);
|
||||
|
||||
XMapWindow(display, window);
|
||||
XStoreName(display, window, "[glad] Modern GLX with X11");
|
||||
|
||||
if (!window) {
|
||||
printf("Unable to create window.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int glx_version = gladLoaderLoadGLX(display, screen);
|
||||
if (!glx_version) {
|
||||
printf("Unable to load GLX.\n");
|
||||
return 1;
|
||||
}
|
||||
printf("Loaded GLX %d.%d\n", GLAD_VERSION_MAJOR(glx_version), GLAD_VERSION_MINOR(glx_version));
|
||||
|
||||
GLint visual_attributes[] = {
|
||||
GLX_RENDER_TYPE, GLX_RGBA_BIT,
|
||||
GLX_DOUBLEBUFFER, 1,
|
||||
None
|
||||
};
|
||||
|
||||
int num_fbc = 0;
|
||||
GLXFBConfig *fbc = glXChooseFBConfig(display, screen, visual_attributes, &num_fbc);
|
||||
|
||||
GLint context_attributes[] = {
|
||||
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
|
||||
GLX_CONTEXT_MINOR_VERSION_ARB, 3,
|
||||
GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
|
||||
None
|
||||
};
|
||||
|
||||
GLXContext context =
|
||||
glXCreateContextAttribsARB(display, fbc[0], NULL, 1, context_attributes);
|
||||
if (!context) {
|
||||
printf("Unable to create OpenGL context.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
glXMakeCurrent(display, window, context);
|
||||
|
||||
int gl_version = gladLoaderLoadGL();
|
||||
if (!gl_version) {
|
||||
printf("Unable to load GL.\n");
|
||||
return 1;
|
||||
}
|
||||
printf("Loaded GL %d.%d\n", GLAD_VERSION_MAJOR(gl_version), GLAD_VERSION_MINOR(gl_version));
|
||||
|
||||
XWindowAttributes gwa;
|
||||
XGetWindowAttributes(display, window, &gwa);
|
||||
glViewport(0, 0, gwa.width, gwa.height);
|
||||
|
||||
bool quit = false;
|
||||
while (!quit) {
|
||||
while (XPending(display)) {
|
||||
XEvent xev;
|
||||
XNextEvent(display, &xev);
|
||||
|
||||
if (xev.type == KeyPress) {
|
||||
quit = true;
|
||||
}
|
||||
}
|
||||
|
||||
glClearColor(0.8, 0.6, 0.7, 1.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glXSwapBuffers(display, window);
|
||||
|
||||
usleep(1000 * 10);
|
||||
}
|
||||
|
||||
glXMakeCurrent(display, 0, 0);
|
||||
glXDestroyContext(display, context);
|
||||
|
||||
XDestroyWindow(display, window);
|
||||
XFreeColormap(display, colormap);
|
||||
XCloseDisplay(display);
|
||||
|
||||
gladLoaderUnloadGLX();
|
||||
}
|
||||
17
third-party/glad/example/c/vulkan_tri_glfw/CMakeLists.txt
vendored
Normal file
17
third-party/glad/example/c/vulkan_tri_glfw/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
project(glad_examples_c_vulkan_tri_glfw C)
|
||||
|
||||
set(GLAD_SOURCES_DIR "${PROJECT_SOURCE_DIR}/../../..")
|
||||
add_subdirectory("${GLAD_SOURCES_DIR}/cmake" glad_cmake)
|
||||
|
||||
find_package(glfw3 REQUIRED)
|
||||
|
||||
glad_add_library(glad_vulkan_12 REPRODUCIBLE LOADER API vulkan=1.2)
|
||||
add_executable(vulkan_tri_glfw
|
||||
vulkan_tri_glfw.c
|
||||
)
|
||||
target_link_libraries(vulkan_tri_glfw
|
||||
PUBLIC
|
||||
glad_vulkan_12
|
||||
glfw
|
||||
)
|
||||
2244
third-party/glad/example/c/vulkan_tri_glfw/vulkan_tri_glfw.c
vendored
Normal file
2244
third-party/glad/example/c/vulkan_tri_glfw/vulkan_tri_glfw.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
172
third-party/glad/example/c/wgl.c
vendored
Normal file
172
third-party/glad/example/c/wgl.c
vendored
Normal file
@@ -0,0 +1,172 @@
|
||||
/**
|
||||
* Thanks to Xeek for the code!
|
||||
*
|
||||
* Building and running under Linux:
|
||||
* i686-w64-mingw32-gcc example/c/wgl.c build/src/wgl.c build/src/gl.c -Ibuild/include -lgdi32 -lopengl32
|
||||
* wine a.exe
|
||||
*/
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <tchar.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <glad/wgl.h>
|
||||
#include <glad/gl.h>
|
||||
|
||||
|
||||
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
|
||||
static const TCHAR window_classname[] = _T("SampleWndClass");
|
||||
static const TCHAR window_title[] = _T("[glad] WGL");
|
||||
static const POINT window_location = { CW_USEDEFAULT, 0 };
|
||||
static const SIZE window_size = { 1024, 768 };
|
||||
static const GLfloat clear_color[] = { 0.0f, 0.0f, 1.0f, 1.0f };
|
||||
|
||||
|
||||
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
|
||||
UNREFERENCED_PARAMETER(hPrevInstance);
|
||||
UNREFERENCED_PARAMETER(lpCmdLine);
|
||||
|
||||
WNDCLASSEX wcex = { };
|
||||
wcex.cbSize = sizeof(WNDCLASSEX);
|
||||
wcex.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wcex.lpfnWndProc = WndProc;
|
||||
wcex.hInstance = hInstance;
|
||||
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
wcex.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
|
||||
wcex.lpszClassName = window_classname;
|
||||
|
||||
ATOM wndclass = RegisterClassEx(&wcex);
|
||||
|
||||
HWND hWnd = CreateWindow(MAKEINTATOM(wndclass), window_title,
|
||||
WS_OVERLAPPEDWINDOW,
|
||||
window_location.x, window_location.y,
|
||||
window_size.cx, window_size.cy,
|
||||
NULL, NULL, hInstance, NULL);
|
||||
|
||||
if (!hWnd) {
|
||||
MessageBox(NULL, _T("Failed to create window!"), window_title, MB_ICONERROR);
|
||||
return -1;
|
||||
}
|
||||
// Configure & Initialize OpenGL:
|
||||
|
||||
// Get a device context so I can set the pixel format later:
|
||||
HDC hdc = GetDC(hWnd);
|
||||
if (hdc == NULL) {
|
||||
DestroyWindow(hWnd);
|
||||
MessageBox(NULL, _T("Failed to get Window's device context!"), window_title, MB_ICONERROR);
|
||||
return -1;
|
||||
}
|
||||
// Set the pixel format for the device context:
|
||||
PIXELFORMATDESCRIPTOR pfd = { };
|
||||
pfd.nSize = sizeof(pfd);
|
||||
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); // Set the size of the PFD to the size of the class
|
||||
pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW; // Enable double buffering, opengl support and drawing to a window
|
||||
pfd.iPixelType = PFD_TYPE_RGBA; // Set our application to use RGBA pixels
|
||||
pfd.cColorBits = 32; // Give us 32 bits of color information (the higher, the more colors)
|
||||
pfd.cDepthBits = 32; // Give us 32 bits of depth information (the higher, the more depth levels)
|
||||
pfd.iLayerType = PFD_MAIN_PLANE; // Set the layer of the PFD
|
||||
int format = ChoosePixelFormat(hdc, &pfd);
|
||||
if (format == 0 || SetPixelFormat(hdc, format, &pfd) == FALSE) {
|
||||
ReleaseDC(hWnd, hdc);
|
||||
DestroyWindow(hWnd);
|
||||
MessageBox(NULL, _T("Failed to set a compatible pixel format!"), window_title, MB_ICONERROR);
|
||||
return -1;
|
||||
}
|
||||
// Create and enable a temporary (helper) opengl context:
|
||||
HGLRC temp_context = NULL;
|
||||
if (NULL == (temp_context = wglCreateContext(hdc))) {
|
||||
ReleaseDC(hWnd, hdc);
|
||||
DestroyWindow(hWnd);
|
||||
MessageBox(NULL, _T("Failed to create the initial rendering context!"), window_title, MB_ICONERROR);
|
||||
return -1;
|
||||
}
|
||||
wglMakeCurrent(hdc, temp_context);
|
||||
|
||||
// Load WGL Extensions:
|
||||
gladLoaderLoadWGL(hdc);
|
||||
|
||||
// Set the desired OpenGL version:
|
||||
int attributes[] = {
|
||||
WGL_CONTEXT_MAJOR_VERSION_ARB, 3, // Set the MAJOR version of OpenGL to 3
|
||||
WGL_CONTEXT_MINOR_VERSION_ARB, 2, // Set the MINOR version of OpenGL to 2
|
||||
WGL_CONTEXT_FLAGS_ARB,
|
||||
WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, // Set our OpenGL context to be forward compatible
|
||||
0
|
||||
};
|
||||
|
||||
// Create the final opengl context and get rid of the temporary one:
|
||||
HGLRC opengl_context = NULL;
|
||||
if (NULL == (opengl_context = wglCreateContextAttribsARB(hdc, NULL, attributes))) {
|
||||
wglDeleteContext(temp_context);
|
||||
ReleaseDC(hWnd, hdc);
|
||||
DestroyWindow(hWnd);
|
||||
MessageBox(NULL, _T("Failed to create the final rendering context!"), window_title, MB_ICONERROR);
|
||||
return -1;
|
||||
}
|
||||
wglMakeCurrent(NULL, NULL); // Remove the temporary context from being active
|
||||
wglDeleteContext(temp_context); // Delete the temporary OpenGL context
|
||||
wglMakeCurrent(hdc, opengl_context); // Make our OpenGL 3.2 context current
|
||||
|
||||
// Glad Loader!
|
||||
if (!gladLoaderLoadGL()) {
|
||||
wglMakeCurrent(NULL, NULL);
|
||||
wglDeleteContext(opengl_context);
|
||||
ReleaseDC(hWnd, hdc);
|
||||
DestroyWindow(hWnd);
|
||||
MessageBox(NULL, _T("Glad Loader failed!"), window_title, MB_ICONERROR);
|
||||
return -1;
|
||||
}
|
||||
// Show & Update the main window:
|
||||
ShowWindow(hWnd, nCmdShow);
|
||||
UpdateWindow(hWnd);
|
||||
|
||||
// A typical native Windows game loop:
|
||||
bool should_quit = false;
|
||||
MSG msg = { };
|
||||
while (!should_quit) {
|
||||
// Generally you'll want to empty out the message queue before each rendering
|
||||
// frame or messages will build up in the queue possibly causing input
|
||||
// delay. Multiple messages and input events occur before each frame.
|
||||
while (PeekMessage(&msg, hWnd, 0, 0, PM_REMOVE)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
|
||||
if (msg.message == WM_QUIT || (msg.message == WM_KEYDOWN && msg.wParam == VK_ESCAPE))
|
||||
should_quit = true;
|
||||
}
|
||||
|
||||
glClearColor(clear_color[0], clear_color[1], clear_color[2], clear_color[3]);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
SwapBuffers(hdc);
|
||||
}
|
||||
|
||||
// Clean-up:
|
||||
if (opengl_context)
|
||||
wglDeleteContext(opengl_context);
|
||||
if (hdc)
|
||||
ReleaseDC(hWnd, hdc);
|
||||
if (hWnd)
|
||||
DestroyWindow(hWnd);
|
||||
|
||||
return (int) msg.wParam;
|
||||
}
|
||||
|
||||
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
||||
switch (uMsg) {
|
||||
case WM_QUIT:
|
||||
case WM_CLOSE:
|
||||
DestroyWindow(hWnd);
|
||||
break;
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
default:
|
||||
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user