File: main.cpp

package info (click to toggle)
glbinding 3.3.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,972 kB
  • sloc: cpp: 224,461; javascript: 1,615; sh: 114; makefile: 98
file content (136 lines) | stat: -rw-r--r-- 3,408 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136

#include <iostream>

#include <GLFW/glfw3.h>

#include <glbinding/glbinding.h>
#include <glbinding/Version.h>
#include <glbinding/FunctionCall.h>
#include <glbinding/CallbackMask.h>

#include <glbinding/gl/gl.h>
#include <glbinding/getProcAddress.h>

#include <glbinding-aux/ContextInfo.h>
#include <glbinding-aux/Meta.h>
#include <glbinding-aux/types_to_string.h>
#include <glbinding-aux/ValidVersions.h>
#include <glbinding-aux/debug.h>


using namespace gl;
using namespace glbinding;


void error(int errnum, const char * errmsg)
{
    std::cerr << errnum << ": " << errmsg << std::endl;
}


void key_callback(GLFWwindow * window, int key, int /*scancode*/, int action, int /*mods*/)
{
    if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
    {
        glfwSetWindowShouldClose(window, 1);
    }
}


int main(int, char *[])
{
    glfwSetErrorCallback(error);

    if (!glfwInit())
        return 1;

    glfwDefaultWindowHints();

#ifdef SYSTEM_DARWIN
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, true);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#endif

    // Initialize window 1

    GLFWwindow * window1 = glfwCreateWindow(640, 480, "", nullptr, nullptr);
    if (!window1)
    {
        glfwTerminate();
        return -1;
    }

    glfwSetKeyCallback(window1, key_callback);

    glfwMakeContextCurrent(window1);

    glbinding::initialize(0, glfwGetProcAddress, false); // only resolve functions that are actually used (lazy)
    glbinding::aux::enableGetErrorCallback();

    // Initialize window 2

    GLFWwindow * window2 = glfwCreateWindow(640, 480, "", nullptr, nullptr);
    if (!window2)
    {
        glfwTerminate();
        return -1;
    }

    glfwMakeContextCurrent(window2);

    glfwSetKeyCallback(window2, key_callback);

    glbinding::initialize(1, glfwGetProcAddress, false); // only resolve functions that are actually used (lazy)
    glbinding::aux::enableGetErrorCallback();

    // print some gl infos (query)

    std::cout << std::endl
        << "OpenGL Version:  " << aux::ContextInfo::version() << std::endl
        << "OpenGL Vendor:   " << aux::ContextInfo::vendor() << std::endl
        << "OpenGL Renderer: " << aux::ContextInfo::renderer() << std::endl;

    // Rendering Loop

    int width, height;

    int activeWindow = 0;
    while (!glfwWindowShouldClose(window1) && !glfwWindowShouldClose(window2))
    {
        glfwPollEvents();

        if ((activeWindow % 2) == 0)
        {
            glfwGetFramebufferSize(window1, &width, &height);

            glfwMakeContextCurrent(window1);
            glbinding::useContext(0);
            glClearColor(1.0f, 0.0f, activeWindow / 15.0f, 0.0f);
            glViewport(0, 0, width, height);

            glClear(GL_COLOR_BUFFER_BIT);

            glfwSwapBuffers(window1);
        }
        else if ((activeWindow % 2) == 1)
        {
            glfwGetFramebufferSize(window2, &width, &height);

            glfwMakeContextCurrent(window2);
            glbinding::useContext(1);
            glClearColor(0.0f, 1.0f, activeWindow / 15.0f, 0.0f);
            glViewport(0, 0, width, height);

            glClear(GL_COLOR_BUFFER_BIT);

            glfwSwapBuffers(window2);
        }

        activeWindow = (activeWindow + 1) % 16;
    }

    glfwTerminate();
    return 0;
}