2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
2003-10-15 19:08:51 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation;
|
|
|
|
// either version 2.1 of the License, or (at your option) any later version.
|
2003-10-15 19:08:51 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This software is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
2003-05-20 00:03:39 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
2007-10-09 11:35:47 +00:00
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2003-05-20 00:03:39 +00:00
|
|
|
|
2003-10-05 05:26:59 +00:00
|
|
|
// various utility classes for OpenGL programming,
|
|
|
|
// used in Astropulse and SETI@home
|
|
|
|
// See also graphics_data.C,h
|
|
|
|
|
2003-10-03 22:51:28 +00:00
|
|
|
#ifndef GUTIL_H
|
|
|
|
#define GUTIL_H
|
2003-10-03 00:44:25 +00:00
|
|
|
|
2006-04-13 22:17:23 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2003-01-29 21:13:15 +00:00
|
|
|
struct COLOR {
|
2003-10-05 21:30:00 +00:00
|
|
|
float r;
|
|
|
|
float g;
|
|
|
|
float b;
|
|
|
|
float a;
|
2005-02-11 02:15:20 +00:00
|
|
|
COLOR(float rr=0,float gg=0, float bb=0, float aa=0) : r(rr),g(gg),b(bb),a(aa) {};
|
2003-01-29 21:13:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern void HLStoRGB( double H, double L, double S, COLOR& c);
|
|
|
|
|
2003-10-16 21:06:10 +00:00
|
|
|
extern void scale_screen(int w,int h);
|
|
|
|
extern void center_screen(int w,int h);
|
2003-01-29 21:13:15 +00:00
|
|
|
|
2003-10-05 21:30:00 +00:00
|
|
|
extern void drawSphere(float* pos, float rad);
|
|
|
|
extern void drawCylinder(bool vertical, float* pos, float len, float rad);
|
2003-01-29 21:13:15 +00:00
|
|
|
|
|
|
|
#define TEXT_LEFT 0
|
|
|
|
#define TEXT_CENTER 1
|
|
|
|
#define TEXT_RIGHT 2
|
|
|
|
extern void draw_text_line(
|
2004-07-09 15:29:18 +00:00
|
|
|
float* pos, float height, float width, const char *text,
|
2003-01-29 21:13:15 +00:00
|
|
|
int justify=TEXT_LEFT
|
|
|
|
);
|
2003-09-16 23:45:29 +00:00
|
|
|
|
2004-07-09 15:29:18 +00:00
|
|
|
void draw_text_simple(const char* text,float line_width,float char_height);
|
2003-09-16 23:45:29 +00:00
|
|
|
|
2003-01-29 21:13:15 +00:00
|
|
|
extern void draw_text(
|
2004-07-09 15:29:18 +00:00
|
|
|
float* pos, float height, float width, float spacing, const char *text
|
2003-01-29 21:13:15 +00:00
|
|
|
);
|
2003-09-10 23:44:46 +00:00
|
|
|
|
2003-09-18 23:55:11 +00:00
|
|
|
extern void draw_text_new(
|
2004-07-09 15:29:18 +00:00
|
|
|
float* pos, float height, float width, float spacing, const char *text
|
2003-09-18 23:55:11 +00:00
|
|
|
);
|
|
|
|
|
2003-10-16 21:06:10 +00:00
|
|
|
extern void draw_text_right(
|
2004-07-09 15:29:18 +00:00
|
|
|
float* pos, float height, float width, float spacing, const char *text
|
2003-10-09 00:21:49 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
extern void draw_text_new_3d(
|
2004-07-09 15:29:18 +00:00
|
|
|
float* pos, float height, float width, float spacing, const char *text
|
2003-10-09 00:21:49 +00:00
|
|
|
);
|
|
|
|
|
2003-09-10 23:44:46 +00:00
|
|
|
extern void draw_rotated_text(
|
2004-07-09 15:29:18 +00:00
|
|
|
float* pos, float height, float width, float spacing, const char *text, float rotation, float* rotation_vector
|
2003-09-10 23:44:46 +00:00
|
|
|
);
|
|
|
|
|
2004-07-09 15:29:18 +00:00
|
|
|
extern float text_width(const char* text);
|
|
|
|
extern float text_width_new(const char* text);
|
2003-01-29 21:13:15 +00:00
|
|
|
extern void draw_text_panel(
|
2003-10-05 21:30:00 +00:00
|
|
|
float* _pos, float* size, float margin, COLOR color,
|
|
|
|
float char_height, float line_width, float line_spacing,
|
2004-07-09 15:29:18 +00:00
|
|
|
const char* text
|
2003-05-20 00:03:39 +00:00
|
|
|
);
|
2003-03-27 18:20:25 +00:00
|
|
|
|
2003-03-30 23:27:22 +00:00
|
|
|
extern void mode_texture();
|
2003-09-16 23:45:29 +00:00
|
|
|
extern void mode_ortho();
|
2003-10-05 21:30:00 +00:00
|
|
|
extern void mode_shaded(float*);
|
2003-03-27 18:20:25 +00:00
|
|
|
extern void mode_unshaded();
|
|
|
|
extern void mode_lines();
|
2003-09-16 23:45:29 +00:00
|
|
|
extern void ortho_done();
|
2003-09-17 23:17:09 +00:00
|
|
|
extern bool get_matrix(double src[16]);
|
|
|
|
extern bool get_projection(double src[16]);
|
|
|
|
extern bool get_viewport(int view[4]);
|
2004-05-15 22:09:26 +00:00
|
|
|
extern void get_2d_positions(double p1, double p2, double p3,
|
2004-07-09 15:29:18 +00:00
|
|
|
double model[16], double proj[16], int viewport[4], double proj_pos[3]
|
2003-10-05 21:30:00 +00:00
|
|
|
);
|
2003-03-27 18:20:25 +00:00
|
|
|
|
2003-10-06 16:10:33 +00:00
|
|
|
// a progress bar represented as an opaque cylinder within a translucent cylinder
|
2003-03-27 18:20:25 +00:00
|
|
|
//
|
2003-10-15 19:08:51 +00:00
|
|
|
class PROGRESS {
|
2003-10-05 21:30:00 +00:00
|
|
|
float color[4], inner_color[4];
|
|
|
|
float len, rad, inner_rad;
|
2003-03-27 18:20:25 +00:00
|
|
|
public:
|
2004-07-09 15:29:18 +00:00
|
|
|
float pos[3];
|
2003-10-31 22:37:46 +00:00
|
|
|
void init(float* pos, float len, float diam, float inner, float* c, float* ic);
|
2003-03-27 18:20:25 +00:00
|
|
|
void draw(float);
|
2005-02-11 02:15:20 +00:00
|
|
|
PROGRESS() : len(0), rad(0), inner_rad(0) {
|
|
|
|
memset(color,0,sizeof(color));
|
|
|
|
memset(inner_color,0,sizeof(inner_color));
|
|
|
|
memset(pos,0,sizeof(pos));
|
|
|
|
};
|
2003-03-27 18:20:25 +00:00
|
|
|
};
|
|
|
|
|
2003-10-09 00:21:49 +00:00
|
|
|
//2d progress bar
|
|
|
|
class PROGRESS_2D {
|
|
|
|
float color[4], inner_color[4];
|
|
|
|
float len, width, inner_width;
|
2004-07-09 15:29:18 +00:00
|
|
|
float pos[3];
|
2003-10-15 00:01:58 +00:00
|
|
|
public:
|
|
|
|
void set_pos(float*);
|
2003-10-31 22:37:46 +00:00
|
|
|
void init(float* pos, float len, float width, float inner_width, float* c, float* ic);
|
2003-10-09 00:21:49 +00:00
|
|
|
void draw(float);
|
2005-02-11 02:15:20 +00:00
|
|
|
PROGRESS_2D() : len(0), width(0), inner_width(0) {
|
|
|
|
memset(color,0,sizeof(color));
|
|
|
|
memset(inner_color,0,sizeof(inner_color));
|
|
|
|
memset(pos,0,sizeof(pos));
|
|
|
|
};
|
2003-10-09 00:21:49 +00:00
|
|
|
};
|
|
|
|
|
2003-10-10 18:00:35 +00:00
|
|
|
// a graph of a function of 1 variable drawn as a ribbon in 3D
|
2003-03-27 18:20:25 +00:00
|
|
|
//
|
2003-10-10 18:00:35 +00:00
|
|
|
class RIBBON_GRAPH {
|
2003-10-10 23:36:19 +00:00
|
|
|
float size[3];
|
2003-03-27 18:20:25 +00:00
|
|
|
float color[4], tick_color[4];
|
|
|
|
float *data, dmax;
|
2003-10-10 18:00:35 +00:00
|
|
|
float tick_yfrac;
|
|
|
|
float ticks[3];
|
2003-03-27 18:20:25 +00:00
|
|
|
int len;
|
|
|
|
void draw_x(int);
|
|
|
|
void draw_y(int);
|
2003-10-10 18:00:35 +00:00
|
|
|
void draw_tick(int i);
|
2004-07-09 15:29:18 +00:00
|
|
|
float pos[3];
|
2003-10-14 23:40:50 +00:00
|
|
|
public:
|
|
|
|
void set_pos(float*);
|
2003-10-31 22:37:46 +00:00
|
|
|
void init(float* pos, float* size, float* color, float* tick_color, float tick_yfrac=0.2);
|
2003-10-15 19:08:51 +00:00
|
|
|
void draw(float* data, int len, bool with_ticks=false);
|
2003-10-10 18:00:35 +00:00
|
|
|
void add_tick(float x, int index);
|
2003-03-28 18:30:39 +00:00
|
|
|
};
|
|
|
|
|
2003-10-14 23:40:50 +00:00
|
|
|
#define PANEL_MAX_LINES 10
|
2003-10-06 16:10:33 +00:00
|
|
|
// a colored panel with some text, that can move cyclically
|
|
|
|
//
|
|
|
|
class MOVING_TEXT_PANEL {
|
2003-10-15 19:08:51 +00:00
|
|
|
float base_pos[3];
|
2003-10-06 16:10:33 +00:00
|
|
|
float theta;
|
|
|
|
float dtheta;
|
|
|
|
COLOR color;
|
2004-07-09 15:29:18 +00:00
|
|
|
float char_height;
|
2003-10-14 22:30:52 +00:00
|
|
|
float line_width;
|
2003-10-15 19:08:51 +00:00
|
|
|
float line_spacing;
|
2004-07-09 15:29:18 +00:00
|
|
|
float size[3];
|
|
|
|
double margin;
|
|
|
|
char text[PANEL_MAX_LINES][256];
|
2003-10-15 19:08:51 +00:00
|
|
|
public:
|
2005-02-11 02:15:20 +00:00
|
|
|
MOVING_TEXT_PANEL();
|
2004-07-09 15:29:18 +00:00
|
|
|
float pos[3];
|
2003-10-06 16:10:33 +00:00
|
|
|
void init(float* pos, float* size, COLOR& color, double dtheta, double ch, double lw, double ls, double margin);
|
|
|
|
void draw();
|
2004-07-09 15:29:18 +00:00
|
|
|
void set_text(int lineno, const char* t);
|
2003-10-14 23:40:50 +00:00
|
|
|
void get_pos(int lineno, float* pos);
|
2003-10-06 16:10:33 +00:00
|
|
|
static void sort(MOVING_TEXT_PANEL* tp, int n);
|
|
|
|
void move(double dt);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-10-31 22:37:46 +00:00
|
|
|
// ----- STARFIELDS
|
2003-05-20 00:03:39 +00:00
|
|
|
//
|
2004-05-15 22:09:26 +00:00
|
|
|
// stars have their own coord system
|
|
|
|
// x = -1..1
|
|
|
|
// y = -1..1
|
|
|
|
// z = 0..zmax
|
|
|
|
// the projection plane is z=1,
|
|
|
|
// and the square +- 1/zmax is mapped to the window
|
|
|
|
//
|
2003-10-09 00:21:49 +00:00
|
|
|
|
2003-10-15 19:08:51 +00:00
|
|
|
struct STAR {
|
2004-07-09 15:29:18 +00:00
|
|
|
double x, y, z;
|
2003-09-16 23:45:29 +00:00
|
|
|
};
|
|
|
|
|
2003-10-10 18:00:35 +00:00
|
|
|
class STARFIELD {
|
2004-05-15 22:09:26 +00:00
|
|
|
double zmax, zmaxinv;
|
|
|
|
double speed;
|
2004-07-09 15:29:18 +00:00
|
|
|
int nstars;
|
|
|
|
void replace_star(int);
|
2003-10-10 18:00:35 +00:00
|
|
|
STAR* stars;
|
2003-10-31 22:37:46 +00:00
|
|
|
public:
|
|
|
|
STARFIELD();
|
2003-10-10 18:00:35 +00:00
|
|
|
void build_stars(int, float);
|
2003-10-16 21:06:10 +00:00
|
|
|
void update_stars(float);
|
2003-10-10 18:00:35 +00:00
|
|
|
};
|
|
|
|
|
2003-09-17 23:17:09 +00:00
|
|
|
|
2003-10-05 05:26:59 +00:00
|
|
|
|
2003-10-31 22:37:46 +00:00
|
|
|
// ----- TEXTURES AND IMAGES
|
2003-10-09 06:00:05 +00:00
|
|
|
|
|
|
|
#define ALIGN_BOTTOM 0
|
|
|
|
#define ALIGN_CENTER 1
|
|
|
|
#define ALIGN_TOP 2
|
2003-10-05 05:26:59 +00:00
|
|
|
|
2005-12-01 00:25:21 +00:00
|
|
|
unsigned int* read_rgb_texture (const char *, int*, int* ,int *);
|
2005-07-19 18:47:51 +00:00
|
|
|
|
2003-10-06 16:10:33 +00:00
|
|
|
struct TEXTURE_DESC {
|
2004-07-09 15:29:18 +00:00
|
|
|
bool present;
|
2003-10-06 16:10:33 +00:00
|
|
|
unsigned int id;
|
|
|
|
double xsize; // size of underlying image
|
|
|
|
double ysize;
|
2005-02-11 02:15:20 +00:00
|
|
|
TEXTURE_DESC() : present(false),id(0),xsize(0),ysize(0) {};
|
2003-10-09 06:00:05 +00:00
|
|
|
void draw(float* pos, float* size, int xalign, int yalign);
|
2004-07-09 15:29:18 +00:00
|
|
|
int load_image_file(const char* filename);
|
|
|
|
int CreateTextureJPG(const char* strFileName);
|
|
|
|
int CreateTextureBMP(const char* strFileName);
|
|
|
|
int CreateTexturePPM(const char* strFileName);
|
|
|
|
int CreateTextureTGA(const char* strFileName);
|
2005-07-19 18:47:51 +00:00
|
|
|
int CreateTextureRGB(const char* strFileName);
|
2003-10-06 16:10:33 +00:00
|
|
|
};
|
|
|
|
|
2003-10-05 05:26:59 +00:00
|
|
|
|
2003-10-31 22:37:46 +00:00
|
|
|
// ----- FONTS
|
2003-10-05 05:26:59 +00:00
|
|
|
//
|
2003-10-10 23:36:19 +00:00
|
|
|
extern unsigned int listBase;
|
2004-07-09 15:29:18 +00:00
|
|
|
extern unsigned int MyCreateFont(const char *fontName, int Size,int weight);
|
|
|
|
extern void print_text(const char* string);
|
2003-10-05 05:26:59 +00:00
|
|
|
|
2003-10-15 19:08:51 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|