Redraw screen at 120fps
This commit is contained in:
parent
670354024f
commit
a12da132d3
@ -8,25 +8,65 @@ opengl_service_t::opengl_service_t(
|
|||||||
configuration_m = configuration_p;
|
configuration_m = configuration_p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void_t<opengl_service_t::error_t> opengl_service_t::draw_quad(
|
void_t<opengl_service_t::error_t> opengl_service_t::draw(
|
||||||
|
int cycle_p
|
||||||
) {
|
) {
|
||||||
glClearColor(1.0, 1.0, 1.0, 1.0);
|
glClearColor(1.0, 1.0, 1.0, 1.0);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glOrtho(-1., 1., -1., 1., 1., 20.);
|
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
double rotate_x = static_cast<double>(cycle_p * 1);
|
||||||
glLoadIdentity();
|
double rotate_y = static_cast<double>(cycle_p * 1);
|
||||||
gluLookAt(0., 0., 10., 0., 0., 0., 0., 1., 0.);
|
glRotatef( rotate_x, 1.0, 0.0, 0.0 );
|
||||||
|
glRotatef( rotate_y, 0.0, 1.0, 0.0 );
|
||||||
|
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_POLYGON);
|
||||||
glColor3f(1., 0., 0.); glVertex3f(-.75, -.75, 0.);
|
|
||||||
glColor3f(0., 1., 0.); glVertex3f( .75, -.75, 0.);
|
glColor3f( 1.0, 1.0, 1.0 );
|
||||||
glColor3f(0., 0., 1.); glVertex3f( .75, .75, 0.);
|
glVertex3f( 0.5, -0.5, 0.5 );
|
||||||
glColor3f(1., 1., 0.); glVertex3f(-.75, .75, 0.);
|
glVertex3f( 0.5, 0.5, 0.5 );
|
||||||
|
glVertex3f( -0.5, 0.5, 0.5 );
|
||||||
|
glVertex3f( -0.5, -0.5, 0.5 );
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
|
// Purple side - RIGHT
|
||||||
|
glBegin(GL_POLYGON);
|
||||||
|
glColor3f( 1.0, 0.0, 1.0 );
|
||||||
|
glVertex3f( 0.5, -0.5, -0.5 );
|
||||||
|
glVertex3f( 0.5, 0.5, -0.5 );
|
||||||
|
glVertex3f( 0.5, 0.5, 0.5 );
|
||||||
|
glVertex3f( 0.5, -0.5, 0.5 );
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
// Green side - LEFT
|
||||||
|
glBegin(GL_POLYGON);
|
||||||
|
glColor3f( 0.0, 1.0, 0.0 );
|
||||||
|
glVertex3f( -0.5, -0.5, 0.5 );
|
||||||
|
glVertex3f( -0.5, 0.5, 0.5 );
|
||||||
|
glVertex3f( -0.5, 0.5, -0.5 );
|
||||||
|
glVertex3f( -0.5, -0.5, -0.5 );
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
// Blue side - TOP
|
||||||
|
glBegin(GL_POLYGON);
|
||||||
|
glColor3f( 0.0, 0.0, 1.0 );
|
||||||
|
glVertex3f( 0.5, 0.5, 0.5 );
|
||||||
|
glVertex3f( 0.5, 0.5, -0.5 );
|
||||||
|
glVertex3f( -0.5, 0.5, -0.5 );
|
||||||
|
glVertex3f( -0.5, 0.5, 0.5 );
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
// Red side - BOTTOM
|
||||||
|
glBegin(GL_POLYGON);
|
||||||
|
glColor3f( 1.0, 0.0, 0.0 );
|
||||||
|
glVertex3f( 0.5, -0.5, -0.5 );
|
||||||
|
glVertex3f( 0.5, -0.5, 0.5 );
|
||||||
|
glVertex3f( -0.5, -0.5, 0.5 );
|
||||||
|
glVertex3f( -0.5, -0.5, -0.5 );
|
||||||
|
|
||||||
|
glEnd();
|
||||||
|
glFlush();
|
||||||
|
|
||||||
void_t<opengl_service_t::error_t> void_l;
|
void_t<opengl_service_t::error_t> void_l;
|
||||||
void_l.error_m = opengl_service_t::error_t::none;
|
void_l.error_m = opengl_service_t::error_t::none;
|
||||||
return void_l;
|
return void_l;
|
||||||
@ -35,13 +75,14 @@ void_t<opengl_service_t::error_t> opengl_service_t::draw_quad(
|
|||||||
void_t<opengl_service_t::error_t> opengl_service_t::enable_depth_test(
|
void_t<opengl_service_t::error_t> opengl_service_t::enable_depth_test(
|
||||||
) {
|
) {
|
||||||
glEnable(
|
glEnable(
|
||||||
GL_DEPTH_TEST
|
GL_DEPTH_TEST
|
||||||
);
|
);
|
||||||
void_t<opengl_service_t::error_t> void_l;
|
void_t<opengl_service_t::error_t> void_l;
|
||||||
void_l.error_m = opengl_service_t::error_t::none;
|
void_l.error_m = opengl_service_t::error_t::none;
|
||||||
return void_l;
|
return void_l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void_t<opengl_service_t::error_t> opengl_service_t::resize_viewport(
|
void_t<opengl_service_t::error_t> opengl_service_t::resize_viewport(
|
||||||
int x,
|
int x,
|
||||||
int y,
|
int y,
|
||||||
|
@ -20,7 +20,8 @@ class opengl_service_t {
|
|||||||
};
|
};
|
||||||
struct configuration_t {
|
struct configuration_t {
|
||||||
};
|
};
|
||||||
void_t<error_t> draw_quad(
|
void_t<error_t> draw(
|
||||||
|
int cycle_p
|
||||||
);
|
);
|
||||||
void_t<error_t> enable_depth_test(
|
void_t<error_t> enable_depth_test(
|
||||||
);
|
);
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "target/linux/draw/opengl_x11_service.h"
|
#include "target/linux/draw/opengl_x11_service.h"
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/X.h>
|
#include <X11/X.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -67,6 +68,11 @@ void_t<window_service_t::error_t> window_service_t::create_window(
|
|||||||
CWColormap | CWEventMask,
|
CWColormap | CWEventMask,
|
||||||
&set_window_attributes_l
|
&set_window_attributes_l
|
||||||
);
|
);
|
||||||
|
XSelectInput(
|
||||||
|
display_l,
|
||||||
|
window_l,
|
||||||
|
ExposureMask | KeyPressMask
|
||||||
|
);
|
||||||
XMapWindow(
|
XMapWindow(
|
||||||
display_l,
|
display_l,
|
||||||
window_l
|
window_l
|
||||||
@ -93,44 +99,77 @@ void_t<window_service_t::error_t> window_service_t::create_window(
|
|||||||
opengl_service_l->enable_depth_test(
|
opengl_service_l->enable_depth_test(
|
||||||
);
|
);
|
||||||
|
|
||||||
XEvent event_l;
|
int display_fd_l = ConnectionNumber(display_l);
|
||||||
|
fd_set in_fds;
|
||||||
|
|
||||||
|
int cycle_l = 0;
|
||||||
XWindowAttributes window_attributes_l;
|
XWindowAttributes window_attributes_l;
|
||||||
while(true) {
|
XEvent event_l;
|
||||||
XNextEvent(
|
while (true) {
|
||||||
display_l,
|
FD_ZERO(&in_fds);
|
||||||
&event_l
|
FD_SET(display_fd_l, &in_fds);
|
||||||
|
|
||||||
|
// Set our timer.
|
||||||
|
timeval timeval_l;
|
||||||
|
timeval_l.tv_usec = 8333;
|
||||||
|
timeval_l.tv_sec = 0;
|
||||||
|
|
||||||
|
// Wait for X Event or a Timer
|
||||||
|
int select_l = select(
|
||||||
|
display_fd_l + 1,
|
||||||
|
&in_fds,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
&timeval_l
|
||||||
);
|
);
|
||||||
if (event_l.type == Expose) {
|
if (select_l >= 0) {
|
||||||
XGetWindowAttributes(
|
// event received
|
||||||
display_l,
|
switch (event_l.type) {
|
||||||
window_l,
|
case KeyPress:
|
||||||
&window_attributes_l
|
opengl_x11_service_l->dispose(
|
||||||
);
|
display_l
|
||||||
opengl_service_l->resize_viewport(
|
);
|
||||||
0,
|
XDestroyWindow(
|
||||||
0,
|
display_l,
|
||||||
window_attributes_l.width,
|
window_l
|
||||||
window_attributes_l.height
|
);
|
||||||
);
|
XCloseDisplay(
|
||||||
opengl_service_l->draw_quad(
|
display_l
|
||||||
);
|
);
|
||||||
opengl_x11_service_l->swap_buffers(
|
break;
|
||||||
display_l,
|
case Expose:
|
||||||
window_l
|
XGetWindowAttributes(
|
||||||
);
|
display_l,
|
||||||
} else if (event_l.type == KeyPress) {
|
window_l,
|
||||||
opengl_x11_service_l->dispose(
|
&window_attributes_l
|
||||||
display_l
|
);
|
||||||
);
|
opengl_service_l->resize_viewport(
|
||||||
XDestroyWindow(
|
0,
|
||||||
display_l,
|
0,
|
||||||
window_l
|
window_attributes_l.width,
|
||||||
);
|
window_attributes_l.height
|
||||||
XCloseDisplay(
|
);
|
||||||
display_l
|
opengl_service_l->draw(
|
||||||
);
|
cycle_l
|
||||||
break;
|
);
|
||||||
|
opengl_x11_service_l->swap_buffers(
|
||||||
|
display_l,
|
||||||
|
window_l
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// timeout
|
||||||
}
|
}
|
||||||
|
while (XPending(display_l)) {
|
||||||
|
XNextEvent(
|
||||||
|
display_l,
|
||||||
|
&event_l
|
||||||
|
);
|
||||||
|
}
|
||||||
|
cycle_l += 1;
|
||||||
}
|
}
|
||||||
void_l.error_m = window_service_t::error_t::none;
|
void_l.error_m = window_service_t::error_t::none;
|
||||||
return void_l;
|
return void_l;
|
||||||
|
Loading…
Reference in New Issue
Block a user