test-shader.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "GUI/ViewPort3D.H"
00038 #include "Util/log.H"
00039 #include "Util/WorkThreadServer.H"
00040 #include "Util/JobWithSemaphore.H"
00041 #include "Component/ModelManager.H"
00042 #include "Raster/GenericFrame.H"
00043 #include "Image/Layout.H"
00044 #include "Image/MatrixOps.H"
00045 #include "Image/DrawOps.H"
00046 #include "GUI/DebugWin.H"
00047 #include "Media/FrameSeries.H"
00048 #include "Transport/FrameInfo.H"
00049 #include <stdlib.h>
00050 #include <math.h>
00051
00052 #include "GUI/XWinManaged.H"
00053 #include "GUI/ImageDisplayStream.H"
00054
00055
00056 int main(int argc, char *argv[]){
00057
00058 ModelManager manager("Test Viewport");
00059
00060 nub::ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager));
00061 manager.addSubComponent(ofs);
00062
00063 nub::ref<InputFrameSeries> ifs(new InputFrameSeries(manager));
00064 manager.addSubComponent(ifs);
00065
00066
00067
00068 if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1);
00069
00070 manager.start();
00071
00072 ViewPort3D vp(320,240, false, false, false);
00073
00074
00075
00076 vp.setCamera(Point3D<float>(0,0,100), Point3D<float>(0,0,0));
00077
00078 vp.initFrame();
00079 Image<PixRGB<byte> > tmp(320,240,ZEROS);
00080 uint texId = vp.addTexture(tmp);
00081
00082 GLhandleARB prog1 = vp.createShader("src/Image/OpenGlShaders/sobel.frag", GL_FRAGMENT_SHADER_ARB);
00083 GLhandleARB prog2 = vp.createShader("src/Image/OpenGlShaders/nonmaxsupp.frag", GL_FRAGMENT_SHADER_ARB);
00084
00085 float texCoordOffsets[18];
00086 float xInc = 1.0/ float(320);
00087 float yInc = 1.0/ float(240);
00088 for(int i=0; i<3; i++)
00089 for(int j=0; j<3; j++)
00090 {
00091 texCoordOffsets[(((i*3)+j)*2)+0] = (-1.0 * xInc) + ( float(i) * xInc);
00092 texCoordOffsets[(((i*3)+j)*2)+1] = (-1.0 * yInc) + ( float(j) * yInc);
00093 }
00094
00095 glUseProgramObjectARB(prog1);
00096 int uniformLoc = glGetUniformLocationARB(prog1, "tc_offset" );
00097 if( uniformLoc != -1 )
00098 glUniform2fvARB( uniformLoc, 9, texCoordOffsets );
00099 else
00100 LINFO("error. could not find uniformLoc for variable tc_offset");
00101
00102 glUseProgramObjectARB(prog2);
00103 uniformLoc = glGetUniformLocationARB(prog2, "tc_offset" );
00104 if( uniformLoc != -1 )
00105 glUniform2fvARB( uniformLoc, 9, texCoordOffsets );
00106 else
00107 LINFO("error. could not find uniformLoc for variable tc_offset");
00108
00109
00110
00111
00112
00113
00114 while(1)
00115 {
00116 Image< PixRGB<byte> > inputImg;
00117 ifs->updateNext();
00118 const FrameState is = ifs->updateNext();
00119 if (is == FRAME_COMPLETE)
00120 break;
00121
00122
00123 GenericFrame input = ifs->readFrame();
00124 if (!input.initialized())
00125 break;
00126 inputImg = input.asRgb();
00127
00128
00129 Image<float> texImg = luminance(inputImg);
00130
00131 vp.loadTexture(texImg, texId);
00132 vp.progToTexture(prog1);
00133
00134 glUseProgramObjectARB(prog2);
00135
00136 vp.initProjection();
00137 glBegin(GL_QUADS);
00138 glTexCoord2f(0.0, 0.0); glVertex3f(0, 0, 0);
00139 glTexCoord2f(1.0, 0.0); glVertex3f(320, 0, 0);
00140 glTexCoord2f(1.0, 1.0); glVertex3f(320, 240 , 0);
00141 glTexCoord2f(0.0, 1.0); glVertex3f(0, 240, 0);
00142 glEnd();
00143
00144
00145 Image<PixRGB<float> > img = vp.getFrameFloat();
00146
00147 Image<float> tmp(img.getDims(), ZEROS);
00148 for(uint i=0; i < img.size(); i++)
00149 tmp.setVal(i, img.getVal(i).red());
00150 tmp *= 256;
00151
00152 img = tmp;
00153
00154 ofs->writeRGB(img, "output", FrameInfo("output", SRC_POS));
00155 usleep(10000);
00156 }
00157
00158 manager.stop();
00159 exit(0);
00160
00161 }
00162
00163