2#include <cgv_gl/gl/wgl.h>
13struct unix_gl_context :
public gl_context
25 bool init_application();
26 bool ensure_init_application();
28 bool set_pixel_format();
29 bool create(
const std::string& title,
bool show);
31 unix_gl_context(
unsigned int w = -1,
unsigned int h = -1);
39 void render_pass(RenderPass render_pass = RP_MAIN,
40 RenderPassFlags render_pass_flags = RPF_ALL) {}
44 void set_default_render_pass_flags(RenderPassFlags) { }
46 bool in_render_process()
const {
return false; }
48 bool is_created()
const {
return true; }
50 bool is_current()
const {
return true; }
52 bool make_current()
const;
54 void clear_current()
const;
58 unsigned int get_width()
const {
return width; }
60 unsigned int get_height()
const {
return height; }
62 void resize(
unsigned int width,
unsigned int height) { }
64 void set_bg_color(
float r,
float g,
float b,
float a) {}
68 void force_redraw() {}
69 bool is_alpha_buffer_attached()
const {
return true; }
70 void attach_alpha_buffer() {}
71 void detach_alpha_buffer() {}
72 bool is_stencil_buffer_attached()
const {
return false; }
73 void attach_stencil_buffer() {}
74 void detach_stencil_buffer() {}
75 bool is_quad_buffer_supported()
const {
return false; }
76 bool is_quad_buffer_attached()
const {
return false; }
77 void attach_quad_buffer() {}
78 void detach_quad_buffer() {}
79 bool is_accum_buffer_attached()
const {
return false; }
80 void attach_accum_buffer() {}
81 void detach_accum_buffer() {}
82 bool is_multisample_enabled()
const {
return false; }
83 void enable_multisample() {}
84 void disable_multisample() {}
91 float get_current_font_size()
const {
return 12; }
97 std::ostream& output_stream() {
return std::cout; }
100bool unix_gl_context::make_current()
const
104 res = glXMakeCurrent(d_dpy, d_win, d_ctx);
105 XUnlockDisplay(d_dpy);
108 std::cerr <<
"failed to make current" << std::endl;
114void unix_gl_context::clear_current()
const
117 glXMakeCurrent(d_dpy, 0, 0);
118 XUnlockDisplay(d_dpy);
121unix_gl_context::unix_gl_context(
unsigned int w,
unsigned int h)
130unix_gl_context::~unix_gl_context()
133 glXMakeCurrent(d_dpy, d_win, d_ctx);
134 glXDestroyContext(d_dpy, d_ctx);
135 XDestroyWindow(d_dpy, d_win);
136 XUnlockDisplay(d_dpy);
137 XCloseDisplay(d_dpy);
143bool unix_gl_context::create(
const std::string& title,
bool show)
147 const char *display =
":0";
149 if (!(d_dpy = XOpenDisplay(display))) {
150 std::cerr <<
"Couldn't open X11 display" << std::endl;
165 int scrnum = DefaultScreen(d_dpy);
167 Window root = RootWindow(d_dpy, scrnum);
182 XVisualInfo *visinfo = glXChooseVisual(d_dpy, scrnum, attr);
185 std::cerr <<
"Couldn't get a visual" << std::endl;
188 d_ctx = glXCreateContext(d_dpy, visinfo, NULL, True);
192 XSetWindowAttributes winattr;
193 winattr.background_pixel = 0;
194 winattr.border_pixel = 0;
195 winattr.colormap = XCreateColormap(d_dpy, root, visinfo->visual, AllocNone);
196 winattr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
197 unsigned long mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
200 d_win = XCreateWindow(d_dpy, root, 0, 0, width, height, 0,
201 visinfo->depth, InputOutput, visinfo->visual, mask, &winattr);
216 XMapWindow(d_dpy, d_win);
217 glXMakeCurrent(d_dpy, d_win, d_ctx);
218 XUnmapWindow(d_dpy, d_win);
232 glViewport(0, 0, width, height);
236 XUnlockDisplay(d_dpy);
240context* create_unix_gl_context(
RenderAPI api,
unsigned int w,
unsigned int h,
241 const std::string& title,
bool show)
243 if (api != RA_OPENGL)
245 unix_gl_context* ctx_ptr =
new unix_gl_context(w,h);
246 if (!ctx_ptr->create(title, show)) {
257#include "lib_begin.h"
262extern CGV_API context_factory_registration create_unix_gl_context_registration(gl::create_unix_gl_context);
RenderAPI
enumeration of rendering APIs which can be queried from the context
RenderPass
Enumeration of different render passes, which can be queried from the context and used to specify a n...
RenderPassFlags
available flags that can be queried from the context and set for a new render pass
@ RPF_NONE
no frame initialization is performed
namespace that holds tools that dont fit any other namespace