summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2011-12-30 21:13:07 +0000
committerTim Redfern <tim@eclectronics.org>2011-12-30 21:13:07 +0000
commit4f1d5b3a6efe1de7885b37b091595f7bbc8a9b29 (patch)
tree477bc2474eaf2f72f72a253ae9ec4cd0f2ee0a6a /src
parent86c462a8d5b9517738161eede77ccc6703af779b (diff)
succesfully combined camera and FBO
Diffstat (limited to 'src')
-rw-r--r--src/keyVar.cpp2
-rw-r--r--src/main.cpp2
-rw-r--r--src/testApp.cpp88
-rw-r--r--src/viewpoint.cpp135
4 files changed, 85 insertions, 142 deletions
diff --git a/src/keyVar.cpp b/src/keyVar.cpp
index 26e0455..ea8b9ff 100644
--- a/src/keyVar.cpp
+++ b/src/keyVar.cpp
@@ -5,7 +5,7 @@
*/
#include "keyVar.h"
-#define DEBUG 1
+#define DEBUG 0
void keyVar::set(char _keyInc,char _keyDec,float _val,float _speed,float _accel,float _accelTime){
keyInc=_keyInc;
diff --git a/src/main.cpp b/src/main.cpp
index 6ff359a..049d993 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -6,7 +6,7 @@
int main( ){
ofAppGlutWindow window;
- ofSetupOpenGL(&window, 400,400, OF_WINDOW); // <-------- setup the GL context
+ ofSetupOpenGL(&window, 512,512, OF_WINDOW); // <-------- setup the GL context
// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
diff --git a/src/testApp.cpp b/src/testApp.cpp
index 8ff0865..10dbdf4 100644
--- a/src/testApp.cpp
+++ b/src/testApp.cpp
@@ -39,8 +39,8 @@ void testApp::setup(){
//bottleModel.setRotation(0, -90, 1, 0, 0);
//bottleModel.setRotation(1, 270, 0, 0, 1);
//bottleModel.setScale(0.9, 0.9, 0.9);
- bottle.setPosition(ofGetWidth()/2, ofGetHeight()/2, -50);
- board.setPosition(ofGetWidth()/2, ofGetHeight()/2, -50);
+ bottle.setPosition(0, 0, -50);
+ board.setPosition(0, 0, -50);
//ofDisableArbTex();
@@ -88,10 +88,6 @@ void testApp::draw(){
switch(mode) {
case CALIBRATE:
- glPushMatrix();
- glTranslatef(ofGetWidth(),(ofGetHeight())+100,0);
- //board.draw();
-
int cx,cz;
glFrontFace(GL_CW);
@@ -109,17 +105,6 @@ void testApp::draw(){
}
glEnd();
-
-/*
- glBegin(GL_QUADS);
- glVertex3f(-100, 0,-100);
- glVertex3f(100, 0,-100);
- glVertex3f(100, 0,100);
- glVertex3f(-100, 0,100);
- glEnd();
- */
- glPopMatrix();
- //glFrontFace(GL_CCW);
bottle.draw();
break;
@@ -130,72 +115,21 @@ void testApp::draw(){
bottle.draw();
unbindTexture(texture);
break;
- }
- //glPopMatrix();
- views[0].end();
-
-
-
-
- /*
-
- glPopMatrix();
-
- views[0].renderFBO.draw(0,0);
-
- glPushMatrix();
-
- */
-
- if (mode!=NOTHING){
-
+ case NOTHING:
- bindTexture(views[0].renderFBO);
- glPushMatrix();
- //draw a grid
- //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
- ofNoFill();
-
- ofSetLineWidth(1.0);
- //ofSetColor(I_fade1,I_fade1,I_fade1);
- int gridX=50;
- int gridY=50;
- int xStep=ofGetWidth()/2;
- int yStep=ofGetHeight()/2;
- ofTranslate(ofGetWidth()/2,ofGetHeight()/2);
-
- for (float i = -1; i < 1.001; i+=(2.0f/gridY)){
- glBegin(GL_QUAD_STRIP);
- ofPoint p0;
- ofPoint p1;
- for (float j = -1; j < 1.001; j+=(2.0f/gridX)){
- p0=distort(ofPoint(j,i-(2.0f/gridY)),views[0].distortFactor);
- p1=distort(ofPoint(j,i),views[0].distortFactor);
- glTexCoord2f((j+1)*0.5,((i-(2.0f/gridY))+1)*0.5);
- glVertex3f(p0.x*xStep,p0.y*yStep,-0.1);
- glTexCoord2f((j+1)*0.5,(i+1)*0.5);
- glVertex3f(p1.x*xStep,p1.y*yStep,-0.1);
- }
- glEnd();
- }
-
- ofFill();
-
-
- //renderFBO.getTextureReference().unbind();
- unbindTexture(views[0].renderFBO);
- glPopMatrix();
- }
+ bindTexture(texture);
+ glPushMatrix();
+ drawBox(50.0f);
+ unbindTexture(texture);
+ glPopMatrix();
+ break;
+ }
+ views[0].end();
ofSetHexColor(0xFFFFFF);
ofDrawBitmapString("fps: "+ofToString(ofGetFrameRate(), 2), 10, 15);
-
- // add polygons here
- //glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
-
-
}
//--------------------------------------------------------------
diff --git a/src/viewpoint.cpp b/src/viewpoint.cpp
index 64a2b99..5d61f1f 100644
--- a/src/viewpoint.cpp
+++ b/src/viewpoint.cpp
@@ -1,88 +1,97 @@
#include "viewpoint.h"
-#define DEBUG 1
+#define DEBUG 0
void viewpoint::setup(float w, float h, float x, float y) {
- window=ofRectangle(w,h,x,y);
- distortFactor=0.0;
- renderFBO.allocate(window.width,window.height,GL_RGB);
+ window=ofRectangle(w,h,x,y);
+ distortFactor=0.0;
+ renderFBO.allocate(window.width,window.height,GL_RGB);
- //todo: load/save from xml
- fov=17.25;
- aspect=1.79;
- near=1;
- far=20;
+ //todo: load/save from xml
+ fov=17.25;
+ aspect=1.79;
+ near=1;
+ far=20;
camera.setParent(target);
- camera.setPosition(0,0,200);
vars=new keyVar[8];
//void set(char _keyInc,char _keyDec,float _val,float _speed,float _accel,float accelTime);
vars[0].set('w','s',17.25,0.5,2.0,3.0);
- vars[1].set('g','d',0.0,0.2,3.0,3.0);
- vars[2].set('r','v',0.0,0.2,3.0,3.0);
- vars[3].set('t','c',0.0,0.2,3.0,3.0);
+ vars[1].set('g','d',0.0,10,3.0,3.0);
+ vars[2].set('r','v',0.0,10,3.0,3.0);
+ vars[3].set('t','c',0.0,10,3.0,3.0);
vars[4].set('u','n',0.0,1.0,3.0,3.0);
- vars[5].set('j','h',0.0,1.0,3.0,3.0);
- vars[6].set('o','l',0.0,0.2,3.0,3.0);
- vars[7].set('q','a',0,0.0001,2.0,3.0);
+ vars[5].set('j','h',0.0,1.0,3.0,3.0);
+ vars[6].set('o','l',1000.0,10,3.0,3.0);
+ vars[7].set('q','a',0,0.0001,2.0,3.0);
+
+ //camera.setPosition(0,0,vars[6].getVal());
}
//--------------------------------------------------------------
void viewpoint::begin(){
- camera.begin();
+
+ renderFBO.begin();
+ ofClear(0,0,0);
+
+ //ofPushView();
+
+ camera.begin();
camera.setFov(vars[0].getVal());
target.setPosition(vars[1].getVal(),vars[2].getVal(),vars[3].getVal());
target.rotate(vars[4].getInc(),1,0,0);
target.rotate(vars[5].getInc(),0,1,0);
- camera.move(0,0,vars[6].getInc());
+ camera.setPosition(0,0,vars[6].getVal());
- renderFBO.begin();
- ofClear(0,0,0);
-}
+
+ }
//--------------------------------------------------------------
void viewpoint::end(){
-
- renderFBO.end();
- camera.end();
-
- ofPushMatrix();
- bindTexture(renderFBO);
-
- //draw a grid
- //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
- ofNoFill();
-
- ofSetLineWidth(1.0);
- //ofSetColor(I_fade1,I_fade1,I_fade1);
- int gridX=50;
- int gridY=50;
- int xStep=ofGetWidth()/2;
- int yStep=ofGetHeight()/2;
- ofTranslate(ofGetWidth()/2,ofGetHeight()/2);
-
- for (float i = -1; i < 1.001; i+=(2.0f/gridY)){
-
- glBegin(GL_QUAD_STRIP);
- ofPoint p0;
- ofPoint p1;
- for (float j = -1; j < 1.001; j+=(2.0f/gridX)){
- p0=distort(ofPoint(j,i-(2.0f/gridY)),vars[7].getVal());
- p1=distort(ofPoint(j,i),vars[7].getVal());
- glTexCoord2f((j+1)*0.5,((i-(2.0f/gridY))+1)*0.5);
- glVertex3f(p0.x*xStep,p0.y*yStep,-0.1);
- glTexCoord2f((j+1)*0.5,(i+1)*0.5);
- glVertex3f(p1.x*xStep,p1.y*yStep,-0.1);
- }
-
- glEnd();
- //
- }
-
- ofFill();
-
- unbindTexture(renderFBO);
-
- ofPopMatrix();
+
+ camera.end();
+ //ofPopView();
+
+ renderFBO.end();
+
+ ofPushMatrix();
+
+ bindTexture(renderFBO);
+
+ //draw a grid
+ //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
+ ofNoFill();
+
+ ofSetLineWidth(1.0);
+ //ofSetColor(I_fade1,I_fade1,I_fade1);
+ int gridX=50;
+ int gridY=50;
+ int xStep=ofGetWidth()/2;
+ int yStep=ofGetHeight()/2;
+ ofTranslate(ofGetWidth()/2,ofGetHeight()/2);
+
+ for (float i = -1; i < 1.001; i+=(2.0f/gridY)){
+
+ glBegin(GL_QUAD_STRIP);
+ ofPoint p0;
+ ofPoint p1;
+ for (float j = -1; j < 1.001; j+=(2.0f/gridX)){
+ p0=distort(ofPoint(j,i-(2.0f/gridY)),vars[7].getVal());
+ p1=distort(ofPoint(j,i),vars[7].getVal());
+ glTexCoord2f((j+1)*0.5,((i-(2.0f/gridY))+1)*0.5);
+ glVertex3f(p0.x*xStep,p0.y*yStep,-0.1);
+ glTexCoord2f((j+1)*0.5,(i+1)*0.5);
+ glVertex3f(p1.x*xStep,p1.y*yStep,-0.1);
+ }
+
+ glEnd();
+ //
+ }
+
+ ofFill();
+
+ unbindTexture(renderFBO);
+
+ ofPopMatrix();
}
//--------------------------------------------------------------