Redraw screen at 120fps

This commit is contained in:
James Whiteman 2022-02-01 14:32:50 -08:00
parent 670354024f
commit a12da132d3
3 changed files with 131 additions and 50 deletions

View File

@ -8,25 +8,65 @@ opengl_service_t::opengl_service_t(
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);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glOrtho(-1., 1., -1., 1., 1., 20.);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0., 0., 10., 0., 0., 0., 0., 1., 0.);
double rotate_x = static_cast<double>(cycle_p * 1);
double rotate_y = static_cast<double>(cycle_p * 1);
glRotatef( rotate_x, 1.0, 0.0, 0.0 );
glRotatef( rotate_y, 0.0, 1.0, 0.0 );
glBegin(GL_QUADS);
glColor3f(1., 0., 0.); glVertex3f(-.75, -.75, 0.);
glColor3f(0., 1., 0.); glVertex3f( .75, -.75, 0.);
glColor3f(0., 0., 1.); glVertex3f( .75, .75, 0.);
glColor3f(1., 1., 0.); glVertex3f(-.75, .75, 0.);
glBegin(GL_POLYGON);
glColor3f( 1.0, 1.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();
// 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_l.error_m = opengl_service_t::error_t::none;
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(
) {
glEnable(
GL_DEPTH_TEST
GL_DEPTH_TEST
);
void_t<opengl_service_t::error_t> void_l;
void_l.error_m = opengl_service_t::error_t::none;
return void_l;
}
void_t<opengl_service_t::error_t> opengl_service_t::resize_viewport(
int x,
int y,

View File

@ -20,7 +20,8 @@ class opengl_service_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(
);

View File

@ -4,6 +4,7 @@
#include "target/linux/draw/opengl_x11_service.h"
#include <X11/Xlib.h>
#include <X11/X.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -67,6 +68,11 @@ void_t<window_service_t::error_t> window_service_t::create_window(
CWColormap | CWEventMask,
&set_window_attributes_l
);
XSelectInput(
display_l,
window_l,
ExposureMask | KeyPressMask
);
XMapWindow(
display_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(
);
XEvent event_l;
int display_fd_l = ConnectionNumber(display_l);
fd_set in_fds;
int cycle_l = 0;
XWindowAttributes window_attributes_l;
while(true) {
XNextEvent(
display_l,
&event_l
XEvent event_l;
while (true) {
FD_ZERO(&in_fds);
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) {
XGetWindowAttributes(
display_l,
window_l,
&window_attributes_l
);
opengl_service_l->resize_viewport(
0,
0,
window_attributes_l.width,
window_attributes_l.height
);
opengl_service_l->draw_quad(
);
opengl_x11_service_l->swap_buffers(
display_l,
window_l
);
} else if (event_l.type == KeyPress) {
opengl_x11_service_l->dispose(
display_l
);
XDestroyWindow(
display_l,
window_l
);
XCloseDisplay(
display_l
);
break;
if (select_l >= 0) {
// event received
switch (event_l.type) {
case KeyPress:
opengl_x11_service_l->dispose(
display_l
);
XDestroyWindow(
display_l,
window_l
);
XCloseDisplay(
display_l
);
break;
case Expose:
XGetWindowAttributes(
display_l,
window_l,
&window_attributes_l
);
opengl_service_l->resize_viewport(
0,
0,
window_attributes_l.width,
window_attributes_l.height
);
opengl_service_l->draw(
cycle_l
);
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;
return void_l;