|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tgl.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tconvert.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tofflinegl.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "trop.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "timage_io.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tcurves.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef __sgi
|
|
Shinya Kitaoka |
9f5a1b |
#ifdef _WIN32
|
|
Shinya Kitaoka |
d4642c |
#include <cstdlib></cstdlib>
|
|
Toshihiro Shimizu |
890ddd |
#include <gl glut.h=""></gl>
|
|
Campbell Barton |
107701 |
#elif defined(LINUX)
|
|
Campbell Barton |
107701 |
#include <gl glut.h=""></gl>
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#include <glut glut.h=""></glut>
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Campbell Barton |
107701 |
#if defined(MACOSX) || defined(LINUX)
|
|
Toshihiro Shimizu |
890ddd |
#include <qglcontext></qglcontext>
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//#include "tthread.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#undef SCALE_BY_GLU
|
|
Toshihiro Shimizu |
890ddd |
//#undef NEW_DRAW_TEXT
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// GLUquadric* localDisk=0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
Find the number of slices in function of radius size.
|
|
Toshihiro Shimizu |
890ddd |
\par radius of circle
|
|
Toshihiro Shimizu |
890ddd |
\par size of pixel
|
|
Toshihiro Shimizu |
890ddd |
\ret number of division to obtain a circle
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
int computeSlices(double radius, double pixelSize = 1.0)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (radius < 0)
|
|
Toshihiro Shimizu |
890ddd |
return 2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double thetaStep;
|
|
Toshihiro Shimizu |
890ddd |
double temp = pixelSize * 0.5 / radius;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (fabs(1.0 - temp) <= 1)
|
|
Toshihiro Shimizu |
890ddd |
thetaStep = acos(1.0 - temp);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Shinya Kitaoka |
ee259f |
thetaStep = M_PI_4;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(thetaStep != 0.0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
ee259f |
int numberOfSlices = (int)(M_2PI / thetaStep);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return numberOfSlices != 0 ? numberOfSlices : 2;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} // end of unnamed namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double tglGetPixelSize2()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double mat[16];
|
|
Toshihiro Shimizu |
890ddd |
glMatrixMode(GL_MODELVIEW);
|
|
Toshihiro Shimizu |
890ddd |
glGetDoublev(GL_MODELVIEW_MATRIX, mat);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double det = fabs(mat[0] * mat[5] - mat[1] * mat[4]);
|
|
Toshihiro Shimizu |
890ddd |
if (det < TConsts::epsilon)
|
|
Toshihiro Shimizu |
890ddd |
det = TConsts::epsilon;
|
|
Toshihiro Shimizu |
890ddd |
return 1.0 / det;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
double tglGetTextWidth(const std::string &s, void *font)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double factor = 0.07;
|
|
Toshihiro Shimizu |
890ddd |
double w = 0;
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < (int)s.length(); i++)
|
|
Toshihiro Shimizu |
890ddd |
w += glutStrokeWidth(font, s[i]);
|
|
Toshihiro Shimizu |
890ddd |
return w * factor;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
void tglDrawText(const TPointD &p, const std::string &s, void *character)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
#ifndef __sgi
|
|
Toshihiro Shimizu |
890ddd |
glPushMatrix();
|
|
Toshihiro Shimizu |
890ddd |
glTranslated(p.x, p.y, 0);
|
|
Toshihiro Shimizu |
890ddd |
double factor = 0.07;
|
|
Toshihiro Shimizu |
890ddd |
glScaled(factor, factor, factor);
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < (int)s.size(); i++)
|
|
Toshihiro Shimizu |
890ddd |
glutStrokeCharacter(character, s[i]);
|
|
Toshihiro Shimizu |
890ddd |
glPopMatrix();
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
assert("Not Yet Implemented" && 0);
|
|
Toshihiro Shimizu |
890ddd |
std::cout << s << std::endl;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
void tglDrawText(const TPointD &p, const std::wstring &s, void *character)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
#ifndef __sgi
|
|
Toshihiro Shimizu |
890ddd |
glPushMatrix();
|
|
Toshihiro Shimizu |
890ddd |
glTranslated(p.x, p.y, 0);
|
|
Toshihiro Shimizu |
890ddd |
double factor = 0.07;
|
|
Toshihiro Shimizu |
890ddd |
glScaled(factor, factor, factor);
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < (int)s.size(); i++)
|
|
Toshihiro Shimizu |
890ddd |
glutStrokeCharacter(character, s[i]);
|
|
Toshihiro Shimizu |
890ddd |
glPopMatrix();
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
assert("Not Yet Implemented" && 0);
|
|
Toshihiro Shimizu |
890ddd |
std::cout << s << std::endl;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void tglDrawSegment(const TPointD &p1, const TPointD &p2)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
glBegin(GL_LINES);
|
|
Toshihiro Shimizu |
890ddd |
tglVertex(p1);
|
|
Toshihiro Shimizu |
890ddd |
tglVertex(p2);
|
|
Toshihiro Shimizu |
890ddd |
glEnd();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void tglDrawCircle(const TPointD ¢er, double radius)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (radius <= 0)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double pixelSize = 1;
|
|
Toshihiro Shimizu |
890ddd |
int slices = 60;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (slices <= 0)
|
|
Toshihiro Shimizu |
890ddd |
slices = computeSlices(radius, pixelSize) >> 1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
ee259f |
double step = M_PI / slices;
|
|
Toshihiro Shimizu |
890ddd |
double step2 = 2.0 * step;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double
|
|
Toshihiro Shimizu |
890ddd |
cos_t,
|
|
Toshihiro Shimizu |
890ddd |
sin_t,
|
|
Toshihiro Shimizu |
890ddd |
cos_ts, sin_ts, t;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glPushMatrix();
|
|
Toshihiro Shimizu |
890ddd |
glTranslated(center.x, center.y, 0.0);
|
|
Toshihiro Shimizu |
890ddd |
glBegin(GL_LINES);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
cos_t = radius /* *1.0*/;
|
|
Toshihiro Shimizu |
890ddd |
sin_t = 0.0;
|
|
Shinya Kitaoka |
ee259f |
for (t = 0; t + step < M_PI_2; t += step2) {
|
|
Toshihiro Shimizu |
890ddd |
cos_ts = radius * cos(t + step);
|
|
Toshihiro Shimizu |
890ddd |
sin_ts = radius * sin(t + step);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glVertex2f(cos_t, sin_t);
|
|
Toshihiro Shimizu |
890ddd |
glVertex2f(cos_ts, sin_ts);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glVertex2f(-cos_t, sin_t);
|
|
Toshihiro Shimizu |
890ddd |
glVertex2f(-cos_ts, sin_ts);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glVertex2f(-cos_t, -sin_t);
|
|
Toshihiro Shimizu |
890ddd |
glVertex2f(-cos_ts, -sin_ts);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glVertex2f(cos_t, -sin_t);
|
|
Toshihiro Shimizu |
890ddd |
glVertex2f(cos_ts, -sin_ts);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
cos_t = cos_ts;
|
|
Toshihiro Shimizu |
890ddd |
sin_t = sin_ts;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
cos_ts = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
sin_ts = radius /* *1.0*/;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glVertex2f(cos_t, sin_t);
|
|
Toshihiro Shimizu |
890ddd |
glVertex2f(cos_ts, sin_ts);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glVertex2f(-cos_t, sin_t);
|
|
Toshihiro Shimizu |
890ddd |
glVertex2f(-cos_ts, sin_ts);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glVertex2f(-cos_t, -sin_t);
|
|
Toshihiro Shimizu |
890ddd |
glVertex2f(-cos_ts, -sin_ts);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glVertex2f(cos_t, -sin_t);
|
|
Toshihiro Shimizu |
890ddd |
glVertex2f(cos_ts, -sin_ts);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glEnd();
|
|
Toshihiro Shimizu |
890ddd |
glPopMatrix();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void tglDrawDisk(const TPointD &c, double r)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (r <= 0)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double pixelSize = 1;
|
|
Toshihiro Shimizu |
890ddd |
int slices = 60;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (slices <= 0)
|
|
Toshihiro Shimizu |
890ddd |
slices = computeSlices(r, pixelSize) >> 1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glPushMatrix();
|
|
Toshihiro Shimizu |
890ddd |
glTranslated(c.x, c.y, 0.0);
|
|
Toshihiro Shimizu |
890ddd |
GLUquadric *quadric = gluNewQuadric();
|
|
Toshihiro Shimizu |
890ddd |
gluDisk(quadric, 0, r, slices, 1);
|
|
Toshihiro Shimizu |
890ddd |
gluDeleteQuadric(quadric);
|
|
Toshihiro Shimizu |
890ddd |
glPopMatrix();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void tglDrawRect(const TRectD &rect)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
glBegin(GL_LINE_LOOP);
|
|
Toshihiro Shimizu |
890ddd |
tglVertex(rect.getP00());
|
|
Toshihiro Shimizu |
890ddd |
tglVertex(rect.getP10());
|
|
Toshihiro Shimizu |
890ddd |
tglVertex(rect.getP11());
|
|
Toshihiro Shimizu |
890ddd |
tglVertex(rect.getP01());
|
|
Toshihiro Shimizu |
890ddd |
glEnd();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void tglFillRect(const TRectD &rect)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
glBegin(GL_POLYGON);
|
|
Toshihiro Shimizu |
890ddd |
tglVertex(rect.getP00());
|
|
Toshihiro Shimizu |
890ddd |
tglVertex(rect.getP10());
|
|
Toshihiro Shimizu |
890ddd |
tglVertex(rect.getP11());
|
|
Toshihiro Shimizu |
890ddd |
tglVertex(rect.getP01());
|
|
Toshihiro Shimizu |
890ddd |
glEnd();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void tglRgbOnlyColorMask()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
tglMultColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
|
|
Toshihiro Shimizu |
890ddd |
tglEnableBlending(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void tglAlphaOnlyColorMask()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
tglMultColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);
|
|
Toshihiro Shimizu |
890ddd |
tglEnableBlending(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void tglEnableBlending(GLenum src, GLenum dst)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
glEnable(GL_BLEND);
|
|
Toshihiro Shimizu |
890ddd |
glBlendFunc(src, dst);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void tglEnableLineSmooth(bool enable, double lineSize)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (enable) {
|
|
Toshihiro Shimizu |
890ddd |
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
|
|
Toshihiro Shimizu |
890ddd |
glEnable(GL_LINE_SMOOTH);
|
|
Toshihiro Shimizu |
890ddd |
glLineWidth(lineSize);
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
glDisable(GL_LINE_SMOOTH);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void tglEnablePointSmooth(double pointSize)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
glEnable(GL_BLEND);
|
|
Toshihiro Shimizu |
890ddd |
glPointSize(pointSize);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void tglGetColorMask(GLboolean &red, GLboolean &green, GLboolean &blue, GLboolean &alpha)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
GLboolean channels[4];
|
|
Toshihiro Shimizu |
890ddd |
glGetBooleanv(GL_COLOR_WRITEMASK, &channels[0]);
|
|
Toshihiro Shimizu |
890ddd |
red = channels[0], green = channels[1], blue = channels[2], alpha = channels[3];
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void tglMultColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
GLboolean channels[4];
|
|
Toshihiro Shimizu |
890ddd |
glGetBooleanv(GL_COLOR_WRITEMASK, &channels[0]);
|
|
Toshihiro Shimizu |
890ddd |
glColorMask(red && channels[0],
|
|
Toshihiro Shimizu |
890ddd |
green && channels[1],
|
|
Toshihiro Shimizu |
890ddd |
blue && channels[2],
|
|
Toshihiro Shimizu |
890ddd |
alpha && channels[3]);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
//============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class GlFontManager
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
GlFontManager();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
~GlFontManager();
|
|
Toshihiro Shimizu |
890ddd |
static GlFontManager *instance();
|
|
Toshihiro Shimizu |
890ddd |
bool setFont(void *font = GLUT_BITMAP_TIMES_ROMAN_10);
|
|
Toshihiro Shimizu |
890ddd |
void drawText(/*const TRectD bBox,*/
|
|
Shinya Kitaoka |
3bfa54 |
std::wstring wtext /*,
|
|
Toshihiro Shimizu |
890ddd |
TDimensionD scale = TDimensionD(1.0, 1.0)*/);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
private:
|
|
Toshihiro Shimizu |
890ddd |
static GlFontManager *m_instance;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// font font_height
|
|
Toshihiro Shimizu |
890ddd |
// | |
|
|
Toshihiro Shimizu |
890ddd |
std::map<void *,="" double=""> m_fonts;</void>
|
|
Toshihiro Shimizu |
890ddd |
std::vector<trectd> m_charsBBox;</trectd>
|
|
Toshihiro Shimizu |
890ddd |
void *m_currentFont;
|
|
Toshihiro Shimizu |
890ddd |
TRaster32P m_fontTexture;
|
|
Toshihiro Shimizu |
890ddd |
GLuint m_base;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
GlFontManager *GlFontManager::m_instance = 0L;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
GlFontManager::GlFontManager()
|
|
Toshihiro Shimizu |
890ddd |
: m_currentFont(0L), m_base(0)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_fonts.insert(std::make_pair(GLUT_BITMAP_8_BY_13, 13.0));
|
|
Toshihiro Shimizu |
890ddd |
m_fonts.insert(std::make_pair(GLUT_BITMAP_9_BY_15, 15.0));
|
|
Toshihiro Shimizu |
890ddd |
m_fonts.insert(std::make_pair(GLUT_BITMAP_TIMES_ROMAN_10, 10.0));
|
|
Toshihiro Shimizu |
890ddd |
m_fonts.insert(std::make_pair(GLUT_BITMAP_TIMES_ROMAN_24, 24.0));
|
|
Toshihiro Shimizu |
890ddd |
m_fonts.insert(std::make_pair(GLUT_BITMAP_HELVETICA_10, 10.0));
|
|
Toshihiro Shimizu |
890ddd |
m_fonts.insert(std::make_pair(GLUT_BITMAP_HELVETICA_12, 12.0));
|
|
Toshihiro Shimizu |
890ddd |
m_fonts.insert(std::make_pair(GLUT_BITMAP_HELVETICA_18, 18.0));
|
|
Toshihiro Shimizu |
890ddd |
bool ok = setFont();
|
|
Toshihiro Shimizu |
890ddd |
assert(ok);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
GlFontManager::~GlFontManager()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_instance = 0L;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
GlFontManager *GlFontManager::instance()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!m_instance)
|
|
Toshihiro Shimizu |
890ddd |
m_instance = new GlFontManager();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return m_instance;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool GlFontManager::setFont(void *font)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
// cerca il font scelto nella mappa dei fonts conosciuti
|
|
Toshihiro Shimizu |
890ddd |
std::map<void *,="" double="">::iterator it =</void>
|
|
Toshihiro Shimizu |
890ddd |
m_fonts.find(font);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// se e' stato trovato
|
|
Toshihiro Shimizu |
890ddd |
if (it != m_fonts.end()) {
|
|
Toshihiro Shimizu |
890ddd |
m_currentFont = font;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
|
Toshihiro Shimizu |
890ddd |
glPushMatrix();
|
|
Toshihiro Shimizu |
890ddd |
m_base = glGenLists(256);
|
|
Toshihiro Shimizu |
890ddd |
glListBase(m_base);
|
|
Toshihiro Shimizu |
890ddd |
int i = 0;
|
|
Toshihiro Shimizu |
890ddd |
for (; i < 256; ++i) {
|
|
Toshihiro Shimizu |
890ddd |
glNewList(m_base + i, GL_COMPILE);
|
|
Toshihiro Shimizu |
890ddd |
glutStrokeCharacter(GLUT_STROKE_ROMAN, i);
|
|
Toshihiro Shimizu |
890ddd |
//glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, i);
|
|
Toshihiro Shimizu |
890ddd |
glEndList();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
glPopAttrib();
|
|
Toshihiro Shimizu |
890ddd |
glPopMatrix();
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void GlFontManager::drawText(/*const TRectD bBox,*/
|
|
Shinya Kitaoka |
3bfa54 |
std::wstring wtext /*,
|
|
Toshihiro Shimizu |
890ddd |
TDimensionD scale*/)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!m_currentFont)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
9eb50d |
std::string text = ::to_string(wtext);
|
|
Toshihiro Shimizu |
890ddd |
const char *textString = text.c_str();
|
|
Toshihiro Shimizu |
890ddd |
glListBase(m_base);
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
glPushMatrix();
|
|
Toshihiro Shimizu |
890ddd |
glTranslated(bBox.x0, bBox.y0, 0.0);
|
|
Toshihiro Shimizu |
890ddd |
glScaled(scale.lx*0.07, scale.ly*0.07, 1.0);
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
glCallLists((GLuint)strlen(textString), GL_BYTE, textString);
|
|
Toshihiro Shimizu |
890ddd |
/*glPopMatrix();*/
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} // anonymous namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void tglDraw(const TCubic &cubic, int precision, GLenum pointOrLine)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
CHECK_ERRORS_BY_GL;
|
|
Toshihiro Shimizu |
890ddd |
assert(pointOrLine == GL_POINT || pointOrLine == GL_LINE);
|
|
Shinya Kitaoka |
6a4e01 |
float ctrlPts[4][3];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ctrlPts[0][0] = cubic.getP0().x;
|
|
Toshihiro Shimizu |
890ddd |
ctrlPts[0][1] = cubic.getP0().y;
|
|
Toshihiro Shimizu |
890ddd |
ctrlPts[0][2] = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ctrlPts[1][0] = cubic.getP1().x;
|
|
Toshihiro Shimizu |
890ddd |
ctrlPts[1][1] = cubic.getP1().y;
|
|
Toshihiro Shimizu |
890ddd |
ctrlPts[1][2] = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ctrlPts[2][0] = cubic.getP2().x;
|
|
Toshihiro Shimizu |
890ddd |
ctrlPts[2][1] = cubic.getP2().y;
|
|
Toshihiro Shimizu |
890ddd |
ctrlPts[2][2] = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ctrlPts[3][0] = cubic.getP3().x;
|
|
Toshihiro Shimizu |
890ddd |
ctrlPts[3][1] = cubic.getP3().y;
|
|
Toshihiro Shimizu |
890ddd |
ctrlPts[3][2] = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CHECK_ERRORS_BY_GL;
|
|
Toshihiro Shimizu |
890ddd |
glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &ctrlPts[0][0]);
|
|
Toshihiro Shimizu |
890ddd |
CHECK_ERRORS_BY_GL;
|
|
Toshihiro Shimizu |
890ddd |
glEnable(GL_MAP1_VERTEX_3);
|
|
Toshihiro Shimizu |
890ddd |
CHECK_ERRORS_BY_GL;
|
|
Toshihiro Shimizu |
890ddd |
glMapGrid1f(precision, 0.0, 1.0);
|
|
Toshihiro Shimizu |
890ddd |
CHECK_ERRORS_BY_GL;
|
|
Toshihiro Shimizu |
890ddd |
glEvalMesh1(pointOrLine, 0, precision);
|
|
Toshihiro Shimizu |
890ddd |
CHECK_ERRORS_BY_GL;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void tglDraw(const TRectD &rect,
|
|
Toshihiro Shimizu |
890ddd |
const std::vector<traster32p> &textures,</traster32p>
|
|
Toshihiro Shimizu |
890ddd |
bool blending)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double pixelSize2 = tglGetPixelSize2();
|
|
Toshihiro Shimizu |
890ddd |
// level e' la minore potenza di 2 maggiore di sqrt(pixelSize2)
|
|
Toshihiro Shimizu |
890ddd |
unsigned int level = 1;
|
|
Toshihiro Shimizu |
890ddd |
while (pixelSize2 * level * level <= 1.0)
|
|
Toshihiro Shimizu |
890ddd |
level <<= 1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
unsigned int texturesCount = (int)textures.size();
|
|
Toshihiro Shimizu |
890ddd |
if (level > texturesCount)
|
|
Toshihiro Shimizu |
890ddd |
level = texturesCount;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
level = texturesCount - level;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
tglDraw(rect, textures[level], blending);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void tglDraw(const TRectD &rect, const TRaster32P &tex, bool blending)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
CHECK_ERRORS_BY_GL;
|
|
Toshihiro Shimizu |
890ddd |
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
|
Toshihiro Shimizu |
890ddd |
if (blending) {
|
|
Toshihiro Shimizu |
890ddd |
glEnable(GL_BLEND);
|
|
Toshihiro Shimizu |
890ddd |
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
unsigned int texWidth = 1;
|
|
Toshihiro Shimizu |
890ddd |
unsigned int texHeight = 1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
while (texWidth < (unsigned int)tex->getLx())
|
|
Toshihiro Shimizu |
890ddd |
texWidth = texWidth << 1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
while (texHeight < (unsigned int)tex->getLy())
|
|
Toshihiro Shimizu |
890ddd |
texHeight = texHeight << 1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double lwTex = 1.0;
|
|
Toshihiro Shimizu |
890ddd |
double lhTex = 1.0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRaster32P texture;
|
|
Toshihiro Shimizu |
890ddd |
unsigned int texLx = (unsigned int)tex->getLx();
|
|
Toshihiro Shimizu |
890ddd |
unsigned int texLy = (unsigned int)tex->getLy();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (texWidth != texLx ||
|
|
Toshihiro Shimizu |
890ddd |
texHeight != texLy) {
|
|
Toshihiro Shimizu |
890ddd |
texture = TRaster32P(texWidth, texHeight);
|
|
Toshihiro Shimizu |
890ddd |
texture->fill(TPixel32(0, 0, 0, 0));
|
|
Toshihiro Shimizu |
890ddd |
texture->copy(tex);
|
|
Toshihiro Shimizu |
890ddd |
lwTex = (texLx) / (double)(texWidth);
|
|
Toshihiro Shimizu |
890ddd |
lhTex = (texLy) / (double)(texHeight);
|
|
Toshihiro Shimizu |
890ddd |
if (lwTex > 1.0)
|
|
Toshihiro Shimizu |
890ddd |
lwTex = 1.0;
|
|
Toshihiro Shimizu |
890ddd |
if (lhTex > 1.0)
|
|
Toshihiro Shimizu |
890ddd |
lhTex = 1.0;
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
texture = tex;
|
|
Toshihiro Shimizu |
890ddd |
GLenum fmt =
|
|
Toshihiro Shimizu |
890ddd |
#ifdef TNZ_MACHINE_CHANNEL_ORDER_BGRM
|
|
Toshihiro Shimizu |
890ddd |
GL_BGRA_EXT;
|
|
Toshihiro Shimizu |
890ddd |
#elif TNZ_MACHINE_CHANNEL_ORDER_MBGR
|
|
Toshihiro Shimizu |
890ddd |
GL_ABGR_EXT;
|
|
Toshihiro Shimizu |
890ddd |
#elif TNZ_MACHINE_CHANNEL_ORDER_RGBM
|
|
Toshihiro Shimizu |
890ddd |
GL_RGBA;
|
|
Toshihiro Shimizu |
890ddd |
#elif TNZ_MACHINE_CHANNEL_ORDER_MRGB
|
|
Toshihiro Shimizu |
890ddd |
GL_BGRA;
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
// Error PLATFORM NOT SUPPORTED
|
|
Campbell Barton |
42d601 |
#error "unknown channel order!"
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Generate a texture id and bind it.
|
|
Toshihiro Shimizu |
890ddd |
GLuint texId;
|
|
Toshihiro Shimizu |
890ddd |
glGenTextures(1, &texId);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glBindTexture(GL_TEXTURE_2D, texId);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glPixelStorei(GL_UNPACK_ROW_LENGTH, texture->getWrap());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
texture->lock();
|
|
Toshihiro Shimizu |
890ddd |
glTexImage2D(GL_TEXTURE_2D,
|
|
Toshihiro Shimizu |
890ddd |
0,
|
|
Toshihiro Shimizu |
890ddd |
4,
|
|
Toshihiro Shimizu |
890ddd |
texWidth,
|
|
Toshihiro Shimizu |
890ddd |
texHeight,
|
|
Toshihiro Shimizu |
890ddd |
0,
|
|
Toshihiro Shimizu |
890ddd |
fmt,
|
|
Toshihiro Shimizu |
890ddd |
#ifdef TNZ_MACHINE_CHANNEL_ORDER_MRGB
|
|
Toshihiro Shimizu |
890ddd |
GL_UNSIGNED_INT_8_8_8_8_REV,
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
GL_UNSIGNED_BYTE,
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
texture->getRawData());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
|
Toshihiro Shimizu |
890ddd |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
Toshihiro Shimizu |
890ddd |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
|
Toshihiro Shimizu |
890ddd |
glEnable(GL_TEXTURE_2D);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double rectLx = rect.getLx();
|
|
Toshihiro Shimizu |
890ddd |
double rectLy = rect.getLy();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
tglColor(TPixel32(0, 0, 0, 0));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glPushMatrix();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glTranslated(rect.x0, rect.y0, 0.0);
|
|
Toshihiro Shimizu |
890ddd |
glBegin(GL_POLYGON);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glTexCoord2d(0, 0);
|
|
Toshihiro Shimizu |
890ddd |
tglVertex(TPointD(0.0, 0.0));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glTexCoord2d(lwTex, 0);
|
|
Toshihiro Shimizu |
890ddd |
tglVertex(TPointD(rectLx, 0.0));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glTexCoord2d(lwTex, lhTex);
|
|
Toshihiro Shimizu |
890ddd |
tglVertex(TPointD(rectLx, rectLy));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glTexCoord2d(0, lhTex);
|
|
Toshihiro Shimizu |
890ddd |
tglVertex(TPointD(0.0, rectLy));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glEnd();
|
|
Toshihiro Shimizu |
890ddd |
glDisable(GL_TEXTURE_2D);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glPopMatrix();
|
|
Toshihiro Shimizu |
890ddd |
glPopAttrib();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Delete texture
|
|
Toshihiro Shimizu |
890ddd |
glDeleteTextures(1, &texId);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
texture->unlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void tglBuildMipmaps(std::vector<traster32p> &rasters,</traster32p>
|
|
Toshihiro Shimizu |
890ddd |
const TFilePath &filepath)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(rasters.size() > 0);
|
|
Toshihiro Shimizu |
890ddd |
TRop::ResampleFilterType resampleFilter = TRop::ClosestPixel;
|
|
Toshihiro Shimizu |
890ddd |
TRasterP ras;
|
|
Toshihiro Shimizu |
890ddd |
TImageReader::load(filepath, ras);
|
|
Toshihiro Shimizu |
890ddd |
int rasLx = ras->getLx();
|
|
Toshihiro Shimizu |
890ddd |
int rasLy = ras->getLy();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int lx = 1;
|
|
Toshihiro Shimizu |
890ddd |
while (lx < rasLx)
|
|
Toshihiro Shimizu |
890ddd |
lx <<= 1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int ly = 1;
|
|
Toshihiro Shimizu |
890ddd |
while (ly < rasLy)
|
|
Toshihiro Shimizu |
890ddd |
ly <<= 1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRaster32P ras2(lx, ly);
|
|
Toshihiro Shimizu |
890ddd |
double sx = (double)lx / (double)ras->getLx();
|
|
Toshihiro Shimizu |
890ddd |
double sy = (double)ly / (double)ras->getLy();
|
|
Toshihiro Shimizu |
890ddd |
#ifndef SCALE_BY_GLU
|
|
Toshihiro Shimizu |
890ddd |
TRop::resample(ras2, ras, TScale(sx, sy), resampleFilter);
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
ras->lock();
|
|
Toshihiro Shimizu |
890ddd |
gluScaleImage(GL_RGBA, ras->getLx(), ras->getLy(), GL_UNSIGNED_BYTE, ras->getRawData(),
|
|
Toshihiro Shimizu |
890ddd |
lx, ly, GL_UNSIGNED_BYTE, ras2->getRawData());
|
|
Toshihiro Shimizu |
890ddd |
ras->unlock();
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
rasters[0] = ras2;
|
|
Toshihiro Shimizu |
890ddd |
int ras2Lx = ras2->getLx();
|
|
Toshihiro Shimizu |
890ddd |
int ras2Ly = ras2->getLy();
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 1; i < (int)rasters.size(); ++i) {
|
|
Toshihiro Shimizu |
890ddd |
lx >>= 1;
|
|
Toshihiro Shimizu |
890ddd |
ly >>= 1;
|
|
Toshihiro Shimizu |
890ddd |
if (lx < 1)
|
|
Toshihiro Shimizu |
890ddd |
lx = 1;
|
|
Toshihiro Shimizu |
890ddd |
if (ly < 1)
|
|
Toshihiro Shimizu |
890ddd |
ly = 1;
|
|
Toshihiro Shimizu |
890ddd |
rasters[i] = TRaster32P(lx, ly);
|
|
Toshihiro Shimizu |
890ddd |
sx = (double)lx / (double)ras2Lx;
|
|
Toshihiro Shimizu |
890ddd |
sy = (double)ly / (double)ras2Ly;
|
|
Toshihiro Shimizu |
890ddd |
rasters[i] = TRaster32P(lx, ly);
|
|
Toshihiro Shimizu |
890ddd |
#ifndef SCALE_BY_GLU
|
|
Toshihiro Shimizu |
890ddd |
TRop::resample(rasters[i], ras2, TScale(sx, sy), resampleFilter);
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
ras2->lock();
|
|
Toshihiro Shimizu |
890ddd |
gluScaleImage(GL_RGBA, ras->getLx(), ras->getLy(), GL_UNSIGNED_BYTE, ras2->getRawData(),
|
|
Toshihiro Shimizu |
890ddd |
lx, ly, GL_UNSIGNED_BYTE, rasters[i]->getRawData());
|
|
Toshihiro Shimizu |
890ddd |
ras2->unlock();
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
//Forse si potrebbe togliere l'ifdef ed usare QT
|
|
Shinya Kitaoka |
9f5a1b |
#if defined(_WIN32)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TGlContext tglGetCurrentContext()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return std::make_pair(wglGetCurrentDC(), wglGetCurrentContext());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void tglMakeCurrent(TGlContext context)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
wglMakeCurrent(context.first, context.second);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void tglDoneCurrent(TGlContext)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
wglMakeCurrent(NULL, NULL);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#elif defined(LINUX) || defined(__sgi) || defined(MACOSX)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TGlContext tglGetCurrentContext()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return reinterpret_cast<tglcontext>(</tglcontext>
|
|
Toshihiro Shimizu |
890ddd |
const_cast<qglcontext *="">(QGLContext::currentContext()));</qglcontext>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// (Daniele) I'm not sure why QGLContext::currentContext() returns
|
|
Toshihiro Shimizu |
890ddd |
// const. I think it shouldn't, and guess (hope) this is safe...
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void tglMakeCurrent(TGlContext context)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (context)
|
|
Toshihiro Shimizu |
890ddd |
reinterpret_cast<qglcontext *="">(context)->makeCurrent();</qglcontext>
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
tglDoneCurrent(tglGetCurrentContext());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void tglDoneCurrent(TGlContext context)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (context)
|
|
Toshihiro Shimizu |
890ddd |
reinterpret_cast<qglcontext *="">(context)->doneCurrent();</qglcontext>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Campbell Barton |
42d601 |
#else
|
|
Campbell Barton |
42d601 |
#error "unknown platform!"
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
// End Of File
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|