added glad generator and a glad runtime
This commit is contained in:
parent
2017f6195e
commit
ac18a84a9c
62 changed files with 32373 additions and 10 deletions
98
tools/glad-0.1.14a0/example/c++/hellowindow2.cpp
Normal file
98
tools/glad-0.1.14a0/example/c++/hellowindow2.cpp
Normal file
|
@ -0,0 +1,98 @@
|
|||
#include <iostream>
|
||||
|
||||
|
||||
// THIS IS OPTIONAL AND NOT REQUIRED, ONLY USE THIS IF YOU DON'T WANT GLAD TO INCLUDE windows.h
|
||||
// GLAD will include windows.h for APIENTRY if it was not previously defined.
|
||||
// Make sure you have the correct definition for APIENTRY for platforms which define _WIN32 but don't use __stdcall
|
||||
#ifdef _WIN32
|
||||
#define APIENTRY __stdcall
|
||||
#endif
|
||||
|
||||
// GLAD
|
||||
#include <glad/glad.h>
|
||||
#include <glad/glad_glx.h>
|
||||
|
||||
// confirm that GLAD didn't include windows.h
|
||||
#ifdef _WINDOWS_
|
||||
#error windows.h was included!
|
||||
#endif
|
||||
|
||||
// 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;
|
||||
|
||||
// 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);
|
||||
|
||||
if (!gladLoadGLLoader((GLADloadproc) glfwGetProcAddress))
|
||||
{
|
||||
std::cout << "Failed to initialize OpenGL context" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
std::cout << key << std::endl;
|
||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
}
|
87
tools/glad-0.1.14a0/example/c/simple.c
Normal file
87
tools/glad-0.1.14a0/example/c/simple.c
Normal file
|
@ -0,0 +1,87 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <glad/glad.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);
|
||||
}
|
||||
|
||||
|
||||
#ifdef GLAD_DEBUG
|
||||
void pre_gl_call(const char *name, void *funcptr, int len_args, ...) {
|
||||
printf("Calling: %s (%d arguments)\n", name, len_args);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if(gladLoadGL()) {
|
||||
// you need an OpenGL context before loading glad
|
||||
printf("I did load GL with no context!\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
glutInit(&argc, argv);
|
||||
glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
|
||||
glutInitWindowSize(width, height);
|
||||
glutCreateWindow("cookie");
|
||||
|
||||
glutReshapeFunc(reshape);
|
||||
glutDisplayFunc(display);
|
||||
|
||||
if(!gladLoadGL()) {
|
||||
printf("Something went wrong!\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
#ifdef GLAD_DEBUG
|
||||
// before every opengl call call pre_gl_call
|
||||
glad_set_pre_callback(pre_gl_call);
|
||||
// don't use the callback for glClear
|
||||
// (glClear could be replaced with your own function)
|
||||
glad_debug_glClear = glad_glClear;
|
||||
#endif
|
||||
|
||||
// gladLoadGLLoader(&glutGetProcAddress);
|
||||
printf("OpenGL %d.%d\n", GLVersion.major, GLVersion.minor);
|
||||
if (GLVersion.major < 2) {
|
||||
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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue