From 718d9ea67196aa7e56c84261e0a8c134492023ad Mon Sep 17 00:00:00 2001 From: epoch Date: Tue, 24 Jan 2017 01:23:45 -0600 Subject: changed a couple things about how graphics stuff is abstracted and separated into different files. --- src/graphics.c | 19 ++++++++----------- src/graphics_backend.h | 24 ++++++++++++++++++++++++ src/graphics_opengl.c | 8 ++++++++ src/graphics_opengl.h | 6 ++++++ src/graphics_x11.c | 19 ++++++++++++++----- src/graphics_x11.h | 15 --------------- 6 files changed, 60 insertions(+), 31 deletions(-) create mode 100644 src/graphics_backend.h create mode 100644 src/graphics_opengl.h (limited to 'src') diff --git a/src/graphics.c b/src/graphics.c index b5f05c2..49da7d4 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -7,7 +7,6 @@ #include #include #include -//#include //code to use select instead of non-blocking is commented out. might decide to use it later. #include #define __USE_GNU //for longer math constants #include @@ -15,8 +14,7 @@ #include "config.h" #include "common.h" -//choose which graphic's end you want here I guess? -#include "graphics_x11.h" +#include "graphics_backend.h" //this header includes all the functions you'll need to implement if you want to port hackvr to something else #include "graphics.h" //typedef float real; //think this conflicts? @@ -452,22 +450,21 @@ void draw_screen() { //now we pick the color of this triangle! if(gra_global.red_and_blue) { if(cn==0) { -// XSetForeground(global.dpy,global.backgc,global.red.pixel);//??? + set_color_red(); } else { -// XSetForeground(global.dpy,global.backgc,global.blue.pixel);//??? + set_color_blue(); } //tests of blending grayscale with red and blue // draw_c3_triangle(*(zs[i].t)); } else { - if(!strcmp(global.selected_object,zs[i].s->id)) { +// if(!strcmp(global.selected_object,zs[i].s->id)) { //XSetForeground(global.dpy,global.backgc,global.green.pixel); - } else { -// set_color_based_on_distance(zs[i].d); - } +// } else { +// } + set_color_based_on_distance(zs[i].d); } -// set_color(); //if(between_angles(points_to_angle((c2_t){zs[i].s->p[0].x,zs[i].s->p[0].z},(c2_t){camera.p.x,camera.p.z}),d2r(camera.yr+45),d2r(camera.yr+135))) { - set_color_based_on_distance(zs[i].d); +// set_color_based_on_distance(zs[i].d); draw_c3_shape(*(zs[i].s)); //} } diff --git a/src/graphics_backend.h b/src/graphics_backend.h new file mode 100644 index 0000000..1f88ec6 --- /dev/null +++ b/src/graphics_backend.h @@ -0,0 +1,24 @@ +#ifndef _HACKVR_GRAPHICS_BACKEND_H_ +#define _HACKVR_GRAPHICS_BACKEND_H_ + +//these are just the functions that all backends need to implement to work with hackvr. +//the list of functions are subject to change. + +void draw_cs_line(cs_t p1,cs_t p2); +void draw_cs_text(cs_t p,char *text); +void draw_cs_shape(cs_s_t s); +void draw_cs_filled_shape(cs_s_t s); +void set_aspect_ratio(); +void set_color_based_on_distance(real d); +void flipscreen(); +void set_color(); +void set_color_red(); +void set_color_blue(); +void clear_backbuffer(); +int keypress_handler(int sym); +int graphics_init(); +int graphics_event_handler(); +void set_clipping_rectangle(int x,int y,int width,int height); +void red_and_blue_magic(); + +#endif diff --git a/src/graphics_opengl.c b/src/graphics_opengl.c index fd079cf..5d2e600 100644 --- a/src/graphics_opengl.c +++ b/src/graphics_opengl.c @@ -66,6 +66,14 @@ void set_color() { glColor3f(0.0, 1.0, 0.0); } +void set_color_red() { + glColor3f(1.0, 0.0, 0.0); +} + +void set_color_blue() { + glColor3f(0.0, 0.0, 1.0); +} + void clear_backbuffer() { glClearColor(0.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); diff --git a/src/graphics_opengl.h b/src/graphics_opengl.h new file mode 100644 index 0000000..a5aa15d --- /dev/null +++ b/src/graphics_opengl.h @@ -0,0 +1,6 @@ +#ifndef _HACKVR_GRAPHICS_OPENGL_H_ +#define _HACKVR_GRAPHICS_OPENGL_H_ + +//this file intentionally left blank + +#endif diff --git a/src/graphics_x11.c b/src/graphics_x11.c index dad8b05..9839169 100644 --- a/src/graphics_x11.c +++ b/src/graphics_x11.c @@ -20,6 +20,7 @@ #include "common.h" #include "graphics.h" #include "graphics_x11.h" +#include "graphics_backend.h" //typedef float real; //think this conflicts? @@ -141,6 +142,14 @@ void set_color() { XSetForeground(x11_global.dpy,x11_global.backgc,x11_global.green.pixel); } +void set_color_red() { + XSetForeground(x11_global.dpy,x11_global.backgc,x11_global.red.pixel); +} + +void set_color_blue() { + XSetForeground(x11_global.dpy,x11_global.backgc,x11_global.blue.pixel); +} + void flipscreen() { XCopyArea(x11_global.dpy,x11_global.backbuffer,x11_global.w,x11_global.gc,0,0,gra_global.width,gra_global.height,0,0); } @@ -384,22 +393,22 @@ int graphics_event_handler() { // if(e.xexpose.count == 0) redraw=1; // break; case MotionNotify: - printf("# MotionNotify\n"); + if(global.debug >= 2) printf("# MotionNotify\n"); XQueryPointer(x11_global.dpy,x11_global.w,&root,&child,&gra_global.rmousex,&gra_global.rmousey,&gra_global.mousex,&gra_global.mousey,&mask); redraw=1; break; case ButtonPress: - printf("# ButtonPress\n"); + if(global.debug >= 2) printf("# ButtonPress\n"); redraw=1; gra_global.buttonpressed=e.xbutton.button;//what's this for? mouse? break; case ButtonRelease: - printf("# ButtonRelease\n"); + if(global.debug >= 2) printf("# ButtonRelease\n"); redraw=1; gra_global.buttonpressed=0;//what's this for??? break; case ConfigureNotify: - printf("# ConfigureNotify\n"); + if(global.debug >= 2) printf("# ConfigureNotify\n"); redraw=1; XGetGeometry(x11_global.dpy,x11_global.w,&root,&global.x,&global.y,&gra_global.width,&gra_global.height,&gra_global.border_width,&gra_global.depth); if(gra_global.height * AR_W / AR_H != gra_global.width / (gra_global.split_screen / (gra_global.red_and_blue ? gra_global.split_screen : 1))) { @@ -416,7 +425,7 @@ int graphics_event_handler() { gra_global.mapyoff=gra_global.height/2; break; case KeyPress: - printf("# KeyPress\n"); + if(global.debug >= 2) printf("# KeyPress\n"); redraw=1; if(keypress_handler(XLookupKeysym(&e.xkey,0)) == -1) { printf("# exiting\n"); diff --git a/src/graphics_x11.h b/src/graphics_x11.h index 2f54de1..e2fdd86 100644 --- a/src/graphics_x11.h +++ b/src/graphics_x11.h @@ -19,19 +19,4 @@ struct x11_global {//stores global variables for the x11 *specific* shit. int root_window; }; -void draw_cs_line(cs_t p1,cs_t p2); -void draw_cs_text(cs_t p,char *text); -void draw_cs_shape(cs_s_t s); -void draw_cs_filled_shape(cs_s_t s); -void set_aspect_ratio(); -void set_color_based_on_distance(real d); -void flipscreen(); -void set_color(); -void clear_backbuffer(); -int keypress_handler(int sym); -int graphics_init(); -int graphics_event_handler(); -void set_clipping_rectangle(int x,int y,int width,int height); -void red_and_blue_magic(); - #endif -- cgit v1.2.3