Created
August 2, 2012 12:25
-
-
Save AlexsJones/3236669 to your computer and use it in GitHub Desktop.
First part
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| <one line to give the program's name and a brief idea of what it does.> | |
| Copyright (C) 2012 <copyright holder> <email> | |
| This program is free software: you can redistribute it and/or modify | |
| it under the terms of the GNU General Public License as published by | |
| the Free Software Foundation, either version 3 of the License, or | |
| (at your option) any later version. | |
| This program is distributed in the hope that it will be useful, | |
| but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| GNU General Public License for more details. | |
| You should have received a copy of the GNU General Public License | |
| along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| */ | |
| #include "jnx_opengl.hpp" | |
| #include <iostream> | |
| using namespace std; | |
| using namespace jnx; | |
| jnx_opengl::jnx_opengl() | |
| { | |
| } | |
| jnx_opengl::~jnx_opengl() | |
| { | |
| } | |
| //The config is generated if it is not provided by the developer | |
| //It's very basic and makes some assumptions.. | |
| jnx_gl_config* jnx_opengl::create_default_config() | |
| { | |
| jnx_gl_config *conf = new jnx_gl_config(); | |
| //populate with useful defaults | |
| conf->name = "PLACEHOLDER"; | |
| conf->attributes[0] = GLX_RGBA; | |
| conf->attributes[1] = GLX_DEPTH_SIZE; | |
| conf->attributes[2] = 24; | |
| conf->attributes[3] = GLX_DOUBLEBUFFER; | |
| conf->attributes[4] = None; | |
| conf->event_mask = ExposureMask | KeyPressMask; | |
| conf->x = 0; | |
| conf->y = 0; | |
| conf->width = 600; | |
| conf->height = 600; | |
| conf->border_width = 0; | |
| conf->_class = InputOutput; | |
| return conf; | |
| } | |
| int jnx_opengl::configure(void* conf_in) | |
| { | |
| if(!conf_in) | |
| { | |
| cout << "Creating default configuration..." << endl; | |
| configuration = create_default_config(); | |
| } | |
| else | |
| { | |
| configuration = reinterpret_cast<jnx_gl_config*>(conf_in); | |
| } | |
| configuration->display = XOpenDisplay(NULL); | |
| if(configuration->display == NULL) | |
| { | |
| cout << "Cannot connect to the X server" << endl; | |
| return 1; | |
| } | |
| cout << "jnx_opengl: Set Display..." << endl; | |
| configuration->window = DefaultRootWindow(configuration->display); | |
| cout << "jnx_opengl: Set root window..." << endl; | |
| configuration->visual_info = set_visual_info(configuration); | |
| cout << "jnx_opengl: Set visual information..." << endl; | |
| configuration->color_map = create_colormap(configuration); | |
| cout << "jnx_opengl: Set colourmap..." << endl; | |
| configuration->set_window_attributes.colormap = configuration->color_map; | |
| cout << "jnx_opengl:Set window attributes..." << endl; | |
| configuration->set_window_attributes.event_mask = configuration->event_mask; | |
| cout << "jnx_opengl: Set event mask..." << endl; | |
| configuration->window = XCreateWindow(configuration->display,configuration->window,configuration->x,configuration->y,configuration->width,configuration->height,configuration->border_width,configuration->visual_info->depth,configuration->_class,configuration->visual_info->visual,CWColormap | CWEventMask, &configuration->set_window_attributes); | |
| cout << "jnx_opengl: Create window..." << endl; | |
| return 0; | |
| } | |
| Colormap jnx_opengl::create_colormap(jnx_gl_config* configuration) | |
| { | |
| return XCreateColormap(configuration->display, configuration->window, configuration->visual_info->visual, AllocNone); | |
| } | |
| XVisualInfo* jnx_opengl::set_visual_info(jnx_gl_config* configuration) | |
| { | |
| return glXChooseVisual(configuration->display,0,configuration->attributes); | |
| } | |
| void jnx_opengl::bind_windows(jnx_gl_config* configuration) | |
| { | |
| XMapWindow(configuration->display,configuration->window); | |
| XStoreName(configuration->display,configuration->window,configuration->name); | |
| configuration->glx_context = glXCreateContext(configuration->display,configuration->visual_info,NULL,GL_TRUE); | |
| glXMakeCurrent(configuration->display,configuration->window,configuration->glx_context); | |
| glEnable(GL_DEPTH_TEST); | |
| } | |
| void jnx_opengl::start() | |
| { | |
| while(1) | |
| { | |
| XNextEvent(configuration->display,&configuration->x_event); | |
| if(configuration->x_event.type == Expose) | |
| { | |
| XGetWindowAttributes(configuration->display,configuration->window,&configuration->window_attributes); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment