Exemplo n.º 1
0
void ofGLReadyCallback(){

#ifndef TARGET_OPENGLES
	glewExperimental = GL_TRUE;
	GLenum err = glewInit();
	if (GLEW_OK != err)
	{
		/* Problem: glewInit failed, something is seriously wrong. */
		ofLogError("ofAppRunner") << "couldn't init GLEW: " << glewGetErrorString(err);
		return;
	}
#endif

	ofLogVerbose("ofAppRunner") << "GL ready";
	ofLogVerbose("ofAppRunner") << "Vendor:   " << (char*)glGetString(GL_VENDOR);
	ofLogVerbose("ofAppRunner") << "Renderer: " << (char*)glGetString(GL_RENDERER);
	ofLogVerbose("ofAppRunner") << "Version:  " << (char*)glGetString(GL_VERSION);
	ofLogVerbose("ofAppRunner") << "GLSL:     " << (char*)glGetString(GL_SHADING_LANGUAGE_VERSION);

    if(ofGetGLProgrammableRenderer()){
    	ofGetGLProgrammableRenderer()->setup();
    }

	//Default colors etc are now in ofGraphics - ofSetupGraphicDefaults
	ofSetupGraphicDefaults();
	ofBackground(200);
	ofSetVerticalSync(true);
	ofEnableAlphaBlending();
}
Exemplo n.º 2
0
//---------------------------------------------------------------------------
bool ofVideoPlayer::loadMovie(string name){
	if( !player ){
		setPlayer( shared_ptr<OF_VID_PLAYER_TYPE>(new OF_VID_PLAYER_TYPE) );
		player->setPixelFormat(internalPixelFormat);
	}
	
	bool bOk = player->loadMovie(name);
	width	 = player->getWidth();
	height	 = player->getHeight();

	if( bOk){
        moviePath = name;
        if(bUseTexture){
        	if(player->getTexture()==NULL){
				if(width!=0 && height!=0) {
					tex.resize(max(player->getPixels().getNumPlanes(),1));
					for(int i=0;i<player->getPixels().getNumPlanes();i++){
						ofPixels plane = player->getPixels().getPlane(i);
						tex[i].allocate(plane);
						if(ofGetGLProgrammableRenderer() && plane.getPixelFormat() == OF_PIXELS_GRAY){
							tex[i].setRGToRGBASwizzles(true);
						}
					}
				}
        	}else{
        		playerTex = player->getTexture();
        	}
        }
    }
	
	return bOk;
}
Exemplo n.º 3
0
bool ofFbo::checkGLSupport() {
#ifndef TARGET_OPENGLES
	
	if (!ofIsGLProgrammableRenderer()){
		if(ofGLCheckExtension("GL_EXT_framebuffer_object")){
			ofLogVerbose("ofFbo") << "GL frame buffer object supported";
		}else{
			ofLogError("ofFbo") << "GL frame buffer object not supported by this graphics card";
			return false;
		}
	}

	glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &_maxColorAttachments);
	glGetIntegerv(GL_MAX_DRAW_BUFFERS, &_maxDrawBuffers);
	glGetIntegerv(GL_MAX_SAMPLES, &_maxSamples);

	ofLogVerbose("ofFbo") << "checkGLSupport(): "
                          << "maxColorAttachments: " << _maxColorAttachments << ", "
                          << "maxDrawBuffers: " << _maxDrawBuffers << ", "
                          << "maxSamples: " << _maxSamples;
#else

	if(ofGetGLProgrammableRenderer() || ofGLCheckExtension("GL_OES_framebuffer_object")){
		ofLogVerbose("ofFbo") << "GL frame buffer object supported";
	}else{
		ofLogError("ofFbo") << "GL frame buffer object not supported by this graphics card";
		return false;
	}
	string extensions = (char*)glGetString(GL_EXTENSIONS);
	ofLogVerbose("ofFbo") << extensions;
#endif

	return true;
}
Exemplo n.º 4
0
//---------------------------------------------------------------------
void ofDrawBitmapCharacterEnd(){
	if( vC > 0 ){
		charMesh.getVertices().resize(vC);
		charMesh.getTexCoords().resize(vC);
		bitmappedFontTexture.bind();

		ofPtr<ofGLProgrammableRenderer> programmableRenderer = ofGetGLProgrammableRenderer();

		if (!programmableRenderer){
			#ifndef TARGET_OPENGLES
				// this temporarily enables alpha testing,
				// which discards pixels unless their alpha is 1.0f
				glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT);
				glEnable(GL_ALPHA_TEST);
				glAlphaFunc(GL_GREATER, 0);
			#endif
		}else{
			// glPush/PopAttrib is deprecated + we are doing the alpha test through a shader
			programmableRenderer->setAlphaBitmapText(true);
		}

		charMesh.draw();

		if (!programmableRenderer){
			#ifndef TARGET_OPENGLES
				glPopAttrib();
			#endif
		}else{
			programmableRenderer->setAlphaBitmapText(false);
		}

		bitmappedFontTexture.unbind();
	}

}
Exemplo n.º 5
0
//---------------------------------------------------------------------------
bool ofVideoPlayer::loadMovie(string name){
	//#ifndef TARGET_ANDROID
		if( player == NULL ){
			setPlayer( ofPtr<OF_VID_PLAYER_TYPE>(new OF_VID_PLAYER_TYPE) );
			player->setPixelFormat(internalPixelFormat);
		}
	//#endif
	
	bool bOk = player->loadMovie(name);
	width	 = player->getWidth();
	height	 = player->getHeight();

	if( bOk){
        moviePath = name;
        if(bUseTexture ){
            if(width!=0 && height!=0) {
                tex.allocate(width, height, ofGetGLInternalFormatFromPixelFormat(internalPixelFormat));
        		if(ofGetGLProgrammableRenderer() && internalPixelFormat == OF_PIXELS_MONO){
        			tex.setRGToRGBASwizzles(true);
        		}
            }
        }
    }
	
	return bOk;
}
Exemplo n.º 6
0
void ofMaterial::end() {
#ifndef TARGET_PROGRAMMABLE_GL
	if(!ofIsGLProgrammableRenderer()){
	#ifndef TARGET_OPENGLES
		// Set previous material colors and properties
		glMaterialfv(GL_FRONT, GL_DIFFUSE, &prev_data.diffuse.r);
		glMaterialfv(GL_FRONT, GL_SPECULAR, &prev_data.specular.r);
		glMaterialfv(GL_FRONT, GL_AMBIENT, &prev_data.ambient.r);
		glMaterialfv(GL_FRONT, GL_EMISSION, &prev_data.emissive.r);
		glMaterialfv(GL_FRONT, GL_SHININESS, &prev_data.shininess);

		glMaterialfv(GL_BACK, GL_DIFFUSE, &prev_data_back.diffuse.r);
		glMaterialfv(GL_BACK, GL_SPECULAR, &prev_data_back.specular.r);
		glMaterialfv(GL_BACK, GL_AMBIENT, &prev_data_back.ambient.r);
		glMaterialfv(GL_BACK, GL_EMISSION, &prev_data_back.emissive.r);
		glMaterialfv(GL_BACK, GL_SHININESS, &prev_data_back.shininess);
	#else
		// opengl es 1.1 implementation must use GL_FRONT_AND_BACK.

		glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, &prev_data.diffuse.r);
		glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &prev_data.specular.r);
		glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, &prev_data.ambient.r);
		glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, &prev_data.emissive.r);
		glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &prev_data.shininess);
	#endif
	}
#endif
	if(ofIsGLProgrammableRenderer()){
		ofGetGLProgrammableRenderer()->setCurrentMaterial(NULL);
		if(currentShader) currentShader->end();
		currentShader = NULL;
	}
}
Exemplo n.º 7
0
//---------------------------------
int ofGetGlInternalFormat(const ofFloatPixels& pix) {
#ifndef TARGET_OPENGLES
	switch(pix.getNumChannels()) {
		case 3: return GL_RGB32F;
		case 4: return GL_RGBA32F;
		case 2:
			if(ofIsGLProgrammableRenderer()){
				return GL_RG32F;
			}else{
				return GL_LUMINANCE_ALPHA32F_ARB;
			}
		default:
			if(ofGetGLProgrammableRenderer()){
				return GL_R32F;
			}else{
				return GL_LUMINANCE32F_ARB;
			}
	}
#else
	ofLogWarning("ofGLUtils") << "ofGetGlInternalFormat(): float textures not supported in OpenGL ES";
	switch(pix.getNumChannels()) {
		case 3: return GL_RGB;
		case 4: return GL_RGBA;
		case 2:
			return GL_LUMINANCE_ALPHA;
		default:
			return GL_LUMINANCE;
	}
#endif
}
Exemplo n.º 8
0
//--------------------------------------------------------------------
void ofVideoPlayer::update(){
	if( player ){

		player->update();
		width = player->getWidth();
		height = player->getHeight();
		
		if( bUseTexture && player->isFrameNew() ) {
			
			playerTex = player->getTexture();
			
			if(playerTex == NULL){
				if(int(tex.size())!=player->getPixels().getNumPlanes()){
					tex.resize(max(player->getPixels().getNumPlanes(),1));
				}
				if(player->getWidth() != 0 && player->getHeight() != 0) {
					for(int i=0;i<player->getPixels().getNumPlanes();i++){
						ofPixels plane = player->getPixels().getPlane(i);
						bool bDiffPixFormat = ( tex[i].isAllocated() && tex[i].texData.glTypeInternal != ofGetGLInternalFormatFromPixelFormat(plane.getPixelFormat()) );
						if(bDiffPixFormat || !tex[i].isAllocated() || tex[i].getWidth() != plane.getWidth() || tex[i].getHeight() != plane.getHeight()){
							tex[i].allocate(plane);
							if(ofGetGLProgrammableRenderer() && plane.getPixelFormat() == OF_PIXELS_GRAY){
								tex[i].setRGToRGBASwizzles(true);
							}
						}
						tex[i].loadData(plane);
					}
				}
			}
		}
	}
}
Exemplo n.º 9
0
//--------------------------------------------------------------
void ofVbo::setVertexData(const float * vert0x, int numCoords, int total, int usage, int stride) {

#ifdef TARGET_OPENGLES
	if(!vaoChecked){
		if(ofGetGLProgrammableRenderer()){
			glGenVertexArrays = (glGenVertexArraysType)dlsym(RTLD_DEFAULT, "glGenVertexArrays");
			glDeleteVertexArrays =  (glDeleteVertexArraysType)dlsym(RTLD_DEFAULT, "glDeleteVertexArrays");
			glBindVertexArray =  (glBindVertexArrayType)dlsym(RTLD_DEFAULT, "glBindVertexArrayArrays");
		}else{
			glGenVertexArrays = (glGenVertexArraysType)dlsym(RTLD_DEFAULT, "glGenVertexArraysOES");
			glDeleteVertexArrays =  (glDeleteVertexArraysType)dlsym(RTLD_DEFAULT, "glDeleteVertexArraysOES");
			glBindVertexArray =  (glBindVertexArrayType)dlsym(RTLD_DEFAULT, "glBindVertexArrayArraysOES");
		}
		vaoChecked = true;
		supportVAOs = glGenVertexArrays && glDeleteVertexArrays && glBindVertexArray;
	}
#else
	if(!vaoChecked){
		supportVAOs = ofGetGLProgrammableRenderer() || glewIsSupported("GL_ARB_vertex_array_object");
		vaoChecked = true;
	}
#endif


	if(vertId==0) {
		bAllocated  = true;
		bUsingVerts = true;
		vaoChanged=true;
		glGenBuffers(1, &(vertId));
		retain(vertId);
		#if defined(TARGET_ANDROID) || defined(TARGET_OF_IOS)
			registerVbo(this);
		#endif
	}

	vertUsage = usage;
	vertSize = numCoords;
	vertStride = stride==0?3*sizeof(float):stride;
	totalVerts = total;
	
	glBindBuffer(GL_ARRAY_BUFFER, vertId);
	glBufferData(GL_ARRAY_BUFFER, total * stride, vert0x, usage);
	glBindBuffer(GL_ARRAY_BUFFER, 0);

}
Exemplo n.º 10
0
//------------------------------------
void ofVideoPlayer::setUseTexture(bool bUse){
	bUseTexture = bUse;
	if(bUse && width!=0 && height!=0 && !tex.isAllocated()){
		tex.allocate(width, height, ofGetGLTypeFromPixelFormat(internalPixelFormat));
		if(ofGetGLProgrammableRenderer() && internalPixelFormat == OF_PIXELS_MONO){
			tex.setRGToRGBASwizzles(true);
		}
	}
}
Exemplo n.º 11
0
//--------------------------------------------------------------
void ofShader::end()  const{
	if (bLoaded){
		shared_ptr<ofGLProgrammableRenderer> renderer = ofGetGLProgrammableRenderer();
		if(renderer){
			renderer->endCustomShader();
		}else{
			glUseProgram(0);
		}
	}
}
Exemplo n.º 12
0
//--------------------------------------------------------------
void ofShader::begin()  const{
	if (bLoaded){
		glUseProgram(program);
		shared_ptr<ofGLProgrammableRenderer> renderer = ofGetGLProgrammableRenderer();
		if(renderer){
			renderer->beginCustomShader(*this);
		}
	}else{
		ofLogError("ofShader") << "begin(): couldn't begin, shader not loaded";
	}
}
Exemplo n.º 13
0
void ofMaterial::begin() {
#ifndef TARGET_PROGRAMMABLE_GL
	if(!ofIsGLProgrammableRenderer()){
	#ifndef TARGET_OPENGLES
		// save previous values, opengl es cannot use push/pop attrib
		glGetMaterialfv(GL_FRONT,GL_DIFFUSE,&prev_data.diffuse.r);
		glGetMaterialfv(GL_FRONT,GL_SPECULAR,&prev_data.specular.r);
		glGetMaterialfv(GL_FRONT,GL_AMBIENT,&prev_data.ambient.r);
		glGetMaterialfv(GL_FRONT,GL_EMISSION,&prev_data.emissive.r);
		glGetMaterialfv(GL_FRONT, GL_SHININESS, &prev_data.shininess);

		glGetMaterialfv(GL_BACK,GL_DIFFUSE,&prev_data_back.diffuse.r);
		glGetMaterialfv(GL_BACK,GL_SPECULAR,&prev_data_back.specular.r);
		glGetMaterialfv(GL_BACK,GL_AMBIENT,&prev_data_back.ambient.r);
		glGetMaterialfv(GL_BACK,GL_EMISSION,&prev_data_back.emissive.r);
		glGetMaterialfv(GL_BACK, GL_SHININESS, &prev_data_back.shininess);

		// Material colors and properties
		glMaterialfv(GL_FRONT, GL_DIFFUSE, &data.diffuse.r);
		glMaterialfv(GL_FRONT, GL_SPECULAR, &data.specular.r);
		glMaterialfv(GL_FRONT, GL_AMBIENT, &data.ambient.r);
		glMaterialfv(GL_FRONT, GL_EMISSION, &data.emissive.r);
		glMaterialfv(GL_FRONT, GL_SHININESS, &data.shininess);

		glMaterialfv(GL_BACK, GL_DIFFUSE, &data.diffuse.r);
		glMaterialfv(GL_BACK, GL_SPECULAR, &data.specular.r);
		glMaterialfv(GL_BACK, GL_AMBIENT, &data.ambient.r);
		glMaterialfv(GL_BACK, GL_EMISSION, &data.emissive.r);
		glMaterialfv(GL_BACK, GL_SHININESS, &data.shininess);
	#elif !defined(TARGET_PROGRAMMABLE_GL)
		// opengl es 1.1 implementation must use GL_FRONT_AND_BACK.

		glGetMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, &prev_data.diffuse.r);
		glGetMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &prev_data.specular.r);
		glGetMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, &prev_data.ambient.r);
		glGetMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, &prev_data.emissive.r);
		glGetMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &prev_data.shininess);

		glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, &data.diffuse.r);
		glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &data.specular.r);
		glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, &data.ambient.r);
		glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, &data.emissive.r);
		glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &data.shininess);
	#endif
	}
#endif
	if(ofIsGLProgrammableRenderer()){
		ofGetGLProgrammableRenderer()->setCurrentMaterial(this);
	}
}
Exemplo n.º 14
0
//------------------------------------
void ofVideoPlayer::setUseTexture(bool bUse){
	bUseTexture = bUse;
	if(bUse && player && !player->getTexture() && getWidth()!=0 && getHeight()!=0){
		for(int i=0;i<player->getPixels().getNumPlanes();i++){
			ofPixels plane = player->getPixels().getPlane(i);
			bool bDiffPixFormat = ( tex[i].bAllocated() && tex[i].texData.glTypeInternal != ofGetGLInternalFormatFromPixelFormat(plane.getPixelFormat()) );
			if(!tex[i].isAllocated() || bDiffPixFormat){
				tex[i].allocate(plane);
			}
			if(ofGetGLProgrammableRenderer() && plane.getPixelFormat() == OF_PIXELS_GRAY){
				tex[i].setRGToRGBASwizzles(true);
			}
		}
	}
}
Exemplo n.º 15
0
void ofImage_<PixelType>::rotate90(int nRotations){
	int myOldWidth = pixels.getWidth();
	int myOldHeight = pixels.getHeight();
	pixels.rotate90(nRotations);
	if (myOldWidth != pixels.getWidth() || myOldHeight != pixels.getHeight()){
		if (bUseTexture){
			tex.clear();
			tex.allocate(pixels.getWidth(), pixels.getHeight(), ofGetGlInternalFormat(pixels));
			if(ofGetGLProgrammableRenderer() && (pixels.getNumChannels()==1 || pixels.getNumChannels()==2)){
				tex.setRGToRGBASwizzles(true);
			}
		}
	}
	update();
}
Exemplo n.º 16
0
void ofApp::drawModels() {
    ofSetColor(255);
    
    ofEnableBlendMode(OF_BLENDMODE_ALPHA);
    
	ofEnableDepthTest();
    
    glShadeModel(GL_SMOOTH); //some model / light stuff
    light.enable();
    ofEnableSeparateSpecularLight();


    for (int i = 0; i < models.size(); i++) {
        ofPushMatrix();
        models[i]->drawFaces();
        ofPopMatrix();
    }
    //model.setScale(.3, .3, .3);
    //model.drawFaces();
 
    
    if(ofGetGLProgrammableRenderer()){
		glPushAttrib(GL_ALL_ATTRIB_BITS);
		glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
    }
    glEnable(GL_NORMALIZE);
    
    if(ofGetGLProgrammableRenderer()){
    	glPopAttrib();
    }
    
    ofDisableDepthTest();
    light.disable();
    ofDisableLighting();
    ofDisableSeparateSpecularLight();
}
Exemplo n.º 17
0
void ofImage_<PixelType>::update(){
	width = pixels.getWidth();
	height = pixels.getHeight();
	bpp = pixels.getBitsPerPixel();
	type = pixels.getImageType();
	if (pixels.isAllocated() && bUseTexture){
		int glTypeInternal = ofGetGlInternalFormat(pixels);
		if(!tex.isAllocated() || tex.getWidth() != width || tex.getHeight() != height || tex.getTextureData().glTypeInternal != glTypeInternal){
			tex.allocate(pixels.getWidth(), pixels.getHeight(), glTypeInternal);
			if(ofGetGLProgrammableRenderer() && (pixels.getNumChannels()==1 || pixels.getNumChannels()==2)){
				tex.setRGToRGBASwizzles(true);
			}
		}
		tex.loadData(pixels);
	}
}
Exemplo n.º 18
0
void ofImage_<PixelType>::changeTypeOfPixels(ofPixels_<PixelType> &pix, ofImageType newType){
	int oldType = pix.getImageType();
		
	if (oldType == newType) {
		return; // no need to reallocate
	}

	FIBITMAP * bmp = getBmpFromPixels(pix);
	FIBITMAP * convertedBmp = NULL;

	switch (newType){
		case OF_IMAGE_GRAYSCALE:
			convertedBmp = FreeImage_ConvertToGreyscale(bmp);
			break;
		case OF_IMAGE_COLOR:
			convertedBmp = FreeImage_ConvertTo24Bits(bmp);
			break;
		case OF_IMAGE_COLOR_ALPHA:
			convertedBmp = FreeImage_ConvertTo32Bits(bmp);
			break;
		default:
			ofLogError("ofImage") << "changeTypeOfPixels(): unknown image type: " << newType;
			break;
	}
	
	putBmpIntoPixels(convertedBmp, pix, false);

	if (bmp != NULL) {
		FreeImage_Unload(bmp);
	}
	if (convertedBmp != NULL) {
		FreeImage_Unload(convertedBmp);
	}

	if(bUseTexture){
		// always reallocate the texture. if ofTexture doesn't need reallocation,
		// it doesn't have to. but it needs to change the internal format.
		tex.allocate(pixels.getWidth(), pixels.getHeight(), ofGetGlInternalFormat(pixels));
		if(ofGetGLProgrammableRenderer() && (pixels.getNumChannels()==1 || pixels.getNumChannels()==2)){
			tex.setRGToRGBASwizzles(true);
		}
	}
}
Exemplo n.º 19
0
void ofAppAndroidWindow::setupOpenGL(int w, int h, ofWindowMode screenMode){
	jclass javaClass = ofGetJNIEnv()->FindClass("cc/openframeworks/OFAndroid");

	if(javaClass==0){
		ofLogError("ofAppAndroidWindow") << "setupOpenGL(): couldn't find OFAndroid java class";
		return;
	}

	jmethodID method = ofGetJNIEnv()->GetStaticMethodID(javaClass,"setupGL","(I)V");
	if(!method){
		ofLogError("ofAppAndroidWindow") << "setupOpenGL(): couldn't find OFAndroid setupGL method";
		return;
	}

	if(ofGetGLProgrammableRenderer())
		ofGetJNIEnv()->CallStaticVoidMethod(javaClass,method,2);
	else
		ofGetJNIEnv()->CallStaticVoidMethod(javaClass,method,1);
}
Exemplo n.º 20
0
bool ofImage_<PixelType>::loadImage(const ofBuffer & buffer){
#if defined(TARGET_ANDROID) || defined(TARGET_OF_IOS)
	registerImage(this);
#endif
	bool bLoadedOk = ofLoadImage(pixels, buffer);
	if (!bLoadedOk) {
		ofLogError("ofImage") << "loadImage(): couldn't load image from ofBuffer";
		clear();
		return false;
	}
	if (bLoadedOk && pixels.isAllocated() && bUseTexture){
		tex.allocate(pixels.getWidth(), pixels.getHeight(), ofGetGlInternalFormat(pixels));
		if(ofGetGLProgrammableRenderer() && (pixels.getNumChannels()==1 || pixels.getNumChannels()==2)){
			tex.setRGToRGBASwizzles(true);
		}
	}
	update();
	return bLoadedOk;
}
Exemplo n.º 21
0
//--------------------------------------------------------------------
bool ofVideoGrabber::initGrabber(int w, int h, bool setUseTexture){

#ifndef OF_VID_GRABBER_TYPE
#error OF_VID_GRABBER_TYPE is not #defined! 
#endif
    
	if(!grabber){
		setGrabber( shared_ptr<OF_VID_GRABBER_TYPE>(new OF_VID_GRABBER_TYPE) );
	}

	bUseTexture = setUseTexture;

	if( RequestedDeviceID >= 0 ){
		grabber->setDeviceID(RequestedDeviceID);
	}

	setPixelFormat(internalPixelFormat); //this safely handles checks for supported format

	if( desiredFramerate!=-1 ){
		grabber->setDesiredFrameRate(desiredFramerate);
	}

	grabber->initGrabber(w, h);
	width			= (int)grabber->getWidth();
	height			= (int)grabber->getHeight();

	if( grabber->isInitialized() && bUseTexture ){
		if(!grabber->getTexture()){
			for(int i=0;i<grabber->getPixelsRef().getNumPlanes();i++){
				ofPixels plane = grabber->getPixelsRef().getPlane(i);
				tex.push_back(ofTexture());
				tex[i].allocate(plane);
				if(ofGetGLProgrammableRenderer() && plane.getPixelFormat() == OF_PIXELS_GRAY){
					tex[i].setRGToRGBASwizzles(true);
				}
			}
		}
	}

	return grabber->isInitialized();
}
Exemplo n.º 22
0
void ofImage_<PixelType>::cropFrom(ofImage_<PixelType> & otherImage, int x, int y, int w, int h){
	w = ofClamp(w,1,otherImage.getWidth());
	h = ofClamp(h,1,otherImage.getHeight());

	int myOldWidth = pixels.getWidth();
	int myOldHeight = pixels.getHeight();

	otherImage.pixels.cropTo(pixels, x, y, w, h);

	if (myOldWidth != pixels.getWidth() || myOldHeight != pixels.getHeight()){
		if (bUseTexture){
			tex.clear();
			tex.allocate(pixels.getWidth(), pixels.getHeight(), ofGetGlInternalFormat(pixels));
			if(ofGetGLProgrammableRenderer() && (pixels.getNumChannels()==1 || pixels.getNumChannels()==2)){
				tex.setRGToRGBASwizzles(true);
			}
		}
	}

	update();
}
Exemplo n.º 23
0
ofFbo::ofFbo():
isBound(0),
fbo(0),
fboTextures(0),
depthBuffer(0),
stencilBuffer(0),
savedFramebuffer(0),
dirty(false),
defaultTextureIndex(0),
bIsAllocated(false)
{
#ifdef TARGET_OPENGLES
	if(!bglFunctionsInitialized){
		if(ofGetGLProgrammableRenderer()){
			glGenFramebuffers = (glGenFramebuffersType)dlsym(RTLD_DEFAULT, "glGenFramebuffers");
			glDeleteFramebuffers =  (glDeleteFramebuffersType)dlsym(RTLD_DEFAULT, "glDeleteFramebuffers");
			glDeleteRenderbuffers =  (glDeleteRenderbuffersType)dlsym(RTLD_DEFAULT, "glDeleteRenderbuffers");
			glBindFramebuffer =  (glBindFramebufferType)dlsym(RTLD_DEFAULT, "glBindFramebuffer");
			glBindRenderbuffer = (glBindRenderbufferType)dlsym(RTLD_DEFAULT, "glBindRenderbuffer");
			glRenderbufferStorage = (glRenderbufferStorageType)dlsym(RTLD_DEFAULT, "glRenderbufferStorage");
			glFramebufferRenderbuffer = (glFramebufferRenderbufferType)dlsym(RTLD_DEFAULT, "glFramebufferRenderbuffer");
			glRenderbufferStorageMultisample = (glRenderbufferStorageMultisampleType)dlsym(RTLD_DEFAULT, "glRenderbufferStorageMultisample");
			glFramebufferTexture2D = (glFramebufferTexture2DType)dlsym(RTLD_DEFAULT, "glFramebufferTexture2D");
			glCheckFramebufferStatus = (glCheckFramebufferStatusType)dlsym(RTLD_DEFAULT, "glCheckFramebufferStatus");
		}else{
			glGenFramebuffers = (glGenFramebuffersType)dlsym(RTLD_DEFAULT, "glGenFramebuffersOES");
			glDeleteFramebuffers = (glDeleteFramebuffersType)dlsym(RTLD_DEFAULT, "glDeleteFramebuffersOES");
			glDeleteRenderbuffers = (glDeleteRenderbuffersType)dlsym(RTLD_DEFAULT, "glDeleteRenderbuffersOES");
			glBindFramebuffer = (glBindFramebufferType)dlsym(RTLD_DEFAULT, "glBindFramebufferOES");
			glBindRenderbuffer = (glBindRenderbufferType)dlsym(RTLD_DEFAULT, "glBindRenderbufferOES");
			glRenderbufferStorage = (glRenderbufferStorageType)dlsym(RTLD_DEFAULT, "glRenderbufferStorageOES");
			glFramebufferRenderbuffer = (glFramebufferRenderbufferType)dlsym(RTLD_DEFAULT, "glFramebufferRenderbufferOES");
			glRenderbufferStorageMultisample = (glRenderbufferStorageMultisampleType)dlsym(RTLD_DEFAULT, "glRenderbufferStorageMultisampleOES");
			glFramebufferTexture2D = (glFramebufferTexture2DType)dlsym(RTLD_DEFAULT, "glFramebufferTexture2DOES");
			glCheckFramebufferStatus = (glCheckFramebufferStatusType)dlsym(RTLD_DEFAULT, "glCheckFramebufferStatusOES");
		}
	}
#endif
}
Exemplo n.º 24
0
//--------------------------------------------------------------------
void ofVideoGrabber::update(){
	if(grabber){
		grabber->update();
		width = grabber->getWidth();
		height = grabber->getHeight();
		if( bUseTexture && !grabber->getTexture() && grabber->isFrameNew() ){
			if(int(tex.size())!=grabber->getPixelsRef().getNumPlanes()){
				tex.resize(grabber->getPixelsRef().getNumPlanes());
			}
			for(int i=0;i<grabber->getPixelsRef().getNumPlanes();i++){
				ofPixels plane = grabber->getPixelsRef().getPlane(i);
				bool bDiffPixFormat = ( tex[i].isAllocated() && tex[i].texData.glTypeInternal != ofGetGLInternalFormatFromPixelFormat(plane.getPixelFormat()) );
				if(width==0 || height==0 || bDiffPixFormat || !tex[i].isAllocated() ){
					tex[i].allocate(plane);
					if(ofGetGLProgrammableRenderer() && plane.getPixelFormat() == OF_PIXELS_GRAY){
						tex[i].setRGToRGBASwizzles(true);
					}
				}
				tex[i].loadData(plane);
			}
		}
	}
}
Exemplo n.º 25
0
void ofImage_<PixelType>::allocate(int w, int h, ofImageType newType){
	
	if (width == w && height == h && newType == type){
		return;
	}
#if defined(TARGET_ANDROID) || defined(TARGET_OF_IOS)
	registerImage(this);
#endif
	pixels.allocate(w, h, newType);

	// take care of texture allocation --
	if (pixels.isAllocated() && bUseTexture){
		tex.allocate(pixels.getWidth(), pixels.getHeight(), ofGetGlInternalFormat(pixels));
		if(ofGetGLProgrammableRenderer() && (pixels.getNumChannels()==1 || pixels.getNumChannels()==2)){
			tex.setRGToRGBASwizzles(true);
		}
	}
	
	width	= pixels.getWidth();
	height	= pixels.getHeight();
	bpp		= pixels.getBitsPerPixel();
	type	= pixels.getImageType();
}
Exemplo n.º 26
0
//--------------------------------------------------------------------
void ofVideoPlayer::update(){
	if(	player != NULL ){

		player->update();
		
		if( bUseTexture && player->isFrameNew() ) {
			
			playerTex = player->getTexture();
			
			if(playerTex == NULL){
				unsigned char *pxls = player->getPixels();
				
				bool bDiffPixFormat = ( tex.bAllocated() && tex.texData.glTypeInternal != ofGetGLInternalFormatFromPixelFormat(internalPixelFormat) );
				
				//TODO: we might be able to do something smarter here for not re-allocating movies of the same size and type. 
				if(width==0 || height==0 || bDiffPixFormat ){ //added a check if the pixel format and the texture don't match
					if(player->getWidth() != 0 && player->getHeight() != 0) {
						
						width = player->getWidth();
						height = player->getHeight();
					
						if(tex.bAllocated())
							tex.clear();

						tex.allocate(width, height, ofGetGLInternalFormatFromPixelFormat(internalPixelFormat));
		        		if(ofGetGLProgrammableRenderer() && internalPixelFormat == OF_PIXELS_MONO){
		        			tex.setRGToRGBASwizzles(true);
		        		}
						tex.loadData(pxls, tex.getWidth(), tex.getHeight(), ofGetGLTypeFromPixelFormat(internalPixelFormat));
					}
				}else{					
					tex.loadData(pxls, width, height, ofGetGLTypeFromPixelFormat(internalPixelFormat));
				}
			}
		}
	}
}
Exemplo n.º 27
0
//--------------------------------------------------------------------
bool ofVideoGrabber::initGrabber(int w, int h, bool setUseTexture){

#ifndef OF_VID_GRABBER_TYPE
#error OF_VID_GRABBER_TYPE is not #defined! 
#endif
    
	if( grabber == NULL ){
		setGrabber( ofPtr<OF_VID_GRABBER_TYPE>(new OF_VID_GRABBER_TYPE) );
	}

	bInitialized = true;
	bUseTexture = setUseTexture;

	if( RequestedDeviceID >= 0 ){
		grabber->setDeviceID(RequestedDeviceID);
	}

	setPixelFormat(internalPixelFormat); //this safely handles checks for supported format

	if( desiredFramerate!=-1 ){
		grabber->setDesiredFrameRate(desiredFramerate);
	}

	grabberRunning	= grabber->initGrabber(w, h);
	width			= (int)grabber->getWidth();
	height			= (int)grabber->getHeight();

	if( grabberRunning && bUseTexture ){
		if(!grabber->getTexture()) tex.allocate(width, height, ofGetGLInternalFormatFromPixelFormat(internalPixelFormat));
		if(ofGetGLProgrammableRenderer() && internalPixelFormat == OF_PIXELS_MONO){
			tex.setRGToRGBASwizzles(true);
		}
	}

	return grabberRunning;
}
Exemplo n.º 28
0
/** @brief Draws x,y,z axes representing the current reference frame
 *  @detail Axes are drawn in red (+x), green (+y) and blue (+z)
 *	@param size size at which to draw the axes
 **/
void ofDrawAxis(float size) {
	if (ofGetGLProgrammableRenderer()){
		ofPushMatrix();
		ofScale(size, size,size);
		cachedAxesVbo().draw();
		ofPopMatrix();
	} else {
		ofPushStyle();
		ofSetLineWidth(3);
		
		// draw x axis
		ofSetColor(ofColor::red);
		ofLine(0, 0, 0, size, 0, 0);
		
		// draw y axis
		ofSetColor(ofColor::green);
		ofLine(0, 0, 0, 0, size, 0);
		
		// draw z axis
		ofSetColor(ofColor::blue);
		ofLine(0, 0, 0, 0, 0, size);
		ofPopStyle();
	}
}
Exemplo n.º 29
0
//--------------------------------------------------------------
void ofApp::setup(){
  ofBackground(34, 34, 34);
  ofSetVerticalSync(true);
  ofSetFrameRate(0);
//  ofDisableAntiAliasing();
  ofDisableLighting();
//  ofDisableAlphaBlending();
//  ofEnableNormalizedTexCoords();
//  ofDisableArbTex();
  ofEnableArbTex();
//  ofDisableNormalizedTexCoords();
  ofDisableTextureEdgeHack();
//  ofDisableSmoothing();
  ofSetMinMagFilters(GL_NEAREST, GL_NEAREST);
//  ofEnableAlphaBlending();

  img_size = 4096.;
  fbo_size = 8192.;
  w = img_size;
  h = img_size;
  scale_display = 5.7;
  scale_target = scale_display;

//  colorPixels = new unsigned char [w*h*3];
  doShader = true;
  frame_num = 0;
  record_num = 0;
  time_step = 0;
  pick_step = 1;
  animate = false;
  camera_lock = false;
  camera_home = false;
  record = false;
  showFPS = false;

  font.loadFont("type/verdana.ttf", 10);

  quad.clear();
  quad.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);
  quad.addVertex(ofVec3f(0, 0, 0));
  quad.addVertex(ofVec3f(w, 0, 0));
  quad.addVertex(ofVec3f(0, h, 0));
  quad.addVertex(ofVec3f(w, h, 0));

  img_00.loadImage("images/d7f_4k_01.png");
  img_01.loadImage("images/d7f_4k_02.png");
  img_02.loadImage("images/d7f_4k_03.png");
  img_03.loadImage("images/d7f_4k_04.png");
//  img_00.loadImage("images/micro_01.jpg");
//  img_01.loadImage("images/micro_02.jpg");
//  img_02.loadImage("images/micro_03.jpg");
//  img_03.loadImage("images/micro_04.jpg");

  /////////////////////////////////////////////////////////////////////////////
  // Framebuffers, allocation, etc
  /////////////////////////////////////////////////////////////////////////////
//  height.allocate(w,h,GL_RGB);
  height0.allocate(w,h,GL_RGB);
  height1.allocate(w,h,GL_RGB);
  height2.allocate(w,h/2,GL_RGB);
  height3.allocate(w,h/2,GL_RGB);

//  height_old.allocate(w,h,GL_RGB);
//  height_backup.allocate(w,h,GL_RGB);
  display.allocate(ofGetWidth(),ofGetHeight(),GL_RGB);

//  height_FBO.allocate(w,h,GL_RGB);
  height_Fbo0.allocate(w,h,GL_RGB);
  height_Fbo1.allocate(w,h,GL_RGB);
  height_Fbo2.allocate(w,h/2,GL_RGB);
  height_Fbo3.allocate(w,h/2,GL_RGB);
//  height_old_FBO.allocate(w,h,GL_RGB);
  height_old_Fbo0.allocate(w,h,GL_RGB);
  height_old_Fbo1.allocate(w,h,GL_RGB);
  height_old_Fbo2.allocate(w,h/2,GL_RGB);
  height_old_Fbo3.allocate(w,h/2,GL_RGB);
//  height_backup_FBO.allocate(w,h,GL_RGB);
  height_backup_Fbo0.allocate(w,h,GL_RGB);
  height_backup_Fbo1.allocate(w,h,GL_RGB);
  height_backup_Fbo2.allocate(w,h/2,GL_RGB);
  height_backup_Fbo3.allocate(w,h/2,GL_RGB);

  ClearFramebuffers();
  DisableInterpolation();


  /////////////////////////////////////////////////////////////////////////////
  // end framebuffers
  /////////////////////////////////////////////////////////////////////////////


//  #ifdef TARGET_OPENGLES
//    shader.load("shaders_gles/noise.vert","shaders_gles/noise.frag");
//  #else
    if(ofGetGLProgrammableRenderer()){
      shader.load("shaders_gl3/noise.vert", "shaders_gl3/noise.frag");
      waveShader.load("shaders_gl3/wave.vert", "shaders_gl3/wave.frag");
      waveShaderTiled.load("shaders_gl3/wave_tiled.vert", "shaders_gl3/wave_tiled.frag");
      waveShader_display.load("shaders_gl3/wave_DISPLAY.vert",
                              "shaders_gl3/wave_DISPLAY.frag");
      waveShader_displayTiled.load("shaders_gl3/wave_DISPLAY_tiled.vert",
                                    "shaders_gl3/wave_DISPLAY_tiled.frag");
      waveShaderMod.load("shaders_gl3/wave_mod.vert", "shaders_gl3/wave_mod.frag");
    }
    else{
      shader.load("shaders/noise.vert", "shaders/noise.frag");
    }
//  #endif


}
Exemplo n.º 30
0
//--------------------------------------------------------------
void ofVbo::bind(){
	if(supportVAOs){
		if(vaoID==0){
			glGenVertexArrays(1, &vaoID);
			if(vaoID!=0){
				retainVAO(vaoID);
			}else{
				supportVAOs = false;
				ofLogVerbose("ofVbo") << "bind(): error allocating VAO, disabling VAO support";
			}
		}

		glBindVertexArray(vaoID);
	}

	if(vaoChanged || !supportVAOs){
		bool programmable = ofIsGLProgrammableRenderer();
		if(bUsingVerts){
			glBindBuffer(GL_ARRAY_BUFFER, vertId);
			if(!programmable){
				glEnableClientState(GL_VERTEX_ARRAY);
				glVertexPointer(vertSize, GL_FLOAT, vertStride, 0);
			}else{
				glEnableVertexAttribArray(ofShader::POSITION_ATTRIBUTE);
				glVertexAttribPointer(ofShader::POSITION_ATTRIBUTE, vertSize, GL_FLOAT, GL_FALSE, vertStride, 0);
			}
		}else if(supportVAOs){
			if(!programmable){
				glDisableClientState(GL_VERTEX_ARRAY);
			}else{
				glDisableVertexAttribArray(ofShader::POSITION_ATTRIBUTE);
			}
		}

		if(bUsingColors) {
			glBindBuffer(GL_ARRAY_BUFFER, colorId);
			if(!programmable){
				glEnableClientState(GL_COLOR_ARRAY);
				glColorPointer(4, GL_FLOAT, colorStride, 0);
			}else{
				glEnableVertexAttribArray(ofShader::COLOR_ATTRIBUTE);
				glVertexAttribPointer(ofShader::COLOR_ATTRIBUTE, 4, GL_FLOAT, GL_FALSE, colorStride, 0);
			}
		}else if(supportVAOs){
			if(!programmable){
				glDisableClientState(GL_COLOR_ARRAY);
			}else{
				glDisableVertexAttribArray(ofShader::COLOR_ATTRIBUTE);
			}
		}

		if(bUsingNormals) {
			glBindBuffer(GL_ARRAY_BUFFER, normalId);
			if(!programmable){
				glEnableClientState(GL_NORMAL_ARRAY);
				glNormalPointer(GL_FLOAT, normalStride, 0);
			}else{
				// tig: note that we set the 'Normalize' flag to true here, assuming that mesh normals need to be
				// normalized while being uploaded to GPU memory.
				// http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribPointer.xml
				// Normalizing the normals on the shader is probably faster, but sending non-normalized normals is
				// more prone to lead to artifacts difficult to diagnose, especially with the built-in 3D primitives.
				// If you need to optimise this, and you've dug this far through the code, you are most probably
				// able to roll your own client code for binding & rendering vbos anyway...
				glEnableVertexAttribArray(ofShader::NORMAL_ATTRIBUTE);
				glVertexAttribPointer(ofShader::NORMAL_ATTRIBUTE, 3, GL_FLOAT, GL_TRUE, normalStride, 0);
			}
		}else if(supportVAOs){
			if(!programmable){
				glDisableClientState(GL_NORMAL_ARRAY);
			}else{
				glDisableVertexAttribArray(ofShader::NORMAL_ATTRIBUTE);
			}
		}

		if(bUsingTexCoords) {
			glBindBuffer(GL_ARRAY_BUFFER, texCoordId);
			if(!programmable){
				glEnableClientState(GL_TEXTURE_COORD_ARRAY);
				glTexCoordPointer(2, GL_FLOAT, texCoordStride, 0);
			}else{
				glEnableVertexAttribArray(ofShader::TEXCOORD_ATTRIBUTE);
				glVertexAttribPointer(ofShader::TEXCOORD_ATTRIBUTE, 2, GL_FLOAT, GL_FALSE, texCoordStride, 0);
			}
		}else if(supportVAOs){
			if(!programmable){
				glDisableClientState(GL_TEXTURE_COORD_ARRAY);
			}else{
				glDisableVertexAttribArray(ofShader::TEXCOORD_ATTRIBUTE);
			}
		}

		map<int,GLuint>::iterator it;
		for(it=attributeIds.begin();it!=attributeIds.end();it++){
			glBindBuffer(GL_ARRAY_BUFFER, attributeIds[it->first]);
			glEnableVertexAttribArray(it->first);
			glVertexAttribPointer(it->first, attributeNumCoords[it->first], GL_FLOAT, GL_FALSE, attributeStrides[it->first], 0);
		}

		vaoChanged=false;
	}


	ofPtr<ofGLProgrammableRenderer> renderer = ofGetGLProgrammableRenderer();
	if(renderer){
		renderer->setAttributes(bUsingVerts,bUsingColors,bUsingTexCoords,bUsingNormals);
	}
	bBound   = true;
}