Draw ofTexture in opengl

Hello everyone,

I must be missing something very obvious here. I’m trying to draw the texture of an ofFBO using opengl. So why is this not working?

int tw = 300;
int th = 300;

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, rgbaFbo.getTexture().texData.textureID);
glBegin(GL_QUADS);
glTexCoord2i(0, 0); glVertex2i(100, 100);
glTexCoord2i(tw, 0); glVertex2i(100, 500);
glTexCoord2i(tw, th); glVertex2i(500, 500);
glTexCoord2i(0, th); glVertex2i(500, 100);
glEnd();

glFlush();

Hi,

Is there a reason you can’t just use fbo.draw(float x, float y, float width, float height)?

With the above code, GL_TEXTURE_2D is expecting texture coords in the 0-1 range, not pixel dimensions. So try changing tw = 1 and th = 1. The default for ofFbo is arb textures, so you will need to call ofDisableArbTextures() before allocating the fbo to create the fbo using GL_TEXTURE_2D.

Hi @NickHardeman,
Thank you very much for your help.
The reason is that I’m trying to make a dll to draw ofFbo, and the DLL can not contain OF calls.

Actually I knew about the texture coordinates in OF and the ofDisableArbTex() I just was not placing it before the texture allocation. And also I figured out the coordinates go towards lower left corner instead of upper right. Here is the working code:

int tx = 0;
int ty = 0;
int tw = 1;
int th = 1;

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, rgbaFbo.getTexture().texData.textureID);
glBegin(GL_QUADS);
glTexCoord2i(tx, ty); glVertex2i(100, 100);
glTexCoord2i(tx, th); glVertex2i(100, 500); // Attention, we first map the lower left corner//
glTexCoord2i(tw, th); glVertex2i(500, 500);
glTexCoord2i(tw, ty); glVertex2i(500, 100);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);

Thank you so much!
j