|
|
f2b8c4 |
/*
|
|
|
f2b8c4 |
......... 2015 Ivan Mahonin
|
|
|
f2b8c4 |
|
|
|
f2b8c4 |
This program is free software: you can redistribute it and/or modify
|
|
|
f2b8c4 |
it under the terms of the GNU General Public License as published by
|
|
|
f2b8c4 |
the Free Software Foundation, either version 3 of the License, or
|
|
|
f2b8c4 |
(at your option) any later version.
|
|
|
f2b8c4 |
|
|
|
f2b8c4 |
This program is distributed in the hope that it will be useful,
|
|
|
f2b8c4 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
f2b8c4 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
f2b8c4 |
GNU General Public License for more details.
|
|
|
f2b8c4 |
|
|
|
f2b8c4 |
You should have received a copy of the GNU General Public License
|
|
|
f2b8c4 |
along with this program. If not, see <http: licenses="" www.gnu.org="">.</http:>
|
|
|
f2b8c4 |
*/
|
|
|
f2b8c4 |
|
|
|
a80036 |
#include <ctime></ctime>
|
|
|
93cbac |
#include <cassert></cassert>
|
|
|
f2b8c4 |
|
|
|
f2b8c4 |
#include <iostream></iostream>
|
|
|
a80036 |
#include <iomanip></iomanip>
|
|
|
f2b8c4 |
|
|
|
f2b8c4 |
#include <gl gl.h=""></gl>
|
|
|
f2b8c4 |
#include <gl glext.h=""></gl>
|
|
|
f2b8c4 |
#include <gl glx.h=""></gl>
|
|
|
f2b8c4 |
|
|
|
93cbac |
#include "test.h"
|
|
|
7c6b57 |
#include "shaders.h"
|
|
|
93cbac |
|
|
|
f2b8c4 |
|
|
|
f2b8c4 |
#define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
|
|
|
f2b8c4 |
#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
|
|
|
f2b8c4 |
typedef GLXContext (*GLXCREATECONTEXTATTRIBSARBPROC)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
|
|
|
f2b8c4 |
|
|
|
f2b8c4 |
|
|
|
f2b8c4 |
using namespace std;
|
|
|
f2b8c4 |
|
|
|
f2b8c4 |
|
|
|
a80036 |
clock_t get_clock() {
|
|
|
a80036 |
return clock();
|
|
|
a80036 |
}
|
|
|
a80036 |
|
|
|
f2b8c4 |
int main() {
|
|
|
f2b8c4 |
// open display (we will use default display and screen 0)
|
|
|
f2b8c4 |
Display *display = XOpenDisplay(NULL);
|
|
|
f2b8c4 |
assert(display);
|
|
|
f2b8c4 |
|
|
|
f2b8c4 |
// choose config
|
|
|
f2b8c4 |
int config_attribs[] = {
|
|
|
f2b8c4 |
GLX_DOUBLEBUFFER, False,
|
|
|
f2b8c4 |
GLX_RED_SIZE, 8,
|
|
|
f2b8c4 |
GLX_GREEN_SIZE, 8,
|
|
|
f2b8c4 |
GLX_BLUE_SIZE, 8,
|
|
|
f2b8c4 |
GLX_ALPHA_SIZE, 8,
|
|
|
f2b8c4 |
GLX_DEPTH_SIZE, 24,
|
|
|
f2b8c4 |
GLX_STENCIL_SIZE, 8,
|
|
|
f2b8c4 |
GLX_ACCUM_RED_SIZE, 8,
|
|
|
f2b8c4 |
GLX_ACCUM_GREEN_SIZE, 8,
|
|
|
f2b8c4 |
GLX_ACCUM_BLUE_SIZE, 8,
|
|
|
f2b8c4 |
GLX_ACCUM_ALPHA_SIZE, 8,
|
|
|
f2b8c4 |
GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
|
|
|
f2b8c4 |
None };
|
|
|
f2b8c4 |
int nelements = 0;
|
|
|
f2b8c4 |
GLXFBConfig *configs = glXChooseFBConfig(display, 0, config_attribs, &nelements);
|
|
|
f2b8c4 |
assert(configs != NULL && nelements > 0);
|
|
|
f2b8c4 |
GLXFBConfig config = configs[0];
|
|
|
f2b8c4 |
assert(config);
|
|
|
f2b8c4 |
|
|
|
f2b8c4 |
// create pbuffer
|
|
|
f2b8c4 |
int pbuffer_width = 1024;
|
|
|
f2b8c4 |
int pbuffer_height = 1024;
|
|
|
f2b8c4 |
int pbuffer_attribs[] = {
|
|
|
f2b8c4 |
GLX_PBUFFER_WIDTH, pbuffer_width,
|
|
|
f2b8c4 |
GLX_PBUFFER_HEIGHT, pbuffer_height,
|
|
|
f2b8c4 |
None };
|
|
|
f2b8c4 |
GLXPbuffer pbuffer = glXCreatePbuffer(display, config, pbuffer_attribs);
|
|
|
f2b8c4 |
assert(pbuffer);
|
|
|
f2b8c4 |
|
|
|
f2b8c4 |
// create context
|
|
|
f2b8c4 |
int context_attribs[] = {
|
|
|
7c6b57 |
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
|
|
|
7c6b57 |
GLX_CONTEXT_MINOR_VERSION_ARB, 3,
|
|
|
f2b8c4 |
None };
|
|
|
f2b8c4 |
GLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = (GLXCREATECONTEXTATTRIBSARBPROC) glXGetProcAddress((const GLubyte*)"glXCreateContextAttribsARB");
|
|
|
f2b8c4 |
GLXContext context = glXCreateContextAttribsARB(display, config, NULL, True, context_attribs);
|
|
|
f2b8c4 |
assert(context);
|
|
|
f2b8c4 |
|
|
|
f2b8c4 |
// make context current
|
|
|
f2b8c4 |
glXMakeContextCurrent(display, pbuffer, pbuffer, context);
|
|
|
f2b8c4 |
|
|
|
f2b8c4 |
// set view port
|
|
|
f2b8c4 |
glViewport(0, 0, pbuffer_width, pbuffer_height);
|
|
|
f2b8c4 |
|
|
|
7c6b57 |
Shaders::initialize();
|
|
|
7c6b57 |
|
|
|
f2b8c4 |
// do something
|
|
|
7c6b57 |
//Test::test1();
|
|
|
93cbac |
Test::test2();
|
|
|
93cbac |
Test::test3();
|
|
|
f2b8c4 |
|
|
|
7c6b57 |
Shaders::deinitialize();
|
|
|
7c6b57 |
|
|
|
f2b8c4 |
// deinitialization
|
|
|
f2b8c4 |
glXMakeContextCurrent(display, None, None, NULL);
|
|
|
f2b8c4 |
glXDestroyContext(display, context);
|
|
|
f2b8c4 |
glXDestroyPbuffer(display, pbuffer);
|
|
|
f2b8c4 |
XCloseDisplay(display);
|
|
|
f2b8c4 |
|
|
|
f2b8c4 |
cout << "done" << endl;
|
|
|
f2b8c4 |
return 0;
|
|
|
f2b8c4 |
}
|