Browse Source

Added default texture automatic generation

master
Krisjanis Rijnieks 11 years ago
parent
commit
d9d478a550
  1. 2
      example/src/ofApp.cpp
  2. 33
      src/ofxBaseSurface.cpp
  3. 3
      src/ofxBaseSurface.h

2
example/src/ofApp.cpp

@ -6,7 +6,7 @@ void ofApp::setup()
image.loadImage("TestPatternInvert.jpg");
// Create a triangle surface
triangleSurface.setup( ofVec2f(30,40), ofVec2f(500,500), ofVec2f(0,600), ofVec2f(0,0), ofVec2f(1,1), ofVec2f(0,1), &image.getTextureReference() );
//triangleSurface.setup( ofVec2f(30,40), ofVec2f(500,500), ofVec2f(0,600), ofVec2f(0,0), ofVec2f(1,1), ofVec2f(0,1), &image.getTextureReference() );
}
void ofApp::update()

33
src/ofxBaseSurface.cpp

@ -3,4 +3,37 @@
ofxBaseSurface::ofxBaseSurface()
{
ofEnableNormalizedTexCoords();
createDefaultTexture();
}
void ofxBaseSurface::createDefaultTexture()
{
ofPixels pixels;
pixels.allocate(500, 500, 1);
for ( int i=0; i<pixels.size(); i++ ) {
pixels[i] = 255;
}
int squareSize = 10; // size of each test pattern square
bool sy = false;
for ( int y=0; y<pixels.getWidth(); y+=squareSize ) {
bool sx = false;
for ( int x=0; x<pixels.getHeight(); x+=squareSize ) {
for ( int yi=0; yi<squareSize; yi++ ) {
for ( int xi=0; xi<squareSize; xi++ ){
if ( sx && sy ) pixels[(y+yi)*pixels.getWidth()+x+xi] = 255;
else if ( sx && !sy ) pixels[(y+yi)*pixels.getWidth()+x+xi] = 0;
else if ( !sx && sy ) pixels[(y+yi)*pixels.getWidth()+x+xi] = 0;
else pixels[(y+yi)*pixels.getWidth()+x+xi] = 255;
}
}
sx = !sx;
}
sy = !sy;
}
// load pixels into texture
defaultTexture.loadData(pixels);
// Assign default texture to texture pointer
texture = &defaultTexture;
}

3
src/ofxBaseSurface.h

@ -13,6 +13,9 @@ public:
protected:
ofMesh mesh;
ofTexture* texture;
ofTexture defaultTexture;
void createDefaultTexture();
};
#endif
Loading…
Cancel
Save