ofFbo and GL_CULL_FACE does not work together [SOLVED]

Hello. I am trying to render the inside of a 3D object via ofCamera and within ofFbo. It works well without using ofFbo, but once I use it, glEnable(GL_CULL_FACE); does not work;

Code without using ofFbo and a screenshot

void ofApp::setup(){
	ofBackground(0);
	ofEnableNormalizedTexCoords();

	texture.load("PANORAMA.png");
	texture.mirror(true, true);
	
	sphere.setResolution(20);
	sphere.setRadius(200);
	
	camera.setPosition(ofVec3f(300, 300, 300));
	camera.lookAt(ofVec3f(0, 0, 0));
}

void ofApp::draw(){
	camera.begin();
	
		ofEnableDepthTest();
		glEnable(GL_CULL_FACE);
		glCullFace(GL_BACK);
	
		texture.bind();
		sphere.draw();
		texture.unbind();
	
	camera.end();
}

Code with using ofFbo and a screenshot

void ofApp::setup(){
	ofBackground(0);
	ofEnableNormalizedTexCoords();

	texture.load("PANORAMA.png");
	texture.mirror(true, true);
	
	sphere.setResolution(20);
	sphere.setRadius(200);
	
	camera.setPosition(ofVec3f(300, 300, 300));
	camera.lookAt(ofVec3f(0, 0, 0));
	
	fbo.allocate(ofGetWidth(), ofGetHeight());
	fbo.begin();
	ofClear(0, 0, 0, 0);
	fbo.end();
}

void ofApp::draw(){
	fbo.begin();
	camera.begin();
	
		ofEnableDepthTest();
		glEnable(GL_CULL_FACE);
		glCullFace(GL_BACK);
	
		texture.bind();
		sphere.draw();
		texture.unbind();
	
	camera.end();
	fbo.end();
	
	fbo.draw(0, 0);
}

`

As you see, it does not work. Is there a trick to make it work?

The problem was not GL_CULL_FACE (although no ofFbo GL_FRONT and GL_BACK seems to be flipped). Below code that works.

#include "ofApp.h"

void ofApp::setup(){
	ofBackground(0);

	texture.load("PANORAMA.png");
	texture.mirror(true, true);
	
	sphere.setResolution(20);
	sphere.setRadius(200);
	
	camera.setPosition(ofVec3f(300, 300, 300));
	camera.lookAt(ofVec3f(0, 0, 0));
	
	fbo.allocate(ofGetWidth(), ofGetHeight(), GL_RGBA);
	fbo.begin();
	ofClear(0, 0, 0, 0);
	fbo.end();
}

void ofApp::update(){
	fbo.begin();
	ofClear(0, 0, 0, 0);
	
	camera.begin();
	
		ofEnableDepthTest();
		glEnable(GL_CULL_FACE);
		if(ofGetMousePressed()){
			glCullFace(GL_BACK);
		}else{
			glCullFace(GL_FRONT);
		}
	
		ofEnableNormalizedTexCoords();
		texture.bind();
		sphere.draw();
		texture.unbind();
		ofDisableNormalizedTexCoords();
	
		glDisable(GL_CULL_FACE);
		ofDisableDepthTest();
	
	camera.end();
	fbo.end();
}

void ofApp::draw(){
	fbo.draw(0, 0);
}

1 Like