Hi,
I’m very new too openframework and want to know if there is a possible way to get the ofimage to work without the testapp.cpp. I’m currently loading images and get instead of textures white rectangles.
More special I got a class that’s like this:
bild.h
#ifndef _BILD_H
#define _BILD_H
#include "ofImage.h"
#include <string>
class Bild : public ofImage
{
public:
Bild (string dateiname) : ofImage () { this->setDateiname (dateiname); }
void ladeMiniatur (string verzeichnis);
void ladeMittlereAnsicht();
void ladeGrossAnsicht ();
void zeichneBild();
void setDateiname (string dateiname);
string getDateiname ();
private:
enum AnsichtsTyp {Miniatur = 75, MittlereAnsicht = 150, GrossAnsicht = 800 };
void passeGroesseAn (AnsichtsTyp ansichtstyp);
string dateiname;
};
#endif
bild.cpp
#include "bild.h"
void Bild::ladeMiniatur (string verzeichnis)
{
this->loadImage (verzeichnis + "/" + this->dateiname);
this->setUseTexture(true);
//this->passeGroesseAn (Miniatur);
this->bUseTexture = true;
}
void Bild::ladeMittlereAnsicht()
{
this->loadImage (this->dateiname);
this->passeGroesseAn (MittlereAnsicht);
this->bUseTexture = true;
}
void Bild::ladeGrossAnsicht ()
{
this->loadImage (this->dateiname);
this->passeGroesseAn (GrossAnsicht);
this->bUseTexture = true;
}
void Bild::zeichneBild ()
{
this->tex.drawTexture ();
}
void Bild::setDateiname (string dateiname)
{
this->dateiname = dateiname;
}
string Bild::getDateiname ()
{
return this->dateiname;
}
/**
* Skaliert Bild auf ein maximale Größe für Breite bzw. Höhe.
* Je nachdem, ob das Bild breiter ist als hoch oder höher als breit,
* wird für die Breite bzw. Höhe der maximale Wert angenommen.
*
* Dient der Anpassung der Texturgröße an den jeweiligen Anzeigemodus (Miniatur, mittel, groß)
* um für die Miniaturen Speicher zu sparen und bei den größeren Ansichten,
* trotzdem gute Bildqualität zu gewährleisten.
**/
void Bild::passeGroesseAn (AnsichtsTyp ansichtstyp)
{
float skalierung;
// ansichtstypfloat = (float) ansichtstyp;
// Was ist größer - die Breite oder die Höhe des Bildes
if ( ( this->width > ansichtstyp ) || ( this->height > ansichtstyp ) ) // ist das Bild zu groß ??
{
if ( this->width != 0 ) // Division durch null vermeiden, z.B. bei nicht korrekt geladenen Bildern
{
if ( this->height > this->width ) skalierung = this->height / (float)ansichtstyp;
else skalierung = this->width / (float) ansichtstyp;
this->resize ((int)(this->width / skalierung), (int)(this->height / skalierung));
}
else
{
std::cout<<"Fehler: Breite bei "<<this->dateiname<<" gleich 0. Groessenanpassung nicht möglich."<<std::endl;
}
}
}
and I added a function in the oftexture.cpp, which calculates the right coordinates and draw’s:
void ofTexture::drawTexture ()
{
//this->LoadGLTextures();
GLfloat p1x, p2x, p3x, p4x;
GLfloat p1y, p2y, p3y, p4y;
GLfloat ratio;
p1x = -1.0f;
p2x = 1.0f;
p3x = 1.0f;
p4x = -1.0f;
p1y = -1.0f;
p2y = -1.0f;
p3y = 1.0f;
p4y = 1.0f;
glPushMatrix();
ratio = (float) this->width / (float) this->height;
if ( this->height > this->width )
{
p1x *= ratio;
p2x *= ratio;
p3x *= ratio;
p4x *= ratio;
}
else
{
p1y /= ratio;
p2y /= ratio;
p3y /= ratio;
p4y /= ratio;
}
glEnable(textureTarget);
glBindTexture( textureTarget, (GLuint)textureName[0] );
glBegin(GL_QUADS);
glTexCoord2f(0.0f, tex_u); glVertex3f(p1x ,p1y, 0.0f );
glTexCoord2f(tex_t, tex_u); glVertex3f(p2x ,p2y, 0.0f );
glTexCoord2f(tex_t, 0.0f); glVertex3f(p3x ,p3y, 0.0f );
glTexCoord2f(0.0f, 0.0f); glVertex3f(p4x ,p4y, 0.0f );
glEnd();
glDisable(textureTarget);
glPopMatrix();
}