diff options
| author | epoch <epoch@hacking.allowed.org> | 2017-01-07 14:37:12 -0600 | 
|---|---|---|
| committer | epoch <epoch@hacking.allowed.org> | 2017-01-07 14:37:12 -0600 | 
| commit | ebc03fd33fb808db47e47c2426ee6f6879721d4a (patch) | |
| tree | 829a5e2695b54934cbafb2357cc1d7f4a38d0fe2 /src | |
| parent | c40dfd2adba765462e001872cca9b13f8695d22e (diff) | |
| download | hackvr-ebc03fd33fb808db47e47c2426ee6f6879721d4a.tar.gz hackvr-ebc03fd33fb808db47e47c2426ee6f6879721d4a.zip  | |
more crap that still doesn't work right.
Diffstat (limited to 'src')
| -rw-r--r-- | src/graphics_opengl.c | 157 | 
1 files changed, 102 insertions, 55 deletions
diff --git a/src/graphics_opengl.c b/src/graphics_opengl.c index 9e200de..fd079cf 100644 --- a/src/graphics_opengl.c +++ b/src/graphics_opengl.c @@ -1,96 +1,143 @@ -  #include <string.h>  #include <stdlib.h>  #include <stdio.h>  #include <GL/glut.h> +#include <GL/freeglut_ext.h> + +#include "common.h"  GLenum doubleBuffer;  GLubyte ubImage[65536]; +void set_aspect_ratio(int w,int h) { +  glViewport(0,0,w,h); +  glMatrixMode(GL_PROJECTION); +  glLoadIdentity(); +  glOrtho(0,w,0,h,-1,1); +//  glScalef(1,-1,1); +//  glTranslatef(0,-h,0); +} + +void set_color_based_on_distance(real d) { + //scale this color based on distance... closer is lighter. +// float g; +// g=d/100.0 + glColor3f(0.0, 1.0, 0.0); +} + +void set_clipping_rectangle(int x,int y,int w,int h) { + +} +  void draw_cs_line(cs_t p1,cs_t p2) { -  + glBegin(GL_LINES); + glColor3f(0.0, 1.0, 0.0); + glVertex2i(p1.x,p1.y); + glVertex2i(p2.x,p2.y); + glEnd();  }  void draw_cs_text() { +  +} +void draw_cs_shape(cs_s_t s) { +  int i; +  for(i=0;i<s.len+(s.len==1);i++) {//this shape is closed! +    draw_cs_line(s.p[i],s.p[(i+1)%(s.len+(s.len==1))]); +  } +/*  glBegin(GL_LINE_STRIP); +  glColor3f(0.0, 1.0, 0.0); +  for(i=0;i<s.len+(s.len==1);i++) { +    glVertex2i(s.p[i].x,s.p[i].y); +  } +  glEnd(); +*/  } -void draw_c3_shape() { - //oh lawdy... this should be draw_cs_shape... +void draw_cs_filled_shape(cs_s_t s) { +  draw_cs_shape(s); +//  glBegin(GL_POLYGON); +//  glVertex2s(); +//  glEnd();  } -static void -graphics_init(void) -{ -  GLenum type; -  int j; -  GLubyte *img; -  GLsizei imgWidth = 128; - -  type = GLUT_RGB; -  type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; -  glutInitDisplayMode(type); -  glutCreateWindow("ABGR extension"); -  if (!glutExtensionSupported("GL_EXT_abgr")) { -    printf("Couldn't find abgr extension.\n"); -    exit(0); -  } +void set_color() { + glColor3f(0.0, 1.0, 0.0); +} -  glMatrixMode(GL_PROJECTION); -  glLoadIdentity(); -  gluPerspective(60.0, 1.0, 0.1, 1000.0); -  glMatrixMode(GL_MODELVIEW); -  glDisable(GL_DITHER); +void clear_backbuffer() { +  glClearColor(0.0, 0.0, 0.0, 1.0); +  glClear(GL_COLOR_BUFFER_BIT); +} -  glutKeyboardFunc(keypress_handler); -  glutDisplayFunc(draw_screen); +void flipscreen() { +//  glutSwapBuffers(); +  glFlush(); +} + +void red_and_blue_magic() {  } -/* ARGSUSED1 */ -static void -keypress_handler(unsigned char key, int x, int y) -{ +void keypress_handler(unsigned char key, int x, int y) {    switch (key) {    case 27:      exit(0);    }  } -static void draw_screen(void) +/* draw_screen is in graphics.c +void draw_screen(void)  { -  glClearColor(0.0, 0.0, 0.0, 1.0); -  glClear(GL_COLOR_BUFFER_BIT); +}*/ -  glRasterPos3f(0.2, -0.8, -1.5); -  glDrawPixels(128, 128, GL_RGBA, GL_UNSIGNED_BYTE, ubImage); -  if (doubleBuffer) { -    glutSwapBuffers(); -  } else { -    glFlush(); -  } -} +/*void derp_screen() { +  glClear(GL_COLOR_BUFFER_BIT); + +  draw_cs_line((cs_t){0,10},(cs_t){200,210}); + +// clear_backbuffer(); +// set_color(); + flipscreen(); +}*/ -static void -Args(int argc, char **argv) +void graphics_init(void)  { -  GLint i; +//  GLenum type; -  doubleBuffer = GL_TRUE; +//  type = GLUT_RGB; +//  type |= GLUT_DOUBLE; +  int argc=0; +  char *argv[]={"derp",0}; +  glutInit(&argc,argv); +//  glutInitDisplayMode(type); +  glutCreateWindow("hackvr opengl and glut testing"); -  for (i = 1; i < argc; i++) { -    if (strcmp(argv[i], "-sb") == 0) { -      doubleBuffer = GL_FALSE; -    } else if (strcmp(argv[i], "-db") == 0) { -      doubleBuffer = GL_TRUE; -    } -  } +  glMatrixMode(GL_PROJECTION); +  glLoadIdentity(); +  gluPerspective(60.0, 1.0, 0.1, 1000.0); +  glMatrixMode(GL_MODELVIEW); +  glDisable(GL_DITHER); + +  glutKeyboardFunc(keypress_handler); +//  glutDisplayFunc(derp_screen); +  glutReshapeFunc(set_aspect_ratio);  } +  void graphics_event_handler() { -  glutMainLoopUpdate(); -  return 0;             /* ANSI C requires main to return int. */ +  glutMainLoopEvent(); +} + +/* +void main(int argc,char *argv[]) { +  graphics_init(); +  while(1) { +    graphics_event_handler(); +  }  } +*/  | 
