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-07-30 22:51:07 +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-07-30 22:51:07 +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
|
|
|
|
2005-07-14 16:46:38 +00:00
|
|
|
#if defined(_WIN32) && !defined(__STDWX_H__) && !defined(_BOINC_WIN_) && !defined(_AFX_STDAFX_H_)
|
2004-06-17 00:05:18 +00:00
|
|
|
#include "boinc_win.h"
|
2005-11-21 18:34:44 +00:00
|
|
|
#else
|
|
|
|
#include "config.h"
|
2005-07-14 16:46:38 +00:00
|
|
|
#endif
|
|
|
|
|
2005-07-18 23:09:43 +00:00
|
|
|
#ifdef _WIN32
|
2006-03-30 22:06:25 +00:00
|
|
|
|
|
|
|
#ifndef SANS_JPEGLIB
|
2005-07-18 23:09:43 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
2004-06-12 18:44:53 +00:00
|
|
|
#include "jpeglib.h"
|
2005-07-18 23:09:43 +00:00
|
|
|
}
|
2006-03-30 20:54:34 +00:00
|
|
|
#else
|
|
|
|
#include "jpeglib.h"
|
2005-07-18 23:09:43 +00:00
|
|
|
#endif
|
2006-03-30 22:06:25 +00:00
|
|
|
#endif
|
|
|
|
|
2004-06-12 18:44:53 +00:00
|
|
|
#include "bmplib.h"
|
|
|
|
#include "tgalib.h"
|
2003-12-24 00:56:48 +00:00
|
|
|
#endif
|
|
|
|
|
2004-03-06 09:45:25 +00:00
|
|
|
#ifndef _WIN32
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
|
|
|
#include <cmath>
|
|
|
|
#include <csetjmp>
|
2006-05-11 23:19:04 +00:00
|
|
|
#if defined(HAVE_MALLOC_H) || defined(_WIN32)
|
|
|
|
#include <malloc.h>
|
2006-05-15 17:14:15 +00:00
|
|
|
#if defined(__MINGW32__) && !defined(alloca)
|
|
|
|
#define alloca(x) _alloca(x)
|
|
|
|
#endif
|
2006-05-11 23:19:04 +00:00
|
|
|
#endif
|
|
|
|
#if defined(HAVE_ALLOCA_H)
|
|
|
|
#include <alloca.h>
|
|
|
|
#endif
|
2006-02-07 01:08:02 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#undef HAVE_STDLIB_H /* Avoid compiler warning (redefined in jconfig,h) */
|
|
|
|
#endif
|
2006-03-30 22:07:26 +00:00
|
|
|
|
|
|
|
#ifndef SANS_JPEGLIB
|
2004-07-15 21:31:06 +00:00
|
|
|
extern "C"{
|
2004-03-06 09:45:25 +00:00
|
|
|
#include <jpeglib.h>
|
2004-07-15 21:31:06 +00:00
|
|
|
}
|
2004-03-06 09:45:25 +00:00
|
|
|
#endif
|
2003-01-29 21:13:15 +00:00
|
|
|
|
2006-03-30 22:07:26 +00:00
|
|
|
#endif
|
|
|
|
|
2004-07-13 13:54:09 +00:00
|
|
|
#include "boinc_gl.h"
|
|
|
|
|
2003-12-24 01:10:05 +00:00
|
|
|
#include "filesys.h"
|
2004-07-09 15:29:18 +00:00
|
|
|
#include "util.h"
|
2003-09-18 23:55:11 +00:00
|
|
|
|
2006-03-30 20:54:34 +00:00
|
|
|
#include "gutil.h"
|
|
|
|
|
2003-03-27 18:20:25 +00:00
|
|
|
GLfloat mat_specular[] = {1.0, 1.0, 1.0, 1.0};
|
|
|
|
GLfloat mat_shininess[] = {40.0};
|
|
|
|
|
2004-05-15 22:09:26 +00:00
|
|
|
// call this to draw 3D stuff with shaded color
|
|
|
|
//
|
2003-03-27 18:20:25 +00:00
|
|
|
void mode_shaded(GLfloat* color) {
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glEnable(GL_LIGHTING);
|
|
|
|
glEnable(GL_LIGHT0);
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
glShadeModel (GL_SMOOTH);
|
|
|
|
glDepthMask(GL_TRUE);
|
|
|
|
glMaterialfv(GL_FRONT, GL_DIFFUSE, color);
|
|
|
|
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
|
|
|
|
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
|
|
|
|
}
|
|
|
|
|
2004-05-15 22:09:26 +00:00
|
|
|
// call this to use textures (turn off lighting)
|
|
|
|
//
|
2003-03-28 18:30:39 +00:00
|
|
|
void mode_texture() {
|
2004-05-15 22:09:26 +00:00
|
|
|
|
2003-10-06 16:10:33 +00:00
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
glDisable(GL_LIGHT0);
|
2003-03-28 18:30:39 +00:00
|
|
|
}
|
|
|
|
|
2004-05-15 22:09:26 +00:00
|
|
|
// call this to draw unshaded color
|
|
|
|
//
|
2003-03-27 18:20:25 +00:00
|
|
|
void mode_unshaded() {
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
glDisable(GL_LIGHT0);
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
2004-05-15 22:09:26 +00:00
|
|
|
glShadeModel(GL_SMOOTH);
|
2003-03-27 18:20:25 +00:00
|
|
|
glDepthMask(GL_TRUE);
|
|
|
|
}
|
|
|
|
|
2004-05-15 22:09:26 +00:00
|
|
|
// call this to render 2D stuff, with 0..1x0..1 getting mapped
|
|
|
|
// to the full window. You must call ortho_done() when done.
|
|
|
|
//
|
2003-10-15 19:08:51 +00:00
|
|
|
void mode_ortho() {
|
2006-04-07 21:35:49 +00:00
|
|
|
glDisable(GL_DEPTH_TEST);
|
2004-07-09 15:29:18 +00:00
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glPushMatrix();
|
2003-09-16 23:45:29 +00:00
|
|
|
glLoadIdentity();
|
2004-05-27 23:46:07 +00:00
|
|
|
glOrtho(0, 1, 0, 1, 0, 1);
|
2004-07-09 15:29:18 +00:00
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glPushMatrix();
|
2003-09-16 23:45:29 +00:00
|
|
|
glLoadIdentity();
|
2004-05-27 23:46:07 +00:00
|
|
|
gluLookAt(
|
|
|
|
0.0, 0.0, 1.0, // eye position
|
2004-07-09 15:29:18 +00:00
|
|
|
0, 0, 0, // where we're looking
|
|
|
|
0.0, 1.0, 0. // up is in positive Y direction
|
2004-05-27 23:46:07 +00:00
|
|
|
);
|
2004-07-09 15:29:18 +00:00
|
|
|
int viewport[4];
|
|
|
|
get_viewport(viewport);
|
|
|
|
center_screen(viewport[2], viewport[3]);
|
|
|
|
scale_screen(viewport[2], viewport[3]);
|
2003-10-29 21:46:00 +00:00
|
|
|
}
|
|
|
|
|
2003-10-15 19:08:51 +00:00
|
|
|
void ortho_done() {
|
2004-07-09 15:29:18 +00:00
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glPopMatrix();
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glPopMatrix();
|
2003-09-16 23:45:29 +00:00
|
|
|
}
|
|
|
|
|
2003-10-05 05:26:59 +00:00
|
|
|
bool get_matrix(double src[16]) {
|
2004-07-09 15:29:18 +00:00
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glPushMatrix();
|
|
|
|
glGetDoublev(GL_MODELVIEW_MATRIX, src);
|
|
|
|
glPopMatrix();
|
2003-09-17 23:17:09 +00:00
|
|
|
|
2004-07-09 15:29:18 +00:00
|
|
|
return true;
|
2003-09-17 23:17:09 +00:00
|
|
|
}
|
|
|
|
|
2003-10-05 05:26:59 +00:00
|
|
|
bool get_projection(double src[16]) {
|
2004-07-09 15:29:18 +00:00
|
|
|
glMatrixMode(GL_PROJECTION);
|
2003-09-17 23:17:09 +00:00
|
|
|
glPushMatrix();
|
2004-05-15 22:09:26 +00:00
|
|
|
glGetDoublev(GL_PROJECTION_MATRIX, src);
|
2003-09-16 23:45:29 +00:00
|
|
|
glPopMatrix();
|
2003-09-17 23:17:09 +00:00
|
|
|
return true;
|
|
|
|
}
|
2003-09-16 23:45:29 +00:00
|
|
|
|
2003-10-05 05:26:59 +00:00
|
|
|
bool get_viewport(int view[4]) {
|
2003-09-18 23:55:11 +00:00
|
|
|
glMatrixMode(GL_MODELVIEW);
|
2004-05-27 23:46:07 +00:00
|
|
|
glGetIntegerv(GL_VIEWPORT, (GLint*)view);
|
2003-09-16 23:45:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-05-15 22:09:26 +00:00
|
|
|
void get_2d_positions(double x, double y, double z,
|
2003-10-05 05:26:59 +00:00
|
|
|
double model[16], double proj[16], int viewport[4], double proj_pos[3]
|
|
|
|
) {
|
2005-04-25 11:09:40 +00:00
|
|
|
gluProject(x, y, z,model,proj,(GLint*)viewport,&proj_pos[0],&proj_pos[1],&proj_pos[2]);
|
2003-09-16 23:45:29 +00:00
|
|
|
}
|
|
|
|
|
2003-03-27 18:20:25 +00:00
|
|
|
void mode_lines() {
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
glDisable(GL_LIGHT0);
|
|
|
|
}
|
|
|
|
|
2003-01-29 21:13:15 +00:00
|
|
|
static double HuetoRGB(double m1, double m2, double h ) {
|
|
|
|
if( h < 0 ) h += 1.0;
|
|
|
|
if( h > 1 ) h -= 1.0;
|
|
|
|
if( 6.0*h < 1 ) return (m1+(m2-m1)*h*6.0);
|
|
|
|
if( 2.0*h < 1 ) return m2;
|
|
|
|
if( 3.0*h < 2.0 ) return (m1+(m2-m1)*((2.0/3.0)-h)*6.0);
|
|
|
|
return m1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HLStoRGB( double H, double L, double S, COLOR& c) {
|
2004-07-09 15:29:18 +00:00
|
|
|
double m1, m2;
|
|
|
|
|
|
|
|
if(S==0) {
|
2007-08-10 01:51:14 +00:00
|
|
|
c.r=c.g=c.b=(float)L;
|
2004-07-09 15:29:18 +00:00
|
|
|
} else {
|
|
|
|
if(L <=0.5) {
|
|
|
|
m2 = L*(1.0+S);
|
|
|
|
} else {
|
|
|
|
m2 = L+S-L*S;
|
|
|
|
}
|
|
|
|
m1 = 2.0*L-m2;
|
2007-08-10 01:51:14 +00:00
|
|
|
c.r = (float)HuetoRGB(m1,m2,(H+1.0/3.0));
|
|
|
|
c.g = (float)HuetoRGB(m1,m2,H);
|
|
|
|
c.b = (float)HuetoRGB(m1,m2,H-1.0/3.0);
|
2004-07-09 15:29:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline float frand() {
|
2003-01-29 21:13:15 +00:00
|
|
|
return rand()/(float)RAND_MAX;
|
|
|
|
}
|
|
|
|
|
2004-05-27 23:46:07 +00:00
|
|
|
void scale_screen(int iw, int ih) {
|
2007-08-10 01:51:14 +00:00
|
|
|
float aspect_ratio = 4.0f/3.0f;
|
|
|
|
float w=(float)iw, h=(float)ih;
|
|
|
|
float xs, ys;
|
2004-07-09 15:29:18 +00:00
|
|
|
if (h*aspect_ratio > w) {
|
2007-08-10 01:51:14 +00:00
|
|
|
xs = 1.0f;
|
2004-05-27 23:46:07 +00:00
|
|
|
ys = (w/aspect_ratio)/h;
|
2004-07-09 15:29:18 +00:00
|
|
|
} else {
|
2004-05-27 23:46:07 +00:00
|
|
|
xs = (h*aspect_ratio)/w;
|
2007-08-10 01:51:14 +00:00
|
|
|
ys = 1.0f;
|
2004-07-09 15:29:18 +00:00
|
|
|
}
|
2007-08-10 01:51:14 +00:00
|
|
|
glScalef(xs, ys*aspect_ratio, 1.0f);
|
2003-10-16 21:06:10 +00:00
|
|
|
}
|
|
|
|
|
2004-05-27 23:46:07 +00:00
|
|
|
void center_screen(int iw, int ih) {
|
2007-08-10 01:51:14 +00:00
|
|
|
float aspect_ratio = 4.0f/3.0f;
|
|
|
|
float w=(float)iw, h=(float)ih;
|
2004-07-09 15:29:18 +00:00
|
|
|
if (h*aspect_ratio > w) {
|
2007-08-10 01:51:14 +00:00
|
|
|
glTranslatef(0.0f, (h/2.0f-(w/aspect_ratio/2.0f))/h, 0.0f);
|
2004-07-09 15:29:18 +00:00
|
|
|
} else {
|
2007-08-10 01:51:14 +00:00
|
|
|
glTranslatef((w/2.0f-(h*aspect_ratio/2.0f))/w, 0.0f, 0.0f);
|
2004-07-09 15:29:18 +00:00
|
|
|
}
|
2003-10-29 21:46:00 +00:00
|
|
|
}
|
|
|
|
|
2003-01-29 21:13:15 +00:00
|
|
|
void drawSphere(GLfloat* pos, GLfloat rad) {
|
|
|
|
GLUquadricObj* x = gluNewQuadric();
|
|
|
|
glPushMatrix();
|
|
|
|
glTranslatef(pos[0], pos[1], pos[2]);
|
|
|
|
gluSphere(x, rad, 20, 20);
|
|
|
|
gluDeleteQuadric(x);
|
|
|
|
glPopMatrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawCylinder(bool vertical, GLfloat* pos, GLfloat len, GLfloat rad) {
|
|
|
|
GLUquadricObj* x = gluNewQuadric();
|
|
|
|
glPushMatrix();
|
|
|
|
glTranslatef(pos[0], pos[1], pos[2]);
|
|
|
|
if (vertical) {
|
|
|
|
glRotated(-90., 1., 0., 0.);
|
|
|
|
} else {
|
|
|
|
glRotated(90., 0., 1., 0.);
|
|
|
|
}
|
|
|
|
gluCylinder(x, rad, rad, len, 20, 1);
|
|
|
|
gluDeleteQuadric(x);
|
|
|
|
glPopMatrix();
|
|
|
|
}
|
|
|
|
|
2003-10-31 22:37:46 +00:00
|
|
|
void PROGRESS::init(
|
2003-03-27 18:20:25 +00:00
|
|
|
GLfloat* p, GLfloat l, GLfloat r, GLfloat in, GLfloat* c, GLfloat* ic
|
|
|
|
) {
|
|
|
|
memcpy(pos, p, sizeof(pos));
|
|
|
|
len = l;
|
|
|
|
rad = r;
|
|
|
|
inner_rad = in;
|
|
|
|
memcpy(color, c, sizeof(color));
|
|
|
|
memcpy(inner_color, ic, sizeof(inner_color));
|
|
|
|
}
|
|
|
|
|
|
|
|
void PROGRESS::draw(float x) {
|
|
|
|
mode_shaded(inner_color);
|
|
|
|
drawCylinder(false, pos, x*len, inner_rad);
|
|
|
|
mode_shaded(color);
|
|
|
|
drawCylinder(false, pos, len, rad);
|
|
|
|
}
|
|
|
|
|
2003-10-31 22:37:46 +00:00
|
|
|
void PROGRESS_2D::init(
|
2003-10-09 00:21:49 +00:00
|
|
|
GLfloat* p, GLfloat l, GLfloat w, GLfloat in, GLfloat* c, GLfloat* ic
|
|
|
|
) {
|
|
|
|
memcpy(pos, p, sizeof(pos));
|
|
|
|
len = l;
|
|
|
|
width = w;
|
|
|
|
inner_width = in;
|
|
|
|
memcpy(color, c, sizeof(color));
|
|
|
|
memcpy(inner_color, ic, sizeof(inner_color));
|
|
|
|
}
|
|
|
|
|
2003-10-15 00:01:58 +00:00
|
|
|
void PROGRESS_2D::set_pos(float* p) {
|
|
|
|
memcpy(pos, p, sizeof(pos));
|
|
|
|
}
|
|
|
|
|
2003-10-09 00:21:49 +00:00
|
|
|
//pos specifies top left of graph
|
|
|
|
void PROGRESS_2D::draw(float x) {
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
glColor4d(color[0],color[1],color[2],color[3]);
|
|
|
|
glVertex3d(pos[0],pos[1],pos[2]);
|
|
|
|
glVertex3d(pos[0],pos[1]-width,pos[2]);
|
|
|
|
glVertex3d(pos[0]+len,pos[1]-width,pos[2]);
|
|
|
|
glVertex3d(pos[0]+len,pos[1],pos[2]);
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
float dif=width-inner_width;
|
2007-08-10 01:51:14 +00:00
|
|
|
float zoffset=.01f;
|
2003-10-09 00:21:49 +00:00
|
|
|
glBegin(GL_QUADS);
|
|
|
|
glColor4d(inner_color[0],inner_color[1],inner_color[2],inner_color[3]);
|
2003-10-10 23:36:19 +00:00
|
|
|
glVertex3d(pos[0],pos[1]-(dif/2.),pos[2]+zoffset);
|
|
|
|
glVertex3d(pos[0],pos[1]-(inner_width+dif/2.),pos[2]+zoffset);
|
|
|
|
glVertex3d(pos[0]+x*len,pos[1]-(inner_width+dif/2.),pos[2]+zoffset);
|
|
|
|
glVertex3d(pos[0]+x*len,pos[1]-(dif/2.),pos[2]+zoffset);
|
|
|
|
glEnd();
|
|
|
|
#if 0
|
|
|
|
glColor4f(1,1,1,1);
|
|
|
|
glLineWidth(.8f);
|
|
|
|
glEnable(GL_LINE_SMOOTH);
|
|
|
|
glBegin(GL_LINE_STRIP);
|
|
|
|
glVertex3d(pos[0],pos[1],pos[2]);
|
|
|
|
glVertex3d(pos[0],pos[1]-width,pos[2]);
|
|
|
|
glVertex3d(pos[0]+len,pos[1]-width,pos[2]);
|
|
|
|
glVertex3d(pos[0]+len,pos[1],pos[2]);
|
|
|
|
glVertex3d(pos[0],pos[1],pos[2]);
|
2003-10-09 00:21:49 +00:00
|
|
|
glEnd();
|
2003-10-10 23:36:19 +00:00
|
|
|
glDisable(GL_LINE_SMOOTH);
|
|
|
|
#endif
|
2003-10-09 00:21:49 +00:00
|
|
|
}
|
|
|
|
|
2003-10-10 18:00:35 +00:00
|
|
|
|
|
|
|
//----------------- RIBBON_GRAPH ---------------------
|
|
|
|
|
2003-10-31 22:37:46 +00:00
|
|
|
void RIBBON_GRAPH::init(float* p, float* s, float* c, float* tc, float ty) {
|
2003-03-27 18:20:25 +00:00
|
|
|
memcpy(pos, p, sizeof(pos));
|
|
|
|
memcpy(size, s, sizeof(size));
|
|
|
|
memcpy(color, c, sizeof(color));
|
|
|
|
memcpy(tick_color, tc, sizeof(tick_color));
|
2003-10-10 18:00:35 +00:00
|
|
|
tick_yfrac = ty;
|
2003-03-27 18:20:25 +00:00
|
|
|
}
|
|
|
|
|
2003-10-14 23:40:50 +00:00
|
|
|
void RIBBON_GRAPH::set_pos(float* p) {
|
|
|
|
memcpy(pos, p, sizeof(pos));
|
|
|
|
}
|
|
|
|
|
2003-10-31 22:37:46 +00:00
|
|
|
static float yvec[] = {0., 1., 0.};
|
|
|
|
static float xvec[] = {1., 0., 0.};
|
|
|
|
static float xvecneg[] = {-1., 0., 0.};
|
|
|
|
static float zvec[] = {0, 0, 1};
|
2003-03-27 18:20:25 +00:00
|
|
|
|
2003-10-14 20:37:02 +00:00
|
|
|
// draw XZ rect from i to i+1, with height data[i]
|
2003-03-27 18:20:25 +00:00
|
|
|
//
|
2003-10-10 18:00:35 +00:00
|
|
|
void RIBBON_GRAPH::draw_x(int i) {
|
2003-03-27 18:20:25 +00:00
|
|
|
GLfloat pt[3];
|
2007-08-10 01:51:14 +00:00
|
|
|
float r1 = i/(float)len;
|
|
|
|
float r2 = (i+1)/(float)len;
|
2003-03-27 18:20:25 +00:00
|
|
|
|
|
|
|
glNormal3fv(yvec);
|
|
|
|
pt[0] = pos[0] + r1*size[0];
|
|
|
|
pt[1] = pos[1] + data[i]*size[1]/dmax;
|
|
|
|
pt[2] = pos[2];
|
|
|
|
glVertex3fv(pt);
|
|
|
|
pt[0] = pos[0] + r2*size[0];
|
|
|
|
glVertex3fv(pt);
|
|
|
|
pt[2] = pos[2] + size[2];
|
|
|
|
glVertex3fv(pt);
|
|
|
|
pt[0] = pos[0] + r1*size[0];
|
|
|
|
glVertex3fv(pt);
|
2003-10-14 20:37:02 +00:00
|
|
|
|
|
|
|
// also draw XY rect
|
2003-03-30 23:27:22 +00:00
|
|
|
glNormal3fv(zvec);
|
|
|
|
pt[0] = pos[0] + r1*size[0];
|
|
|
|
pt[1] = pos[1] + data[i]*size[1]/dmax;
|
|
|
|
pt[2] = pos[2]+size[2];
|
|
|
|
glVertex3fv(pt);
|
|
|
|
pt[1] = pos[1];
|
|
|
|
glVertex3fv(pt);
|
|
|
|
pt[0] = pos[0] + r2*size[0];
|
|
|
|
glVertex3fv(pt);
|
|
|
|
pt[1] = pos[1] + data[i]*size[1]/dmax;
|
|
|
|
glVertex3fv(pt);
|
2003-03-27 18:20:25 +00:00
|
|
|
}
|
|
|
|
|
2003-10-14 20:37:02 +00:00
|
|
|
// draw YZ rect at position i, with height from data[i-1] to data[i]
|
2003-03-27 18:20:25 +00:00
|
|
|
//
|
2003-10-10 18:00:35 +00:00
|
|
|
void RIBBON_GRAPH::draw_y(int i) {
|
2003-03-27 18:20:25 +00:00
|
|
|
GLfloat pt[3];
|
2007-08-10 01:51:14 +00:00
|
|
|
float r1 = i/(float)len;
|
2003-03-27 18:20:25 +00:00
|
|
|
|
|
|
|
(data[i]>data[i-1])?glNormal3fv(xvecneg):glNormal3fv(xvec);
|
|
|
|
pt[0] = pos[0] + r1*size[0];
|
|
|
|
pt[1] = pos[1] + data[i-1]*size[1]/dmax;
|
|
|
|
pt[2] = pos[2];
|
|
|
|
glVertex3fv(pt);
|
|
|
|
pt[1] = pos[1] + data[i]*size[1]/dmax;
|
|
|
|
glVertex3fv(pt);
|
|
|
|
pt[2] = pos[2] + size[2];
|
|
|
|
glVertex3fv(pt);
|
|
|
|
pt[1] = pos[1] + data[i-1]*size[1]/dmax;
|
|
|
|
glVertex3fv(pt);
|
|
|
|
}
|
|
|
|
|
2003-10-10 18:00:35 +00:00
|
|
|
void RIBBON_GRAPH::draw_tick(int i) {
|
|
|
|
GLfloat pt[3];
|
2007-08-10 01:51:14 +00:00
|
|
|
float r1 = ticks[i]/(float)len;
|
2003-10-10 18:00:35 +00:00
|
|
|
|
|
|
|
pt[0] = pos[0] + r1*size[0];
|
2007-08-10 01:51:14 +00:00
|
|
|
pt[1] = pos[1] + (1.0f-tick_yfrac)*size[1];
|
2003-10-10 18:00:35 +00:00
|
|
|
pt[2] = pos[2];
|
|
|
|
glVertex3fv(pt);
|
2007-08-10 01:51:14 +00:00
|
|
|
pt[1] = pos[1] + size[1]*1.1f;
|
2003-10-10 18:00:35 +00:00
|
|
|
glVertex3fv(pt);
|
|
|
|
pt[2] = pos[2] + size[2];
|
|
|
|
glVertex3fv(pt);
|
2007-08-10 01:51:14 +00:00
|
|
|
pt[1] = pos[1] + (1.0f-tick_yfrac)*size[1];
|
2003-10-10 18:00:35 +00:00
|
|
|
glVertex3fv(pt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RIBBON_GRAPH::draw(float* d, int ln, bool with_ticks) {
|
2003-03-27 18:20:25 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
data = d;
|
|
|
|
len = ln;
|
|
|
|
dmax = 0;
|
|
|
|
for (i=0; i<len; i++) {
|
|
|
|
if (data[i] > dmax) dmax = data[i];
|
|
|
|
}
|
2003-10-10 04:01:13 +00:00
|
|
|
if (dmax ==0) dmax = 1;
|
2003-03-27 18:20:25 +00:00
|
|
|
|
|
|
|
mode_shaded(color);
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
draw_x(0);
|
|
|
|
for (i=1; i<len-1; i++) {
|
|
|
|
draw_y(i);
|
|
|
|
draw_x(i);
|
|
|
|
}
|
|
|
|
draw_x(len-1);
|
2003-10-10 18:00:35 +00:00
|
|
|
if (with_ticks) {
|
2003-10-13 00:41:02 +00:00
|
|
|
mode_shaded(tick_color);
|
2003-10-10 18:00:35 +00:00
|
|
|
for (i=0; i<3; i++) {
|
|
|
|
draw_tick(i);
|
|
|
|
}
|
|
|
|
}
|
2003-03-27 18:20:25 +00:00
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
2003-10-10 18:00:35 +00:00
|
|
|
void RIBBON_GRAPH::add_tick(float x, int index) {
|
|
|
|
ticks[index] = x;
|
2003-03-27 18:20:25 +00:00
|
|
|
}
|
2003-03-28 18:30:39 +00:00
|
|
|
|
|
|
|
|
2003-11-02 22:51:49 +00:00
|
|
|
void normalize(float a[3]) {
|
2003-10-14 22:30:52 +00:00
|
|
|
float mag = sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]);
|
|
|
|
if(mag!=0) {
|
|
|
|
a[0]/=mag;
|
|
|
|
a[1]/=mag;
|
2003-10-15 19:08:51 +00:00
|
|
|
a[2]/=mag;
|
2003-11-02 22:51:49 +00:00
|
|
|
} else {
|
2003-10-14 22:30:52 +00:00
|
|
|
a[0]=0;
|
|
|
|
a[1]=0;
|
|
|
|
a[2]=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-02 22:51:49 +00:00
|
|
|
float dotProd(float a, float b, float c, float x, float y, float z) {
|
2003-10-14 00:16:38 +00:00
|
|
|
return(a*x+b*y+c*z);
|
|
|
|
}
|
|
|
|
|
2003-11-02 22:51:49 +00:00
|
|
|
void crossProd(float a[3], float b[3], float out[3]) {
|
2003-10-14 22:30:52 +00:00
|
|
|
out[0] = a[1]*b[2] - a[2]*b[1];
|
|
|
|
out[1] = a[2]*b[0] - a[0]*b[2];
|
|
|
|
out[2] = a[0]*b[1] - a[1]*b[0];
|
|
|
|
|
|
|
|
normalize(out);
|
|
|
|
}
|
2003-10-14 00:16:38 +00:00
|
|
|
|
2004-05-15 22:09:26 +00:00
|
|
|
// ------------ STARFIELD STUFF --------------------
|
|
|
|
//
|
2003-10-31 22:37:46 +00:00
|
|
|
STARFIELD::STARFIELD() {
|
|
|
|
stars = NULL;
|
2004-05-15 22:09:26 +00:00
|
|
|
zmax = 8;
|
|
|
|
zmaxinv = 1/zmax;
|
2003-10-31 22:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2003-10-10 18:00:35 +00:00
|
|
|
//
|
2004-07-09 15:29:18 +00:00
|
|
|
void STARFIELD::build_stars(int sz, float sp) {
|
2004-05-15 22:09:26 +00:00
|
|
|
int i;
|
2003-10-16 21:06:10 +00:00
|
|
|
|
|
|
|
speed=sp;
|
2004-05-15 22:09:26 +00:00
|
|
|
nstars=sz;
|
2003-10-10 18:00:35 +00:00
|
|
|
|
2003-10-31 22:37:46 +00:00
|
|
|
if (stars) free(stars);
|
2004-05-15 22:09:26 +00:00
|
|
|
stars = (STAR*)calloc(sizeof(STAR), (long unsigned int)nstars);
|
2007-07-13 20:18:46 +00:00
|
|
|
if (!stars) {
|
|
|
|
fprintf(stderr, "out of mem in STARFIELD::build_stars");
|
|
|
|
sz = 0;
|
|
|
|
return;
|
|
|
|
}
|
2003-10-14 22:30:52 +00:00
|
|
|
|
2004-07-09 15:29:18 +00:00
|
|
|
for (i=0; i<nstars; i++) {
|
2004-05-15 22:09:26 +00:00
|
|
|
replace_star(i);
|
2004-07-09 15:29:18 +00:00
|
|
|
}
|
2003-09-16 23:45:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-15 22:09:26 +00:00
|
|
|
// draw the starfield,
|
|
|
|
// move stars
|
|
|
|
//
|
2003-11-02 22:51:49 +00:00
|
|
|
void STARFIELD::update_stars(float dt) {
|
2004-05-15 22:09:26 +00:00
|
|
|
int i;
|
2004-07-09 15:29:18 +00:00
|
|
|
|
2004-05-15 22:37:27 +00:00
|
|
|
mode_ortho();
|
|
|
|
mode_lines();
|
2004-07-09 15:29:18 +00:00
|
|
|
glColor4f(1.0, 1.0, 1.0, 1.0);
|
2004-05-15 22:09:26 +00:00
|
|
|
for (i=0; i<nstars; i++) {
|
2004-05-19 23:16:19 +00:00
|
|
|
stars[i].z -= speed*dt/500;
|
2004-05-15 22:09:26 +00:00
|
|
|
if (stars[i].z < 0) stars[i].z += zmax;
|
|
|
|
if (stars[i].z > zmax) stars[i].z -= zmax;
|
2003-10-09 00:21:49 +00:00
|
|
|
|
2004-05-15 22:09:26 +00:00
|
|
|
double x = stars[i].x/stars[i].z;
|
|
|
|
double y = stars[i].y/stars[i].z;
|
|
|
|
x = (x*zmax+1)/2;
|
|
|
|
y = (y*zmax+1)/2;
|
2003-10-15 19:08:51 +00:00
|
|
|
|
2004-05-15 22:09:26 +00:00
|
|
|
if (stars[i].z > zmax/2) glPointSize(1);
|
|
|
|
else glPointSize(2);
|
2003-09-16 23:45:29 +00:00
|
|
|
glBegin(GL_POINTS);
|
2007-08-10 01:51:14 +00:00
|
|
|
glVertex2f((GLfloat)x, (GLfloat)y);
|
2003-09-16 23:45:29 +00:00
|
|
|
glEnd();
|
2003-10-15 19:08:51 +00:00
|
|
|
}
|
2004-05-15 22:37:27 +00:00
|
|
|
ortho_done();
|
2003-09-16 23:45:29 +00:00
|
|
|
}
|
|
|
|
|
2004-05-15 22:09:26 +00:00
|
|
|
void STARFIELD::replace_star(int i) {
|
|
|
|
stars[i].x = frand()*2-1;
|
|
|
|
stars[i].y = frand()*2-1;
|
|
|
|
stars[i].z = frand()*zmax;
|
2003-09-16 23:45:29 +00:00
|
|
|
}
|
|
|
|
|
2003-10-10 18:00:35 +00:00
|
|
|
// ------------ TEXTURE STUFF --------------------
|
|
|
|
//
|
|
|
|
|
2003-10-31 22:37:46 +00:00
|
|
|
struct tImageJPG {
|
|
|
|
int rowSpan;
|
|
|
|
int sizeX;
|
|
|
|
int sizeY;
|
|
|
|
unsigned char *data;
|
|
|
|
};
|
|
|
|
|
2003-11-02 22:51:49 +00:00
|
|
|
struct Vertex {
|
2003-10-10 18:00:35 +00:00
|
|
|
float tu, tv;
|
|
|
|
float x, y, z;
|
|
|
|
};
|
|
|
|
|
2003-11-02 22:51:49 +00:00
|
|
|
Vertex g_quadVertices[] = {
|
2003-10-10 18:00:35 +00:00
|
|
|
{ 0.0f,0.0f, -1.0f,-1.0f, 0.0f },
|
|
|
|
{ 1.0f,0.0f, 1.0f,-1.0f, 0.0f },
|
|
|
|
{ 1.0f,1.0f, 1.0f, 1.0f, 0.0f },
|
|
|
|
{ 0.0f,1.0f, -1.0f, 1.0f, 0.0f }
|
|
|
|
};
|
|
|
|
|
2003-10-06 16:10:33 +00:00
|
|
|
// read a PPM file
|
|
|
|
// to generate PPM from JPEG:
|
|
|
|
// mogrify -format ppm foo.jpg
|
|
|
|
// or xv foo.jpg; right click on image, choose PPM
|
|
|
|
//
|
2004-07-15 20:49:27 +00:00
|
|
|
int read_ppm_file(const char* name, int& w, int& h, unsigned char** arrayp) {
|
2003-10-06 16:10:33 +00:00
|
|
|
FILE* f;
|
|
|
|
char buf[256];
|
|
|
|
char img_type;
|
|
|
|
unsigned char* array;
|
|
|
|
int i;
|
|
|
|
|
2006-04-28 03:36:56 +00:00
|
|
|
f = boinc_fopen(name, "rb");
|
2003-10-06 16:10:33 +00:00
|
|
|
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);
|
2007-07-10 23:42:05 +00:00
|
|
|
if (!array) return -1;
|
2003-10-06 16:10:33 +00:00
|
|
|
switch(img_type) { // TODO: pad image dimension to power of 2
|
|
|
|
case '3':
|
|
|
|
for (i=0; i<w*h*3; i++) {
|
2005-02-16 23:30:29 +00:00
|
|
|
int x;
|
|
|
|
fscanf(f, "%d", &x);
|
|
|
|
array[i] = x;
|
2003-10-06 16:10:33 +00:00
|
|
|
}
|
|
|
|
case '6':
|
|
|
|
fread(array, 3, w*h, f);
|
|
|
|
break;
|
|
|
|
}
|
2006-04-25 21:24:26 +00:00
|
|
|
|
2003-10-06 16:10:33 +00:00
|
|
|
*arrayp = array;
|
2006-04-25 21:24:26 +00:00
|
|
|
fclose(f);
|
2003-10-06 16:10:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// draw a texture at a given position and size.
|
|
|
|
// Change size if needed so aspect ratio of texture isn't changed
|
|
|
|
//
|
2003-10-09 06:00:05 +00:00
|
|
|
void TEXTURE_DESC::draw(float* p, float* size, int xalign, int yalign) {
|
2003-10-06 16:10:33 +00:00
|
|
|
float pos[3];
|
2007-08-10 01:51:14 +00:00
|
|
|
float tratio, sratio, new_size;
|
2003-10-06 16:10:33 +00:00
|
|
|
memcpy(pos, p, sizeof(pos));
|
|
|
|
glColor4f(1.,1.,1.,1.);
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
2003-10-09 06:00:05 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, id);
|
2003-10-06 16:10:33 +00:00
|
|
|
|
2007-08-10 01:51:14 +00:00
|
|
|
tratio = static_cast<float>(xsize/ysize);
|
2003-10-06 16:10:33 +00:00
|
|
|
sratio = size[0]/size[1];
|
|
|
|
|
|
|
|
if (tratio > sratio) { // texture is wider than space
|
|
|
|
new_size = size[0]/tratio;
|
2007-08-10 01:51:14 +00:00
|
|
|
if (yalign == ALIGN_CENTER) pos[1] += (size[1]-new_size)/2.0f;
|
2003-10-09 06:00:05 +00:00
|
|
|
if (yalign == ALIGN_TOP) pos[1] += size[1]-new_size;
|
2003-10-06 16:10:33 +00:00
|
|
|
size[1] = new_size;
|
|
|
|
}
|
|
|
|
if (sratio > tratio) { // space is wider than texture
|
|
|
|
new_size = size[1]*tratio;
|
2007-08-10 01:51:14 +00:00
|
|
|
if (xalign == ALIGN_CENTER) pos[0] += (size[0]-new_size)/2.0f;
|
2003-10-09 06:00:05 +00:00
|
|
|
if (xalign == ALIGN_TOP) pos[0] += size[0]-new_size;
|
2003-10-06 16:10:33 +00:00
|
|
|
size[0] = new_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
glBegin(GL_QUADS);
|
2003-10-15 19:08:51 +00:00
|
|
|
glTexCoord2f(0., 1.);
|
2003-10-06 16:10:33 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2006-03-30 20:54:34 +00:00
|
|
|
#if 0
|
|
|
|
void printdata(const char* filename, int x, int y, unsigned char* data) {
|
|
|
|
FILE* bmpfile = boinc_fopen(filename,"w");
|
|
|
|
fprintf(bmpfile,"%i,%i\n",x,y);
|
|
|
|
for(int i=0;i<y;i++) {
|
|
|
|
for(int c=0;c<8;c++) {
|
|
|
|
fprintf(bmpfile,"%d ",data[x*i+c]);
|
|
|
|
}
|
|
|
|
fprintf(bmpfile,"\n");
|
|
|
|
}
|
|
|
|
fclose(bmpfile);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SANS_JPEGLIB
|
2003-10-15 19:08:51 +00:00
|
|
|
void DecodeJPG(jpeg_decompress_struct* cinfo, tImageJPG *pImageData) {
|
2003-09-17 23:17:09 +00:00
|
|
|
jpeg_read_header(cinfo, TRUE);
|
2003-10-15 19:08:51 +00:00
|
|
|
jpeg_start_decompress(cinfo);
|
2005-02-16 23:30:29 +00:00
|
|
|
//int rem = cinfo->output_width%4;
|
2003-10-10 23:36:19 +00:00
|
|
|
pImageData->rowSpan = cinfo->output_width * cinfo->output_components;
|
|
|
|
pImageData->sizeX = cinfo->output_width;
|
|
|
|
pImageData->sizeY = cinfo->output_height;
|
2003-09-17 23:17:09 +00:00
|
|
|
|
|
|
|
pImageData->data = new unsigned char[pImageData->rowSpan * pImageData->sizeY];
|
2003-10-15 19:08:51 +00:00
|
|
|
|
2003-09-17 23:17:09 +00:00
|
|
|
unsigned char** rowPtr = new unsigned char*[pImageData->sizeY];
|
2003-10-15 19:08:51 +00:00
|
|
|
for (int i = 0; i < pImageData->sizeY; i++)
|
2003-09-17 23:17:09 +00:00
|
|
|
rowPtr[i] = &(pImageData->data[i*pImageData->rowSpan]);
|
2003-10-15 19:08:51 +00:00
|
|
|
|
2003-09-17 23:17:09 +00:00
|
|
|
int rowsRead = 0;
|
2003-10-10 23:36:19 +00:00
|
|
|
|
2003-10-05 06:03:08 +00:00
|
|
|
while (cinfo->output_scanline < cinfo->output_height) {
|
2003-10-15 19:08:51 +00:00
|
|
|
rowsRead += jpeg_read_scanlines(cinfo, &rowPtr[rowsRead], cinfo->output_height - rowsRead);
|
2003-09-17 23:17:09 +00:00
|
|
|
}
|
|
|
|
delete [] rowPtr;
|
|
|
|
jpeg_finish_decompress(cinfo);
|
|
|
|
}
|
|
|
|
|
2003-10-09 21:25:39 +00:00
|
|
|
struct my_error_mgr {
|
|
|
|
struct jpeg_error_mgr pub;
|
|
|
|
jmp_buf setjmp_buffer;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct my_error_mgr * my_error_ptr;
|
|
|
|
|
|
|
|
METHODDEF(void)
|
|
|
|
my_error_exit (j_common_ptr cinfo)
|
|
|
|
{
|
|
|
|
my_error_ptr myerr = (my_error_ptr) cinfo->err;
|
|
|
|
(*cinfo->err->output_message) (cinfo);
|
|
|
|
longjmp(myerr->setjmp_buffer, 1);
|
|
|
|
}
|
|
|
|
|
2003-10-15 19:08:51 +00:00
|
|
|
tImageJPG *LoadJPG(const char *filename) {
|
2003-09-17 23:17:09 +00:00
|
|
|
struct jpeg_decompress_struct cinfo;
|
|
|
|
tImageJPG *pImageData = NULL;
|
|
|
|
FILE *pFile;
|
2006-05-11 18:28:35 +00:00
|
|
|
#if defined(HAVE_ALLOCA) || defined(_WIN32)
|
|
|
|
alloca(16); // Force a frame pointer even when compiled with
|
|
|
|
// -fomit-frame-pointer
|
|
|
|
#endif
|
2006-04-28 03:36:56 +00:00
|
|
|
|
|
|
|
if((pFile = boinc_fopen(filename, "rb")) == NULL) {
|
2003-10-03 00:44:25 +00:00
|
|
|
fprintf(stderr,"Unable to load JPG File!");
|
2003-09-17 23:17:09 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2003-10-09 21:25:39 +00:00
|
|
|
|
|
|
|
struct my_error_mgr jerr;
|
|
|
|
cinfo.err = jpeg_std_error(&jerr.pub);
|
2003-10-10 23:36:19 +00:00
|
|
|
jerr.pub.error_exit = my_error_exit;
|
2003-10-09 21:25:39 +00:00
|
|
|
if (setjmp(jerr.setjmp_buffer)) {
|
|
|
|
jpeg_destroy_decompress(&cinfo);
|
|
|
|
fclose(pFile);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-10-15 19:08:51 +00:00
|
|
|
jpeg_create_decompress(&cinfo);
|
|
|
|
jpeg_stdio_src(&cinfo, pFile);
|
|
|
|
pImageData = (tImageJPG*)malloc(sizeof(tImageJPG));
|
2007-07-13 20:18:46 +00:00
|
|
|
if (!pImageData) {
|
|
|
|
jpeg_destroy_decompress(&cinfo);
|
|
|
|
fclose(pFile);
|
|
|
|
fprintf(stderr, "out of mem in LoadJPG");
|
|
|
|
return 0;
|
|
|
|
}
|
2003-10-15 19:08:51 +00:00
|
|
|
DecodeJPG(&cinfo, pImageData);
|
|
|
|
jpeg_destroy_decompress(&cinfo);
|
|
|
|
fclose(pFile);
|
2003-09-17 23:17:09 +00:00
|
|
|
return pImageData;
|
|
|
|
}
|
|
|
|
|
2004-07-09 15:29:18 +00:00
|
|
|
int TEXTURE_DESC::CreateTextureJPG(const char* strFileName) {
|
2003-10-15 19:08:51 +00:00
|
|
|
if(!strFileName) return -1;
|
|
|
|
tImageJPG *pImage = LoadJPG(strFileName); // Load the image and store the data
|
|
|
|
if(pImage == NULL) return -1;
|
2003-10-10 23:36:19 +00:00
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
|
2003-11-23 00:58:54 +00:00
|
|
|
glGenTextures(1, (GLuint*)&id);
|
2003-10-15 19:08:51 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, id);
|
|
|
|
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pImage->sizeX, pImage->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pImage->data);
|
2003-09-17 23:17:09 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
|
2003-10-15 19:08:51 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
|
2003-10-09 06:00:05 +00:00
|
|
|
xsize = pImage->sizeX;
|
|
|
|
ysize = pImage->sizeY;
|
2003-10-15 19:08:51 +00:00
|
|
|
|
2003-10-05 06:03:08 +00:00
|
|
|
if (pImage) {
|
|
|
|
if (pImage->data) {
|
2003-10-15 19:08:51 +00:00
|
|
|
free(pImage->data);
|
2003-09-17 23:17:09 +00:00
|
|
|
}
|
2003-10-15 19:08:51 +00:00
|
|
|
free(pImage);
|
2003-09-17 23:17:09 +00:00
|
|
|
}
|
2003-10-06 16:10:33 +00:00
|
|
|
return 0;
|
2003-09-17 23:17:09 +00:00
|
|
|
}
|
2006-03-30 20:54:34 +00:00
|
|
|
#endif
|
2003-09-17 23:17:09 +00:00
|
|
|
|
2003-10-02 01:13:43 +00:00
|
|
|
#ifdef _WIN32
|
2005-03-10 22:05:42 +00:00
|
|
|
int TEXTURE_DESC::CreateTextureBMP(const char* strFileName) {
|
2003-10-15 19:08:51 +00:00
|
|
|
DIB_BITMAP image;
|
2003-10-05 06:03:08 +00:00
|
|
|
if(image.loadBMP(strFileName) == false) {
|
2003-10-06 16:10:33 +00:00
|
|
|
return -1;
|
2003-10-05 06:03:08 +00:00
|
|
|
}
|
2003-10-10 23:36:19 +00:00
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT,4);
|
2003-10-15 19:08:51 +00:00
|
|
|
glGenTextures(1, &id);
|
2003-10-09 06:00:05 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, id);
|
2003-10-15 19:08:51 +00:00
|
|
|
gluBuild2DMipmaps(GL_TEXTURE_2D, image.get_channels(), image.get_width(),
|
|
|
|
image.get_height(), GL_BGR_EXT, GL_UNSIGNED_BYTE,
|
2003-10-05 06:03:08 +00:00
|
|
|
image.getLinePtr(0)
|
|
|
|
);
|
2003-09-17 23:17:09 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
|
2003-10-15 19:08:51 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
|
2003-10-09 06:00:05 +00:00
|
|
|
xsize = image.get_width();
|
|
|
|
ysize = image.get_height();
|
2003-10-06 16:10:33 +00:00
|
|
|
return 0;
|
2003-09-17 23:17:09 +00:00
|
|
|
}
|
2005-08-03 07:04:37 +00:00
|
|
|
#endif // _WIN32
|
2003-10-05 06:03:08 +00:00
|
|
|
|
2005-08-03 07:04:37 +00:00
|
|
|
|
2004-07-09 15:29:18 +00:00
|
|
|
int TEXTURE_DESC::CreateTexturePPM(const char* strFileName) {
|
2003-09-17 23:17:09 +00:00
|
|
|
unsigned char* pixels;
|
2003-10-15 19:08:51 +00:00
|
|
|
int width, height, retval;
|
2003-10-06 16:10:33 +00:00
|
|
|
retval = read_ppm_file(strFileName, width, height, &pixels);
|
2003-10-15 19:08:51 +00:00
|
|
|
if (retval) return retval;
|
2003-10-10 23:36:19 +00:00
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
|
2005-11-04 03:14:33 +00:00
|
|
|
glGenTextures(1, (GLuint*)&id);
|
2003-10-15 19:08:51 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, id);
|
2003-09-17 23:17:09 +00:00
|
|
|
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);
|
2003-10-15 19:08:51 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
|
2003-10-09 06:00:05 +00:00
|
|
|
xsize = width;
|
|
|
|
ysize = height;
|
2006-04-25 21:24:26 +00:00
|
|
|
if (pixels) {
|
|
|
|
free(pixels);
|
|
|
|
}
|
2003-10-06 16:10:33 +00:00
|
|
|
return 0;
|
2003-09-17 23:17:09 +00:00
|
|
|
}
|
2003-09-16 23:45:29 +00:00
|
|
|
|
2005-07-19 18:47:51 +00:00
|
|
|
|
|
|
|
int TEXTURE_DESC::CreateTextureRGB(const char* strFileName) {
|
|
|
|
if(!strFileName) return -1;
|
|
|
|
int sizeX;
|
|
|
|
int sizeY;
|
|
|
|
int sizeZ;
|
|
|
|
// Load the image and store the data
|
|
|
|
unsigned int *pImage = read_rgb_texture(strFileName,&sizeX,&sizeY,&sizeZ);
|
|
|
|
if(pImage == NULL) return -1;
|
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
|
|
|
|
glGenTextures(1, (GLuint*)&id);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, id);
|
|
|
|
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, sizeX, sizeY, GL_RGBA, GL_UNSIGNED_BYTE, pImage);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
|
|
|
|
if (pImage)
|
|
|
|
free(pImage);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-08-03 07:04:37 +00:00
|
|
|
#ifdef _WIN32
|
2004-07-09 15:29:18 +00:00
|
|
|
int TEXTURE_DESC::CreateTextureTGA(const char* strFileName) {
|
2003-09-23 19:53:30 +00:00
|
|
|
if(!strFileName) // Return from the function if no file name was passed in
|
2003-10-06 16:10:33 +00:00
|
|
|
return -1;
|
2003-09-23 19:53:30 +00:00
|
|
|
|
|
|
|
tImageTGA *pImage = LoadTGA(strFileName); // Load the image and store the data
|
2003-10-05 06:03:08 +00:00
|
|
|
if(pImage == NULL) {
|
2003-10-06 16:10:33 +00:00
|
|
|
return -1;
|
2003-10-05 06:03:08 +00:00
|
|
|
}
|
2003-10-10 23:36:19 +00:00
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
|
2003-10-09 06:00:05 +00:00
|
|
|
glGenTextures(1, &id);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, id);
|
2003-09-23 19:53:30 +00:00
|
|
|
int textureType = GL_RGB;
|
2003-10-05 06:03:08 +00:00
|
|
|
if(pImage->channels == 4) {
|
2003-10-15 19:08:51 +00:00
|
|
|
textureType = GL_RGBA;
|
|
|
|
}
|
|
|
|
gluBuild2DMipmaps(GL_TEXTURE_2D, pImage->channels, pImage->sizeX,
|
2003-10-10 23:36:19 +00:00
|
|
|
pImage->sizeY, textureType, GL_UNSIGNED_BYTE, pImage->data);
|
2003-09-23 22:29:21 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
|
2003-10-15 19:08:51 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
|
2003-10-09 06:00:05 +00:00
|
|
|
xsize = pImage->sizeX;
|
|
|
|
ysize = pImage->sizeY;
|
2003-09-23 19:53:30 +00:00
|
|
|
|
2003-10-05 06:03:08 +00:00
|
|
|
if (pImage) { // If we loaded the image
|
|
|
|
if (pImage->data) { // If there is texture data
|
2003-09-23 19:53:30 +00:00
|
|
|
delete[] pImage->data; // Free the texture data, we don't need it anymore
|
|
|
|
}
|
|
|
|
free(pImage); // Free the image structure
|
|
|
|
}
|
2003-10-06 16:10:33 +00:00
|
|
|
return 0;
|
2003-09-23 19:53:30 +00:00
|
|
|
}
|
2005-08-03 07:04:37 +00:00
|
|
|
#endif // _WIN32
|
|
|
|
|
2003-09-23 19:53:30 +00:00
|
|
|
|
2004-07-09 15:29:18 +00:00
|
|
|
int TEXTURE_DESC::load_image_file(const char* filename) {
|
2003-10-09 06:00:05 +00:00
|
|
|
int retval;
|
|
|
|
FILE* f;
|
2006-04-28 03:36:56 +00:00
|
|
|
f = boinc_fopen(filename, "r");
|
2003-10-09 06:00:05 +00:00
|
|
|
if (!f) goto done;
|
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
// for now, just try all the image types in turn
|
|
|
|
|
|
|
|
present = true;
|
2006-03-30 20:54:34 +00:00
|
|
|
#ifndef SANS_JPEGLIB
|
2003-10-09 21:25:39 +00:00
|
|
|
retval = CreateTextureJPG(filename);
|
2008-03-13 21:18:04 +00:00
|
|
|
if (!retval) {
|
|
|
|
fprintf(stderr, "Successfully loaded '%s'.\n", filename);
|
|
|
|
return 0;
|
|
|
|
}
|
2006-03-30 20:54:34 +00:00
|
|
|
#endif
|
2005-03-10 22:05:42 +00:00
|
|
|
#ifdef _WIN32
|
2003-10-15 19:08:51 +00:00
|
|
|
retval = CreateTexturePPM(filename);
|
2008-03-13 21:18:04 +00:00
|
|
|
if (!retval) {
|
|
|
|
fprintf(stderr, "Successfully loaded '%s'.\n", filename);
|
|
|
|
return 0;
|
|
|
|
}
|
2003-10-09 06:00:05 +00:00
|
|
|
retval = CreateTextureBMP(filename);
|
2008-03-13 21:18:04 +00:00
|
|
|
if (!retval) {
|
|
|
|
fprintf(stderr, "Successfully loaded '%s'.\n", filename);
|
|
|
|
return 0;
|
|
|
|
}
|
2003-10-09 06:00:05 +00:00
|
|
|
retval = CreateTextureTGA(filename);
|
2008-03-13 21:18:04 +00:00
|
|
|
if (!retval) {
|
|
|
|
fprintf(stderr, "Successfully loaded '%s'.\n", filename);
|
|
|
|
return 0;
|
|
|
|
}
|
2005-03-10 22:05:42 +00:00
|
|
|
#endif
|
2005-07-19 18:47:51 +00:00
|
|
|
retval = CreateTextureRGB(filename);
|
2008-03-13 21:18:04 +00:00
|
|
|
if (!retval) {
|
|
|
|
fprintf(stderr, "Successfully loaded '%s'.\n", filename);
|
|
|
|
return 0;
|
|
|
|
}
|
2003-10-09 21:25:39 +00:00
|
|
|
|
2003-10-09 06:00:05 +00:00
|
|
|
done:
|
|
|
|
present = false;
|
2008-03-13 21:18:04 +00:00
|
|
|
fprintf(stderr, "Failed to load '%s'.\n", filename);
|
2003-10-06 16:10:33 +00:00
|
|
|
return -1;
|
2003-10-05 05:26:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-18 23:55:11 +00:00
|
|
|
//text
|
2003-10-10 23:36:19 +00:00
|
|
|
unsigned int listBase;
|
2003-09-18 23:55:11 +00:00
|
|
|
|
2004-07-09 15:29:18 +00:00
|
|
|
void print_text(const char* string) {
|
2003-10-15 19:08:51 +00:00
|
|
|
if(string==NULL) return;
|
2003-10-10 23:36:19 +00:00
|
|
|
glPushAttrib(GL_LIST_BIT);
|
2003-10-15 19:08:51 +00:00
|
|
|
glListBase(listBase);
|
2004-03-06 09:45:25 +00:00
|
|
|
glCallLists((GLsizei)strlen(string), GL_UNSIGNED_BYTE, string);
|
2003-10-15 19:08:51 +00:00
|
|
|
glPopAttrib();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_12bffca9ae = "$Id$";
|