Skip to content
Snippets Groups Projects
Commit 65a02495 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

new billboard-style texture drawing

parent 49f5a4a4
No related branches found
No related tags found
No related merge requests found
...@@ -234,7 +234,7 @@ class drawContext { ...@@ -234,7 +234,7 @@ class drawContext {
void drawStringCenter(const std::string &s, double x, double y, double z); void drawStringCenter(const std::string &s, double x, double y, double z);
void drawStringRight(const std::string &s, double x, double y, double z); void drawStringRight(const std::string &s, double x, double y, double z);
void drawString(const std::string &s, double x, double y, double z, double style); void drawString(const std::string &s, double x, double y, double z, double style);
void drawImage(const std::string &s, double x, double y, double z); void drawImage(const std::string &s, double x, double y, double z, int align=0);
void drawSphere(double R, double x, double y, double z, int n1, int n2, int light); void drawSphere(double R, double x, double y, double z, int n1, int n2, int light);
void drawEllipsoid(double x, double y, double z, float v0[3], float v1[3], void drawEllipsoid(double x, double y, double z, float v0[3], float v1[3],
float v2[3], int light); float v2[3], int light);
......
...@@ -21,7 +21,7 @@ void drawContext::drawString(const std::string &s, double x, double y, double z, ...@@ -21,7 +21,7 @@ void drawContext::drawString(const std::string &s, double x, double y, double z,
if(CTX::instance()->printing && !CTX::instance()->print.text) return; if(CTX::instance()->printing && !CTX::instance()->print.text) return;
if(s.size() > 8 && s.substr(0, 7) == "file://"){ if(s.size() > 8 && s.substr(0, 7) == "file://"){
drawImage(s.substr(7), x, y, z); drawImage(s.substr(7), x, y, z, align);
return; return;
} }
...@@ -133,7 +133,8 @@ void drawContext::drawString(const std::string &s, double x, double y, double z, ...@@ -133,7 +133,8 @@ void drawContext::drawString(const std::string &s, double x, double y, double z,
} }
} }
void drawContext::drawImage(const std::string &name, double x, double y, double z) void drawContext::drawImage(const std::string &name, double x, double y, double z,
int align)
{ {
// format can be "@wxh" or "@wxh,wx,wy,wz,hx,hy,hz", where w and h are the // format can be "@wxh" or "@wxh,wx,wy,wz,hx,hy,hz", where w and h are the
// width and height (in model coordinates for T3 or in pixels for T2) of the // width and height (in model coordinates for T3 or in pixels for T2) of the
...@@ -146,6 +147,7 @@ void drawContext::drawImage(const std::string &name, double x, double y, double ...@@ -146,6 +147,7 @@ void drawContext::drawImage(const std::string &name, double x, double y, double
file = name.substr(0, p); file = name.substr(0, p);
} }
double w = 0., h = 0., wx = 1., wy = 0., wz = 0., hx = 0., hy = 1., hz = 0.; double w = 0., h = 0., wx = 1., wy = 0., wz = 0., hx = 0., hy = 1., hz = 0.;
bool billboard = false;
if(format.size()){ if(format.size()){
bool ok; bool ok;
if(format.find(",") != std::string::npos) if(format.find(",") != std::string::npos)
...@@ -155,6 +157,8 @@ void drawContext::drawImage(const std::string &name, double x, double y, double ...@@ -155,6 +157,8 @@ void drawContext::drawImage(const std::string &name, double x, double y, double
ok = (sscanf(format.c_str(), "%lfx%lf", &w, &h) == 2); ok = (sscanf(format.c_str(), "%lfx%lf", &w, &h) == 2);
if(!ok) if(!ok)
Msg::Warning("Bad image format: use `@wxh' or `@wxh,wx,wy,wz,hx,hy,hz'"); Msg::Warning("Bad image format: use `@wxh' or `@wxh,wx,wy,wz,hx,hy,hz'");
if(format.find("#") != std::string::npos)
billboard = true; // texture will always face camera
} }
imgtex *img; imgtex *img;
...@@ -185,6 +189,38 @@ void drawContext::drawImage(const std::string &name, double x, double y, double ...@@ -185,6 +189,38 @@ void drawContext::drawImage(const std::string &name, double x, double y, double
w = h * img->w / img->h; w = h * img->w / img->h;
} }
GLint matrixMode = 0;
if(billboard){
glRasterPos3d(x, y, z);
GLfloat pos[4];
glGetFloatv(GL_CURRENT_RASTER_POSITION, pos);
glGetIntegerv(GL_MATRIX_MODE, &matrixMode);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
double fact = isHighResolution() ? 2. : 1.;
glOrtho((double)viewport[0], (double)viewport[2] * fact,
(double)viewport[1], (double)viewport[3] * fact, -1e3, 1e3);
x = pos[0]; y = pos[1]; z = 0;
w *= fact * s[0] / pixel_equiv_x;
h *= fact * s[1] / pixel_equiv_y;
}
switch(align){
case 1: x -= w/2.; break; // bottom center
case 2: x -= w; break; // bottom right
case 3: y -= h; break; // top left
case 4: x -= w/2.; y -= h; break; // top center
case 5: x -= w; y -= h; break; // top right
case 6: y -= h/2.; break; // center left
case 7: x -= w/2.; y -= h/2.; break; // center center
case 8: x -= w; y -= h/2.; break; // center right
default: break;
}
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
...@@ -198,6 +234,13 @@ void drawContext::drawImage(const std::string &name, double x, double y, double ...@@ -198,6 +234,13 @@ void drawContext::drawImage(const std::string &name, double x, double y, double
glEnd(); glEnd();
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND); glDisable(GL_BLEND);
if(billboard){
glPopMatrix();
glMatrixMode (GL_PROJECTION);
glPopMatrix();
glMatrixMode(matrixMode);
}
} }
void drawContext::drawSphere(double R, double x, double y, double z, void drawContext::drawSphere(double R, double x, double y, double z,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment