#include "ofApp.h"
void ofApp::setup(){
ofSetOrientation(OF_ORIENTATION_90_RIGHT);
w = 250;
h = 200;
texGray.allocate(w,h,GL_LUMINANCE);
texColor.allocate(w,h,GL_RGB);
texColorAlpha.allocate(w,h,GL_RGBA);
grayPixels = new unsigned char [w*h];
colorPixels = new unsigned char [w*h*3];
colorAlphaPixels = new unsigned char [w*h*4];
for (int i = 0; i < w*h; i++){
grayPixels[i] = (unsigned char)(ofRandomuf() * 255);
}
for (int i = 0; i < w; i++){
for (int j = 0; j < h; j++){
colorPixels[(j*w+i)*3 + 0] = i;
colorPixels[(j*w+i)*3 + 1] = j;
colorPixels[(j*w+i)*3 + 2] = 0;
}
}
for (int i = 0; i < w; i++){
for (int j = 0; j < h; j++){
colorAlphaPixels[(j*w+i)*4 + 0] = 255;
colorAlphaPixels[(j*w+i)*4 + 1] = 133;
colorAlphaPixels[(j*w+i)*4 + 2] = 200;
colorAlphaPixels[(j*w+i)*4 + 3] = i;
}
}
texGray.loadData(grayPixels, w,h, GL_LUMINANCE);
texColor.loadData(colorPixels, w,h, GL_RGB);
texColorAlpha.loadData(colorAlphaPixels, w,h, GL_RGBA);
}
void ofApp::update(){
ofBackground(255,255,255);
for (int i = 0; i < w; i++){
for (int j = 0; j < h; j++){
grayPixels[j*w+i] = (unsigned char)(ofRandomuf() * 255);
}
}
texGray.loadData(grayPixels, w,h, GL_LUMINANCE);
}
void ofApp::draw(){
ofScale(0.6, 0.6, 1.0);
ofSetHexColor(0xffffff);
texGray.draw(100,100,w,h);
texColor.draw(350,300,w,h);
ofEnableAlphaBlending();
texColorAlpha.draw(250,200,w,h);
ofDisableAlphaBlending();
}
void ofApp::exit(){
}
void ofApp::touchDown(ofTouchEventArgs & touch){
}
void ofApp::touchMoved(ofTouchEventArgs & touch){
float pct = (float)touch.x / (float)ofGetWidth();
for (int i = 0; i < w; i++){
for (int j = 0; j < h; j++){
colorPixels[(j*w+i)*3 + 0] = i;
colorPixels[(j*w+i)*3 + 1] = j;
colorPixels[(j*w+i)*3 + 2] = (unsigned char)(pct*255);
}
}
texColor.loadData(colorPixels, w,h, GL_RGB);
}
void ofApp::touchUp(ofTouchEventArgs & touch){
}
void ofApp::touchDoubleTap(ofTouchEventArgs & touch){
}
void ofApp::touchCancelled(ofTouchEventArgs & touch){
}
void ofApp::lostFocus(){
}
void ofApp::gotFocus(){
}
void ofApp::gotMemoryWarning(){
}
void ofApp::deviceOrientationChanged(int newOrientation){
}
Comments