mirror of https://github.com/BOINC/boinc.git
*** empty log message ***
svn path=/trunk/boinc/; revision=2414
This commit is contained in:
parent
a90af17b77
commit
cff7da2611
|
@ -169,8 +169,8 @@ bool throttled_app_render(int x, int y, double t) {
|
|||
bool ok_to_render;
|
||||
|
||||
// the following should be passed in via prefs
|
||||
double max_fps = 1000;
|
||||
double max_gfx_cpu_frac = 1.00;
|
||||
double max_fps = 100;
|
||||
double max_gfx_cpu_frac = 0.5;
|
||||
|
||||
ok_to_render = true;
|
||||
now = dtime();
|
||||
|
|
367
api/gutil.C
367
api/gutil.C
|
@ -78,10 +78,15 @@ void mode_shaded(GLfloat* color) {
|
|||
}
|
||||
|
||||
void mode_texture() {
|
||||
#if 0
|
||||
glMatrixMode( GL_MODELVIEW );
|
||||
glLoadIdentity();
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_LIGHT0);
|
||||
#endif
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_LIGHT0);
|
||||
}
|
||||
|
||||
void mode_unshaded() {
|
||||
|
@ -434,17 +439,30 @@ void draw_text_new(
|
|||
}
|
||||
}
|
||||
|
||||
void MOVING_TEXT_PANEL::init(
|
||||
float* p, float* s, COLOR& c, double d, double ch, double lw, double ls, double m
|
||||
) {
|
||||
memcpy(pos, p, sizeof(pos));
|
||||
memcpy(base_pos, p, sizeof(base_pos));
|
||||
memcpy(size, s, sizeof(size));
|
||||
color = c;
|
||||
theta = 0;
|
||||
dtheta = d;
|
||||
char_height = ch;
|
||||
line_width = lw;
|
||||
line_spacing = ls;
|
||||
margin = m;
|
||||
strcpy(text, "");
|
||||
}
|
||||
|
||||
// draw a rectangle of the given color in the XY plane
|
||||
// and draw the given test in it
|
||||
//
|
||||
void draw_text_panel(
|
||||
GLfloat* _pos, GLfloat* size, GLfloat margin, COLOR color,
|
||||
GLfloat char_height, GLfloat line_width, GLfloat line_spacing,
|
||||
char* text
|
||||
) {
|
||||
void MOVING_TEXT_PANEL::draw() {
|
||||
COLOR side_color = color;
|
||||
GLfloat pos0[3], pos1[3], pos2[3], pos3[3];
|
||||
memcpy(pos0, _pos, sizeof(pos0));
|
||||
memcpy(pos1, _pos, sizeof(pos0));
|
||||
memcpy(pos0, pos, sizeof(pos0));
|
||||
memcpy(pos1, pos, sizeof(pos0));
|
||||
pos1[0] += size[0];
|
||||
memcpy(pos2, pos1, sizeof(pos0));
|
||||
pos2[1] += size[1];
|
||||
|
@ -460,10 +478,10 @@ void draw_text_panel(
|
|||
|
||||
// draw flanges
|
||||
//
|
||||
color.r /= 2;
|
||||
color.g /= 2;
|
||||
color.b /= 2;
|
||||
glColor4fv(&color.r);
|
||||
side_color.r /= 2;
|
||||
side_color.g /= 2;
|
||||
side_color.b /= 2;
|
||||
glColor4fv(&side_color.r);
|
||||
GLfloat posa0[3], posa1[3], posa2[3], posa3[3];
|
||||
memcpy(posa0, pos0, sizeof(pos0));
|
||||
memcpy(posa1, pos1, sizeof(pos0));
|
||||
|
@ -498,6 +516,24 @@ void draw_text_panel(
|
|||
draw_text(pos3, char_height, line_width, line_spacing, text);
|
||||
}
|
||||
|
||||
void MOVING_TEXT_PANEL::move(double dt) {
|
||||
pos[0] = base_pos[0] + sin(theta);
|
||||
pos[1] = base_pos[1];
|
||||
pos[2] = base_pos[2] + cos(theta);
|
||||
theta += dtheta*dt;
|
||||
}
|
||||
|
||||
static int compare_tp(const void* p1, const void* p2) {
|
||||
MOVING_TEXT_PANEL* tp1=(MOVING_TEXT_PANEL*)p1, *tp2 = (MOVING_TEXT_PANEL*)p2;
|
||||
if (tp1->pos[2] > tp2->pos[2]) return 1;
|
||||
if (tp2->pos[2] > tp1->pos[2]) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MOVING_TEXT_PANEL::sort(MOVING_TEXT_PANEL* tp, int n) {
|
||||
qsort(tp, n, sizeof(MOVING_TEXT_PANEL), compare_tp);
|
||||
}
|
||||
|
||||
PROGRESS::PROGRESS(
|
||||
GLfloat* p, GLfloat l, GLfloat r, GLfloat in, GLfloat* c, GLfloat* ic
|
||||
) {
|
||||
|
@ -602,83 +638,6 @@ void GRAPH_2D::draw(float* d, int ln) {
|
|||
void GRAPH_2D::add_tick(float x, float yfrac) {
|
||||
}
|
||||
|
||||
// read a PPM file
|
||||
// to generate PPM from JPEG:
|
||||
// mogrify -format ppm foo.jpg
|
||||
// or xv foo.jpg; right click on image, choose PPM
|
||||
//
|
||||
int read_ppm_file(char* name, int& w, int& h, unsigned char** arrayp) {
|
||||
FILE* f;
|
||||
char buf[256];
|
||||
char img_type;
|
||||
unsigned char* array;
|
||||
int i;
|
||||
|
||||
f = fopen(name, "rb");
|
||||
if (!f) return -1;
|
||||
do {fgets(buf, 256, f);} while (buf[0] == '#');
|
||||
if (buf[0] != 'P') {
|
||||
return -1;
|
||||
}
|
||||
img_type = buf[1];
|
||||
do {fgets(buf, 256, f);} while (buf[0] == '#');
|
||||
sscanf(buf, "%d %d", &w, &h);
|
||||
do {fgets(buf, 256, f);} while (buf[0] == '#');
|
||||
array = (unsigned char*)malloc(w*h*3);
|
||||
switch(img_type) { // TODO: pad image dimension to power of 2
|
||||
case '3':
|
||||
for (i=0; i<w*h*3; i++) {
|
||||
fscanf(f, "%d", array+i);
|
||||
}
|
||||
case '6':
|
||||
fread(array, 3, w*h, f);
|
||||
break;
|
||||
}
|
||||
*arrayp = array;
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int texture_id;
|
||||
|
||||
int init_texture(char* filename) {
|
||||
unsigned char* pixels;
|
||||
int width, height, retVal;
|
||||
int err;
|
||||
retVal = read_ppm_file(filename, width, height, &pixels);
|
||||
if (retVal) return retVal;
|
||||
glGenTextures(1, &texture_id);
|
||||
err = glGetError();
|
||||
if (err) return err;
|
||||
glBindTexture(GL_TEXTURE_2D, texture_id);
|
||||
err = glGetError();
|
||||
if (err) return err;
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
err = glGetError();
|
||||
if (err) return err;
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
err = glGetError();
|
||||
if (err) return err;
|
||||
//ASSERT(0);
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D,
|
||||
0,
|
||||
3,
|
||||
//0,
|
||||
//0,
|
||||
width,
|
||||
height,
|
||||
0,
|
||||
GL_RGB,
|
||||
GL_UNSIGNED_BYTE,
|
||||
pixels // dimension of PPM file MUST be power of 2
|
||||
);
|
||||
err = glGetError();
|
||||
if (err) {
|
||||
fprintf(stderr, "glTexImage2D returned error # %d: %s\n", err, gluErrorString(err));
|
||||
return err;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
struct Vertex
|
||||
{
|
||||
float tu, tv;
|
||||
|
@ -694,33 +653,6 @@ Vertex g_quadVertices[] =
|
|||
};
|
||||
float white[4] = {1., 1., 1., 1.};
|
||||
|
||||
void draw_texture(float* p, float* size) {
|
||||
float pos[3];
|
||||
memcpy(pos, p, sizeof(pos));
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, texture_id);
|
||||
mode_shaded(white);
|
||||
#if 1
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0., 1.);
|
||||
glVertex3fv(pos);
|
||||
pos[0] += size[0];
|
||||
glTexCoord2f(1., 1.);
|
||||
glVertex3fv(pos);
|
||||
pos[1] += size[1];
|
||||
glTexCoord2f(1., 0.);
|
||||
glVertex3fv(pos);
|
||||
pos[0] -= size[0];
|
||||
glTexCoord2f(0., 0.);
|
||||
glVertex3fv(pos);
|
||||
glEnd();
|
||||
#else
|
||||
glInterleavedArrays( GL_T2F_V3F, 0, g_quadVertices );
|
||||
glDrawArrays( GL_QUADS, 0, 4 );
|
||||
#endif
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
//star drawing functions -<oliver wang>-
|
||||
#define PI 3.14159265358979323846264
|
||||
|
@ -737,7 +669,7 @@ void build_stars(int size, float speed)
|
|||
while(i<size)
|
||||
{
|
||||
|
||||
float z = (float)(rand()%2000-1000);
|
||||
float z = -frand()*1000;
|
||||
float alpha = 2.0*PI*(float)((rand()%359)/359.0) ;
|
||||
float beta = asin(z/1000.0f);
|
||||
float x = 1000.0f * cos(beta) * cos(alpha);
|
||||
|
@ -824,7 +756,7 @@ void update_stars(int number, float speed)
|
|||
}
|
||||
|
||||
void replaceStar(Star* star) {
|
||||
float z = (float)(rand()%2000-1000);
|
||||
float z = -frand()*1000;
|
||||
float alpha = 2.0*PI*(float)((rand()%359)/359.0) ;
|
||||
float beta = asin(z/1000.0f);
|
||||
float x = 1000.0f * cos(beta) * cos(alpha);
|
||||
|
@ -838,9 +770,135 @@ void replaceStar(Star* star) {
|
|||
star->v=v;
|
||||
}
|
||||
|
||||
//jpg texture support
|
||||
//this is the array that will contain pointers to texture pixel data
|
||||
UINT g_Texture[MAX_TEXTURES];
|
||||
// ------------ OLD TEXTURE STUFF --------------------
|
||||
// read a PPM file
|
||||
// to generate PPM from JPEG:
|
||||
// mogrify -format ppm foo.jpg
|
||||
// or xv foo.jpg; right click on image, choose PPM
|
||||
//
|
||||
int read_ppm_file(char* name, int& w, int& h, unsigned char** arrayp) {
|
||||
FILE* f;
|
||||
char buf[256];
|
||||
char img_type;
|
||||
unsigned char* array;
|
||||
int i;
|
||||
|
||||
f = fopen(name, "rb");
|
||||
if (!f) return -1;
|
||||
do {fgets(buf, 256, f);} while (buf[0] == '#');
|
||||
if (buf[0] != 'P') {
|
||||
return -1;
|
||||
}
|
||||
img_type = buf[1];
|
||||
do {fgets(buf, 256, f);} while (buf[0] == '#');
|
||||
sscanf(buf, "%d %d", &w, &h);
|
||||
do {fgets(buf, 256, f);} while (buf[0] == '#');
|
||||
array = (unsigned char*)malloc(w*h*3);
|
||||
switch(img_type) { // TODO: pad image dimension to power of 2
|
||||
case '3':
|
||||
for (i=0; i<w*h*3; i++) {
|
||||
fscanf(f, "%d", array+i);
|
||||
}
|
||||
case '6':
|
||||
fread(array, 3, w*h, f);
|
||||
break;
|
||||
}
|
||||
*arrayp = array;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
unsigned int texture_id;
|
||||
|
||||
int init_texture(char* filename) {
|
||||
unsigned char* pixels;
|
||||
int width, height, retVal;
|
||||
int err;
|
||||
retVal = read_ppm_file(filename, width, height, &pixels);
|
||||
if (retVal) return retVal;
|
||||
glGenTextures(1, &texture_id);
|
||||
err = glGetError();
|
||||
if (err) return err;
|
||||
glBindTexture(GL_TEXTURE_2D, texture_id);
|
||||
err = glGetError();
|
||||
if (err) return err;
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
err = glGetError();
|
||||
if (err) return err;
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
err = glGetError();
|
||||
if (err) return err;
|
||||
//ASSERT(0);
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D,
|
||||
0,
|
||||
3,
|
||||
//0,
|
||||
//0,
|
||||
width,
|
||||
height,
|
||||
0,
|
||||
GL_RGB,
|
||||
GL_UNSIGNED_BYTE,
|
||||
pixels // dimension of PPM file MUST be power of 2
|
||||
);
|
||||
err = glGetError();
|
||||
if (err) {
|
||||
fprintf(stderr, "glTexImage2D returned error # %d: %s\n", err, gluErrorString(err));
|
||||
return err;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
// draw a texture at a given position and size.
|
||||
// Change size if needed so aspect ratio of texture isn't changed
|
||||
//
|
||||
void draw_texture(float* p, float* size, TEXTURE_DESC& td) {
|
||||
float pos[3];
|
||||
double tratio, sratio, new_size;
|
||||
memcpy(pos, p, sizeof(pos));
|
||||
glColor4f(1.,1.,1.,1.);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, td.id);
|
||||
|
||||
tratio = td.xsize/td.ysize;
|
||||
sratio = size[0]/size[1];
|
||||
|
||||
if (tratio > sratio) { // texture is wider than space
|
||||
new_size = size[0]/tratio;
|
||||
pos[1] += (size[1]-new_size)/2;
|
||||
size[1] = new_size;
|
||||
}
|
||||
if (sratio > tratio) { // space is wider than texture
|
||||
new_size = size[1]*tratio;
|
||||
pos[0] += (size[0]-new_size)/2;
|
||||
size[0] = new_size;
|
||||
}
|
||||
|
||||
#if 1
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0., 1.);
|
||||
glVertex3fv(pos);
|
||||
pos[0] += size[0];
|
||||
glTexCoord2f(1., 1.);
|
||||
glVertex3fv(pos);
|
||||
pos[1] += size[1];
|
||||
glTexCoord2f(1., 0.);
|
||||
glVertex3fv(pos);
|
||||
pos[0] -= size[0];
|
||||
glTexCoord2f(0., 0.);
|
||||
glVertex3fv(pos);
|
||||
glEnd();
|
||||
#else
|
||||
glInterleavedArrays( GL_T2F_V3F, 0, g_quadVertices );
|
||||
glDrawArrays( GL_QUADS, 0, 4 );
|
||||
#endif
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
//// --------------- NEW TEXTURE STUFF ----------------------
|
||||
|
||||
void DecodeJPG(jpeg_decompress_struct* cinfo, tImageJPG *pImageData) {
|
||||
jpeg_read_header(cinfo, TRUE);
|
||||
|
@ -884,72 +942,78 @@ tImageJPG *LoadJPG(const char *filename) {
|
|||
return pImageData;
|
||||
}
|
||||
|
||||
bool CreateTextureJPG(UINT textureArray[], char* strFileName, int textureID) {
|
||||
if(!strFileName) return false;
|
||||
int CreateTextureJPG(char* strFileName, TEXTURE_DESC& td) {
|
||||
if(!strFileName) return -1;
|
||||
tImageJPG *pImage = LoadJPG(strFileName); // Load the image and store the data
|
||||
if(pImage == NULL) return false;
|
||||
glGenTextures(1, &textureArray[textureID]);
|
||||
glBindTexture(GL_TEXTURE_2D, textureArray[textureID]);
|
||||
if(pImage == NULL) return -1;
|
||||
glGenTextures(1, &td.id);
|
||||
glBindTexture(GL_TEXTURE_2D, td.id);
|
||||
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pImage->sizeX, pImage->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pImage->data);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
|
||||
td.xsize = pImage->sizeX;
|
||||
td.ysize = pImage->sizeY;
|
||||
|
||||
if (pImage) {
|
||||
if (pImage->data) {
|
||||
free(pImage->data);
|
||||
}
|
||||
|
||||
free(pImage);
|
||||
}
|
||||
return true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool CreateTextureBMP(UINT textureArray[], char* strFileName, int textureID) {
|
||||
int CreateTextureBMP(char* strFileName, TEXTURE_DESC& td) {
|
||||
#ifdef _WIN32
|
||||
DIB_BITMAP image;
|
||||
if(image.loadBMP(strFileName) == false) {
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
glGenTextures(1, &textureArray[textureID]);
|
||||
glBindTexture(GL_TEXTURE_2D, textureArray[textureID]);
|
||||
glGenTextures(1, &td.id);
|
||||
glBindTexture(GL_TEXTURE_2D, td.id);
|
||||
gluBuild2DMipmaps(GL_TEXTURE_2D, image.get_channels(), image.get_width(),
|
||||
image.get_height(), GL_BGR_EXT, GL_UNSIGNED_BYTE,
|
||||
image.getLinePtr(0)
|
||||
);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
|
||||
td.xsize = image.get_width();
|
||||
td.ysize = image.get_height();
|
||||
#endif
|
||||
return true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool CreateTexturePPM(UINT textureArray[], char* strFileName, int textureID) {
|
||||
int CreateTexturePPM(char* strFileName, TEXTURE_DESC& td) {
|
||||
#ifdef _WIN32
|
||||
unsigned char* pixels;
|
||||
int width, height;
|
||||
if (read_ppm_file(strFileName, width, height, &pixels)==-1) return false;
|
||||
int width, height, retval;
|
||||
retval = read_ppm_file(strFileName, width, height, &pixels);
|
||||
if (retval) return retval;
|
||||
|
||||
glGenTextures(1, &textureArray[textureID]);
|
||||
glBindTexture(GL_TEXTURE_2D, textureArray[textureID]);
|
||||
glGenTextures(1, &td.id);
|
||||
glBindTexture(GL_TEXTURE_2D, td.id);
|
||||
gluBuild2DMipmaps(GL_TEXTURE_2D,3,width,height,GL_RGB,GL_UNSIGNED_BYTE,pixels);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
|
||||
td.xsize = width;
|
||||
td.ysize = height;
|
||||
#endif
|
||||
return true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool CreateTextureTGA(UINT textureArray[], char* strFileName, int textureID) {
|
||||
int CreateTextureTGA(char* strFileName, TEXTURE_DESC& td) {
|
||||
#ifdef _WIN32
|
||||
if(!strFileName) // Return from the function if no file name was passed in
|
||||
return false;
|
||||
return -1;
|
||||
|
||||
tImageTGA *pImage = LoadTGA(strFileName); // Load the image and store the data
|
||||
if(pImage == NULL) {
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
glGenTextures(1, &textureArray[textureID]);
|
||||
glBindTexture(GL_TEXTURE_2D, textureArray[textureID]);
|
||||
glGenTextures(1, &td.id);
|
||||
glBindTexture(GL_TEXTURE_2D, td.id);
|
||||
int textureType = GL_RGB;
|
||||
if(pImage->channels == 4) {
|
||||
textureType = GL_RGBA;
|
||||
|
@ -958,6 +1022,8 @@ bool CreateTextureTGA(UINT textureArray[], char* strFileName, int textureID) {
|
|||
pImage->sizeY, textureType, GL_UNSIGNED_BYTE, pImage->data);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
|
||||
td.xsize = pImage->sizeX;
|
||||
td.ysize = pImage->sizeY;
|
||||
|
||||
if (pImage) { // If we loaded the image
|
||||
if (pImage->data) { // If there is texture data
|
||||
|
@ -966,7 +1032,7 @@ bool CreateTextureTGA(UINT textureArray[], char* strFileName, int textureID) {
|
|||
free(pImage); // Free the image structure
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int getFileType(char* file) {
|
||||
|
@ -992,26 +1058,27 @@ static int getFileType(char* file) {
|
|||
else return -1;
|
||||
}
|
||||
|
||||
void create_texture(char* filename, int id) {
|
||||
int create_texture(char* filename, TEXTURE_DESC& td) {
|
||||
switch (getFileType(filename)) {
|
||||
case IMAGE_TYPE_JPG:
|
||||
CreateTextureJPG(g_Texture, filename, id);
|
||||
return CreateTextureJPG(filename, td);
|
||||
break;
|
||||
case IMAGE_TYPE_PPM:
|
||||
CreateTexturePPM(g_Texture, filename, id);
|
||||
return CreateTexturePPM(filename, td);
|
||||
break;
|
||||
case IMAGE_TYPE_BMP:
|
||||
CreateTextureBMP(g_Texture, filename, id);
|
||||
return CreateTextureBMP(filename, td);
|
||||
break;
|
||||
case IMAGE_TYPE_TGA:
|
||||
CreateTextureTGA(g_Texture, filename, id);
|
||||
return CreateTextureTGA(filename, td);
|
||||
break;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
//text
|
||||
UINT listBase[MAX_FONTS];
|
||||
unsigned int listBase[MAX_FONTS];
|
||||
|
||||
void print_text(unsigned int base, char *string)
|
||||
{
|
||||
|
|
55
api/gutil.h
55
api/gutil.h
|
@ -24,8 +24,6 @@
|
|||
#ifndef GUTIL_H
|
||||
#define GUTIL_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
struct COLOR {
|
||||
float r;
|
||||
float g;
|
||||
|
@ -83,7 +81,7 @@ extern void get_2d_positions(float p1,float p2,float p3,
|
|||
double model[16], double proj[16], int viewport[4], double proj_pos[3]
|
||||
);
|
||||
|
||||
// draw a progress bar as an opaque cylinder within a translucent cylinder
|
||||
// a progress bar represented as an opaque cylinder within a translucent cylinder
|
||||
//
|
||||
class PROGRESS {
|
||||
float pos[3];
|
||||
|
@ -94,7 +92,7 @@ public:
|
|||
void draw(float);
|
||||
};
|
||||
|
||||
// draw a graph as a ribbon
|
||||
// a graph drawn as a ribbon in 3D
|
||||
//
|
||||
class GRAPH_2D {
|
||||
float pos[3], size[3];
|
||||
|
@ -109,6 +107,28 @@ public:
|
|||
void add_tick(float x, float yfrac);
|
||||
};
|
||||
|
||||
// a colored panel with some text, that can move cyclically
|
||||
//
|
||||
class MOVING_TEXT_PANEL {
|
||||
float base_pos[3];
|
||||
float size[3];
|
||||
float theta;
|
||||
float dtheta;
|
||||
float char_height;
|
||||
float line_width;
|
||||
float line_spacing;
|
||||
double margin;
|
||||
COLOR color;
|
||||
public:
|
||||
char text[1024];
|
||||
float pos[3];
|
||||
void init(float* pos, float* size, COLOR& color, double dtheta, double ch, double lw, double ls, double margin);
|
||||
void draw();
|
||||
static void sort(MOVING_TEXT_PANEL* tp, int n);
|
||||
void move(double dt);
|
||||
};
|
||||
|
||||
|
||||
// ----- STUFF RELATED TO STARFIELDS
|
||||
//
|
||||
struct Star {
|
||||
|
@ -128,11 +148,20 @@ extern void replaceStar(Star* tmpStar);
|
|||
#define IMAGE_TYPE_BMP 2
|
||||
#define IMAGE_TYPE_TGA 3
|
||||
|
||||
struct TEXTURE_DESC {
|
||||
unsigned int id;
|
||||
double xsize; // size of underlying image
|
||||
double ysize;
|
||||
};
|
||||
|
||||
#if 0
|
||||
// read a portable pixmap file
|
||||
//
|
||||
extern int read_ppm(char* name, int& w, int& h, unsigned char** arrayp);
|
||||
extern int init_texture(char* filename);
|
||||
extern void draw_texture(float* pos, float* size);
|
||||
#endif
|
||||
|
||||
extern void draw_texture(float* pos, float* size, TEXTURE_DESC&);
|
||||
|
||||
struct tImageJPG {
|
||||
int rowSpan;
|
||||
|
@ -141,22 +170,18 @@ struct tImageJPG {
|
|||
unsigned char *data;
|
||||
};
|
||||
|
||||
typedef unsigned int UINT;
|
||||
|
||||
#define MAX_TEXTURES 16
|
||||
extern UINT g_Texture[MAX_TEXTURES];
|
||||
extern bool CreateTextureJPG(UINT textureArray[], char* strFileName, int textureID);
|
||||
extern bool CreateTextureBMP(UINT textureArray[], char* strFileName, int textureID);
|
||||
extern bool CreateTexturePPM(UINT textureArray[], char* strFileName, int textureID);
|
||||
extern bool CreateTextureTGA(UINT textureArray[], char* strFileName, int textureID);
|
||||
extern void create_texture(char* filename, int id);
|
||||
extern int CreateTextureJPG(char* strFileName, TEXTURE_DESC&);
|
||||
extern int CreateTextureBMP(char* strFileName, TEXTURE_DESC&);
|
||||
extern int CreateTexturePPM(char* strFileName, TEXTURE_DESC&);
|
||||
extern int CreateTextureTGA(char* strFileName, TEXTURE_DESC&);
|
||||
extern int create_texture(char* filename, TEXTURE_DESC&);
|
||||
extern tImageJPG *LoadJPG(const char *filename);
|
||||
|
||||
|
||||
// ----- STUFF RELATED TO FONTS
|
||||
//
|
||||
#define MAX_FONTS 16
|
||||
extern UINT listBase[MAX_FONTS];
|
||||
extern unsigned int listBase[MAX_FONTS];
|
||||
extern void MyCreateFont(unsigned int &base, char *fontName, int Size,int weight);
|
||||
extern void print_text(unsigned int base, char *string);
|
||||
|
||||
|
|
87
api/reduce.C
87
api/reduce.C
|
@ -80,7 +80,7 @@ void REDUCED_ARRAY::reset() {
|
|||
last_ry_count = 0;
|
||||
}
|
||||
|
||||
void REDUCED_ARRAY::init_draw(float* p, float* s, double h0, double dh, float trans) {
|
||||
void REDUCED_ARRAY::init_draw(GRAPH_DRAW_STYLE st, float* p, float* s, double h0, double dh, float trans) {
|
||||
memcpy(draw_pos, p, sizeof(draw_pos));
|
||||
memcpy(draw_size, s, sizeof(draw_size));
|
||||
draw_deltax = draw_size[0]/rdimx;
|
||||
|
@ -88,6 +88,7 @@ void REDUCED_ARRAY::init_draw(float* p, float* s, double h0, double dh, float tr
|
|||
hue0 = h0;
|
||||
dhue = dh;
|
||||
alpha = trans;
|
||||
draw_style = st;
|
||||
}
|
||||
|
||||
// reduce a single row. This is called only if sdimx > rdimx;
|
||||
|
@ -267,45 +268,8 @@ void REDUCED_ARRAY::draw_row_rect_x(int row) {
|
|||
float* row0=0;
|
||||
int trow=row-1;
|
||||
float* trow0=0;
|
||||
z0 = draw_pos[2] + (draw_size[2]*row)/rdimy;
|
||||
z1 = z0+.14f;
|
||||
row0 = rrow(row);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
for (i=0; i<rdimx; i++) {
|
||||
x0 = draw_pos[0] + (draw_size[0]*i)/rdimx;
|
||||
x1 = x0 + draw_deltax*.95f;
|
||||
h = (row0[i]-rdata_min)/(rdata_max-rdata_min);
|
||||
|
||||
y0 = draw_pos[1];
|
||||
y1 = draw_pos[1] + draw_size[1]*h;
|
||||
|
||||
double hue = hue0 + (dhue*i)/rdimx;
|
||||
if (hue > 1) hue -= 1;
|
||||
double sat = 1.;
|
||||
double lum = .5 + h/2;
|
||||
COLOR color;
|
||||
HLStoRGB(hue, lum, sat, color);
|
||||
glColor4f(color.r, color.g, color.b, alpha);
|
||||
|
||||
//front
|
||||
|
||||
glVertex3f(x0, y0, z0);
|
||||
glVertex3f(x1, y0, z0);
|
||||
glVertex3f(x1, y1, z0);
|
||||
glVertex3f(x0, y1, z0);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void REDUCED_ARRAY::draw_row_rect_x(DrawType type,int row) {
|
||||
float z0=0,z1=0,x0=0,x1=0,y0=0,y1=0,h=0;
|
||||
int i=0;
|
||||
float* row0=0;
|
||||
int trow=row-1;
|
||||
float* trow0=0;
|
||||
switch(type) {
|
||||
case TYPE_QUAD:
|
||||
switch(draw_style) {
|
||||
case GRAPH_DRAW_STYLE_QUAD:
|
||||
z0 = draw_pos[2] + (draw_size[2]*row)/rdimy;
|
||||
z1 = z0+.14f;
|
||||
row0 = rrow(row);
|
||||
|
@ -429,7 +393,7 @@ void REDUCED_ARRAY::draw_row_rect_x(DrawType type,int row) {
|
|||
// }
|
||||
glEnd();
|
||||
break;
|
||||
case TYPE_SURFACE:
|
||||
case GRAPH_DRAW_STYLE_SURFACE:
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
|
||||
z0 = draw_pos[2] + (draw_size[2]*row)/rdimy;
|
||||
|
@ -501,7 +465,7 @@ void REDUCED_ARRAY::draw_row_rect_x(DrawType type,int row) {
|
|||
}
|
||||
glEnd();
|
||||
break;
|
||||
case TYPE_WAVE:
|
||||
case GRAPH_DRAW_STYLE_WAVE:
|
||||
glLineWidth(1.0f);
|
||||
z0 = draw_pos[2] + (draw_size[2]*row)/rdimy;
|
||||
z1 = z0+.14f;
|
||||
|
@ -561,7 +525,7 @@ void REDUCED_ARRAY::draw_row_rect_x(DrawType type,int row) {
|
|||
glEnd();
|
||||
glDisable(GL_LINE_SMOOTH);
|
||||
break;
|
||||
case TYPE_STRIP:
|
||||
case GRAPH_DRAW_STYLE_STRIP:
|
||||
z0 = draw_pos[2] + (draw_size[2]*row)/rdimy;
|
||||
z1 = z0+.14f;
|
||||
row0 = rrow(row);
|
||||
|
@ -657,34 +621,6 @@ void REDUCED_ARRAY::draw_row_rect_y(int row) {
|
|||
void REDUCED_ARRAY::draw_row_line(int row) {
|
||||
}
|
||||
|
||||
void REDUCED_ARRAY::draw(DrawType type, int r0, int rn) {
|
||||
int i;
|
||||
mode_unshaded();
|
||||
if (rdimx == sdimx) {
|
||||
if (rdimy == sdimy) {
|
||||
for (i=r0; i<rn; i++) {
|
||||
draw_row_rect_x(type,i);
|
||||
}
|
||||
} else {
|
||||
for (i=r0; i<rn; i++) {
|
||||
draw_row_rect_x(type,i);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (rdimy == sdimy) {
|
||||
for (i=r0; i<rn; i++) {
|
||||
draw_row_rect_x(type,i);
|
||||
}
|
||||
} else {
|
||||
for (i=r0; i<rn; i++) {
|
||||
draw_row_rect_x(type,i);
|
||||
}
|
||||
}
|
||||
}
|
||||
ndrawn_rows = rn;
|
||||
glFlush();
|
||||
}
|
||||
|
||||
void REDUCED_ARRAY::draw(int r0, int rn) {
|
||||
int i;
|
||||
mode_unshaded();
|
||||
|
@ -714,16 +650,11 @@ void REDUCED_ARRAY::draw(int r0, int rn) {
|
|||
}
|
||||
|
||||
void REDUCED_ARRAY::draw_all() {
|
||||
draw(TYPE_QUAD,0, nvalid_rows);
|
||||
draw(0, nvalid_rows);
|
||||
}
|
||||
|
||||
void REDUCED_ARRAY::draw_new() {
|
||||
draw(TYPE_QUAD,ndrawn_rows, nvalid_rows);
|
||||
}
|
||||
|
||||
void REDUCED_ARRAY::draw_part(DrawType type, double frac) {
|
||||
int nr = (int)(nvalid_rows*frac);
|
||||
draw(type,0, nr);
|
||||
draw(ndrawn_rows, nvalid_rows);
|
||||
}
|
||||
|
||||
void REDUCED_ARRAY::draw_part(double frac) {
|
||||
|
|
13
api/reduce.h
13
api/reduce.h
|
@ -27,7 +27,12 @@
|
|||
#define REDUCE_METHOD_MAX 2 // Take the maximum of reduced elements
|
||||
#define REDUCE_METHOD_MIN 3 // Take the minimum of reduced elements
|
||||
|
||||
enum DrawType {TYPE_QUAD,TYPE_STRIP,TYPE_WAVE,TYPE_SURFACE};
|
||||
enum GRAPH_DRAW_STYLE {
|
||||
GRAPH_DRAW_STYLE_QUAD,
|
||||
GRAPH_DRAW_STYLE_STRIP,
|
||||
GRAPH_DRAW_STYLE_WAVE,
|
||||
GRAPH_DRAW_STYLE_SURFACE
|
||||
};
|
||||
|
||||
class REDUCED_ARRAY {
|
||||
public:
|
||||
|
@ -54,11 +59,12 @@ public:
|
|||
double hue0;
|
||||
double dhue;
|
||||
float alpha;
|
||||
GRAPH_DRAW_STYLE draw_style;
|
||||
|
||||
REDUCED_ARRAY();
|
||||
~REDUCED_ARRAY();
|
||||
void init(int, int);
|
||||
void init_draw(float*, float*, double, double, float);
|
||||
void init_draw(GRAPH_DRAW_STYLE, float*, float*, double, double, float);
|
||||
void set_max_dims(int, int);
|
||||
void reduce_source_row(float*, float*);
|
||||
void add_source_row(float*);
|
||||
|
@ -69,15 +75,12 @@ public:
|
|||
return rdata + j*rdimx;
|
||||
}
|
||||
void draw_row_quad(int);
|
||||
void draw_row_rect_x(DrawType,int);
|
||||
void draw_row_rect_x(int);
|
||||
void draw_row_rect_y(int);
|
||||
void draw_row_line(int);
|
||||
void draw(int, int);
|
||||
void draw(DrawType,int, int);
|
||||
void draw_new();
|
||||
void draw_all();
|
||||
void draw_part(DrawType,double frac);
|
||||
void draw_part(double frac);
|
||||
void draw_axes();
|
||||
void draw_axis_labels();
|
||||
|
|
|
@ -6536,3 +6536,19 @@ David Oct 4 2003
|
|||
windows_opengl.C
|
||||
lib/
|
||||
xml_util.C
|
||||
|
||||
David Oct 6 2003
|
||||
- Created class MOVING_TEXT_PANEL (in boinc/api/gutil.h)
|
||||
to do Astropulse-type text display
|
||||
- Created class TEXTURE_DESC (same place)
|
||||
to represent an OpenGL texture (including its ID and size).
|
||||
- Modify draw_texture() to not change the aspect ratio of the picture;
|
||||
it shrinks the image in one dimension or the other, and centers
|
||||
it in the allotted space
|
||||
- Add a GRAPH_DRAW_STYLE field to REDUCED_ARRAY
|
||||
- Eliminate methods of REDUCED_ARRAY that take a style argument
|
||||
|
||||
api/
|
||||
graphics_api.C
|
||||
gutil.C,h
|
||||
reduce.C,h
|
||||
|
|
Loading…
Reference in New Issue