Initial commit - some engine bugs stopping compiling
This commit is contained in:
89
third-party/glad/example/c++/hellowindow2.cpp
vendored
Normal file
89
third-party/glad/example/c++/hellowindow2.cpp
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
#include <iostream>
|
||||
|
||||
// GLAD
|
||||
#include <glad/gl.h>
|
||||
|
||||
// GLFW (include after glad)
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
|
||||
// This example is taken from http://learnopengl.com/
|
||||
// http://learnopengl.com/code_viewer.php?code=getting-started/hellowindow2
|
||||
// The code originally used GLEW, I replaced it with Glad
|
||||
|
||||
// Compile:
|
||||
// g++ example/c++/hellowindow2.cpp -Ibuild/include build/src/gl.c -lglfw -ldl
|
||||
|
||||
|
||||
// Function prototypes
|
||||
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode);
|
||||
|
||||
// Window dimensions
|
||||
const GLuint WIDTH = 800, HEIGHT = 600;
|
||||
|
||||
|
||||
// The MAIN function, from here we start the application and run the game loop
|
||||
int main()
|
||||
{
|
||||
std::cout << "Starting GLFW context, OpenGL 3.3" << std::endl;
|
||||
// Init GLFW
|
||||
glfwInit();
|
||||
// Set all the required options for GLFW
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
|
||||
|
||||
// Create a GLFWwindow object that we can use for GLFW's functions
|
||||
GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||
glfwMakeContextCurrent(window);
|
||||
if (window == NULL)
|
||||
{
|
||||
std::cout << "Failed to create GLFW window" << std::endl;
|
||||
glfwTerminate();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Set the required callback functions
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
|
||||
// Load OpenGL functions, gladLoadGL returns the loaded version, 0 on error.
|
||||
int version = gladLoadGL(glfwGetProcAddress);
|
||||
if (version == 0)
|
||||
{
|
||||
std::cout << "Failed to initialize OpenGL context" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Successfully loaded OpenGL
|
||||
std::cout << "Loaded OpenGL " << GLAD_VERSION_MAJOR(version) << "." << GLAD_VERSION_MINOR(version) << std::endl;
|
||||
|
||||
// Define the viewport dimensions
|
||||
glViewport(0, 0, WIDTH, HEIGHT);
|
||||
|
||||
// Game loop
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
// Check if any events have been activated (key pressed, mouse moved etc.) and call corresponding response functions
|
||||
glfwPollEvents();
|
||||
|
||||
// Render
|
||||
// Clear the colorbuffer
|
||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
// Swap the screen buffers
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
|
||||
// Terminates GLFW, clearing any resources allocated by GLFW.
|
||||
glfwTerminate();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Is called whenever a key is pressed/released via GLFW
|
||||
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);
|
||||
}
|
||||
130
third-party/glad/example/c++/hellowindow2_macro.cpp
vendored
Normal file
130
third-party/glad/example/c++/hellowindow2_macro.cpp
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
#include <iostream>
|
||||
|
||||
// GLAD
|
||||
#define GLAD_GL_IMPLEMENTATION
|
||||
#include <glad/gl.h>
|
||||
|
||||
// GLFW
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
|
||||
// This example is taken from http://learnopengl.com/
|
||||
// http://learnopengl.com/code_viewer.php?code=getting-started/hellowindow2
|
||||
// The code originally used GLEW, I replaced it with Glad
|
||||
|
||||
// Compile:
|
||||
// g++ example/c++/hellowindow2.cpp -Ibuild/include build/src/glad.c -lglfw -ldl
|
||||
|
||||
|
||||
// Function prototypes
|
||||
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode);
|
||||
|
||||
// Window dimensions
|
||||
const GLuint WIDTH = 800, HEIGHT = 600;
|
||||
|
||||
|
||||
#ifdef GLAD_OPTION_GL_DEBUG
|
||||
// Define a custom callback for demonstration purposes
|
||||
void pre_gl_call(const char *name, void *funcptr, int len_args, ...) {
|
||||
#ifdef GLAD_OPTION_GL_MX
|
||||
printf("Current GL Context: %p -> ", gladGetGLContext());
|
||||
#endif
|
||||
printf("Calling: %s at %p (%d arguments)\n", name, funcptr, len_args);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// The MAIN function, from here we start the application and run the game loop
|
||||
int main()
|
||||
{
|
||||
std::cout << "Starting GLFW context, OpenGL 3.3" << std::endl;
|
||||
// Init GLFW
|
||||
glfwInit();
|
||||
// Set all the required options for GLFW
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
|
||||
|
||||
// Create a GLFWwindow object that we can use for GLFW's functions
|
||||
GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||
glfwMakeContextCurrent(window);
|
||||
if (window == NULL)
|
||||
{
|
||||
std::cout << "Failed to create GLFW window" << std::endl;
|
||||
glfwTerminate();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Set the required callback functions
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
|
||||
#ifdef GLAD_OPTION_GL_LOADER
|
||||
printf("Using internal loader.\n");
|
||||
#endif
|
||||
|
||||
#ifdef GLAD_OPTION_GL_MX
|
||||
GladGLContext context = {};
|
||||
#ifdef GLAD_OPTION_GL_LOADER
|
||||
int version = gladLoaderLoadGLContext(&context);
|
||||
#else
|
||||
int version = gladLoadGLContext(&context, glfwGetProcAddress);
|
||||
#endif
|
||||
#else
|
||||
#ifdef GLAD_OPTION_GL_LOADER
|
||||
int version = gladLoaderLoadGL();
|
||||
#else
|
||||
int version = gladLoadGL(glfwGetProcAddress);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (version == 0)
|
||||
{
|
||||
std::cout << "Failed to initialize OpenGL context" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::cout << "Loaded OpenGL " << GLAD_VERSION_MAJOR(version) << "." << GLAD_VERSION_MINOR(version) << std::endl;
|
||||
|
||||
#ifdef GLAD_OPTION_GL_DEBUG
|
||||
// before every opengl call call pre_gl_call
|
||||
glad_set_gl_pre_callback(pre_gl_call);
|
||||
// don't use the callbacks for glClear and glClearColor
|
||||
#ifdef GLAD_OPTION_GL_MX_GLOBAL
|
||||
glad_debug_glClear = gladGetGLContext()->Clear;
|
||||
glad_debug_glClearColor = gladGetGLContext()->ClearColor;
|
||||
#else
|
||||
glad_debug_glClear = glad_glClear;
|
||||
glad_debug_glClearColor = glad_glClearColor;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Define the viewport dimensions
|
||||
glViewport(0, 0, WIDTH, HEIGHT);
|
||||
|
||||
// Game loop
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
// Check if any events have been activated (key pressed, mouse moved etc.) and call corresponding response functions
|
||||
glfwPollEvents();
|
||||
|
||||
// Render
|
||||
// Clear the colorbuffer
|
||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
// Swap the screen buffers
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
|
||||
// Terminates GLFW, clearing any resources allocated by GLFW.
|
||||
glfwTerminate();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Is called whenever a key is pressed/released via GLFW
|
||||
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);
|
||||
}
|
||||
92
third-party/glad/example/c++/hellowindow2_mx.cpp
vendored
Normal file
92
third-party/glad/example/c++/hellowindow2_mx.cpp
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
#include <iostream>
|
||||
|
||||
// GLAD
|
||||
#include <glad/gl.h>
|
||||
|
||||
// GLFW
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
|
||||
// This example is taken from http://learnopengl.com/
|
||||
// http://learnopengl.com/code_viewer.php?code=getting-started/hellowindow2
|
||||
// The code originally used GLEW, I replaced it with Glad
|
||||
|
||||
// Compile:
|
||||
// g++ example/c++/hellowindow2.cpp -Ibuild/include build/src/glad.c -lglfw -ldl
|
||||
|
||||
|
||||
// Function prototypes
|
||||
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode);
|
||||
void draw(GLFWwindow *window, GladGLContext *context);
|
||||
|
||||
// Window dimensions
|
||||
const GLuint WIDTH = 800, HEIGHT = 600;
|
||||
|
||||
|
||||
// The MAIN function, from here we start the application and run the game loop
|
||||
int main()
|
||||
{
|
||||
std::cout << "Starting GLFW context, OpenGL 3.3" << std::endl;
|
||||
// Init GLFW
|
||||
glfwInit();
|
||||
// Set all the required options for GLFW
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
|
||||
|
||||
// Create a GLFWwindow object that we can use for GLFW's functions
|
||||
GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||
glfwMakeContextCurrent(window);
|
||||
if (window == NULL)
|
||||
{
|
||||
std::cout << "Failed to create GLFW window" << std::endl;
|
||||
glfwTerminate();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Set the required callback functions
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
|
||||
GladGLContext context = {};
|
||||
int version = gladLoadGLContext(&context, glfwGetProcAddress);
|
||||
if (version == 0)
|
||||
{
|
||||
std::cout << "Failed to initialize OpenGL context" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
draw(window, &context);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void draw(GLFWwindow *window, GladGLContext *gl) {
|
||||
// Define the viewport dimensions
|
||||
gl->Viewport(0, 0, WIDTH, HEIGHT);
|
||||
|
||||
// Game loop
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
// Check if any events have been activated (key pressed, mouse moved etc.) and call corresponding response functions
|
||||
glfwPollEvents();
|
||||
|
||||
// Render
|
||||
// Clear the colorbuffer
|
||||
gl->ClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
||||
gl->Clear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
// Swap the screen buffers
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
|
||||
// Terminates GLFW, clearing any resources allocated by GLFW.
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
// Is called whenever a key is pressed/released via GLFW
|
||||
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);
|
||||
}
|
||||
18
third-party/glad/example/c++/multiwin_mx/CMakeLists.txt
vendored
Normal file
18
third-party/glad/example/c++/multiwin_mx/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
project(glad_examples_c_multiwin_mx C CXX)
|
||||
|
||||
find_package(glfw3 REQUIRED)
|
||||
|
||||
set(GLAD_SOURCES_DIR "${PROJECT_SOURCE_DIR}/../../..")
|
||||
add_subdirectory("${GLAD_SOURCES_DIR}/cmake" glad_cmake)
|
||||
|
||||
glad_add_library(glad_gl_core_mx_33 REPRODUCIBLE MX API gl:core=3.3)
|
||||
|
||||
add_executable(multiwin_mx
|
||||
multiwin_mx.cpp
|
||||
)
|
||||
target_link_libraries(multiwin_mx
|
||||
PUBLIC
|
||||
glad_gl_core_mx_33
|
||||
glfw
|
||||
)
|
||||
109
third-party/glad/example/c++/multiwin_mx/multiwin_mx.cpp
vendored
Normal file
109
third-party/glad/example/c++/multiwin_mx/multiwin_mx.cpp
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
#include <iostream>
|
||||
|
||||
#include <glad/gl.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
|
||||
// Function prototypes
|
||||
GLFWwindow* create_window(const char *name, int major, int minor);
|
||||
GladGLContext* create_context(GLFWwindow *window);
|
||||
void free_context(GladGLContext *context);
|
||||
void draw(GLFWwindow *window, GladGLContext *context, float r, float g, float b);
|
||||
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode);
|
||||
|
||||
// Window dimensions
|
||||
const GLuint WIDTH = 400, HEIGHT = 300;
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
glfwInit();
|
||||
|
||||
GLFWwindow *window1 = create_window("Window 1", 3, 3);
|
||||
GLFWwindow *window2 = create_window("Window 2", 3, 2);
|
||||
|
||||
if (!window1 || !window2) {
|
||||
std::cout << "Failed to create GLFW window" << std::endl;
|
||||
glfwTerminate();
|
||||
return -1;
|
||||
}
|
||||
|
||||
glfwSetKeyCallback(window1, key_callback);
|
||||
glfwSetKeyCallback(window2, key_callback);
|
||||
|
||||
GladGLContext *context1 = create_context(window1);
|
||||
GladGLContext *context2 = create_context(window2);
|
||||
|
||||
if (!context1 || !context2) {
|
||||
std::cout << "Failed to initialize GL contexts" << std::endl;
|
||||
free_context(context1);
|
||||
free_context(context2);
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window1);
|
||||
context1->Viewport(0, 0, WIDTH, HEIGHT);
|
||||
|
||||
glfwMakeContextCurrent(window2);
|
||||
context2->Viewport(0, 0, WIDTH, HEIGHT);
|
||||
|
||||
|
||||
while (!glfwWindowShouldClose(window1) && !glfwWindowShouldClose(window2))
|
||||
{
|
||||
glfwPollEvents();
|
||||
|
||||
draw(window1, context1, 0.5, 0.2, 0.6);
|
||||
draw(window2, context2, 0.0, 0.1, 0.8);
|
||||
}
|
||||
|
||||
free_context(context1);
|
||||
free_context(context2);
|
||||
|
||||
glfwTerminate();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLFWwindow* create_window(const char *name, int major, int minor) {
|
||||
std::cout << "Creating Window, OpenGL " << major << "." << minor << ": " << name << std::endl;
|
||||
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, major);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, minor);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
|
||||
|
||||
GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, name, NULL, NULL);
|
||||
return window;
|
||||
}
|
||||
|
||||
GladGLContext* create_context(GLFWwindow *window) {
|
||||
glfwMakeContextCurrent(window);
|
||||
|
||||
GladGLContext* context = (GladGLContext*) calloc(1, sizeof(GladGLContext));
|
||||
if (!context) return NULL;
|
||||
|
||||
int version = gladLoadGLContext(context, glfwGetProcAddress);
|
||||
std::cout << "Loaded OpenGL " << GLAD_VERSION_MAJOR(version) << "." << GLAD_VERSION_MINOR(version) << std::endl;
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
void free_context(GladGLContext *context) {
|
||||
free(context);
|
||||
}
|
||||
|
||||
|
||||
void draw(GLFWwindow *window, GladGLContext *gl, float r, float g, float b) {
|
||||
glfwMakeContextCurrent(window);
|
||||
|
||||
gl->ClearColor(r, g, b, 1.0f);
|
||||
gl->Clear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
|
||||
// Is called whenever a key is pressed/released via GLFW
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user