Heys,
I'm having a spot of trouble with texturing a regular quad using the "GL_TEXTURE_RECTANGLE_ARB" texture target. I have read Nehe's Lesson 06 and search around a bit, but have been unable to find a proper solution. I have used a neat debugging tool (imdebug) to assure that the texture actually contains what I believe it does, but for some reason OpenGL refuses to texture the quad I have drawn... Perhaps because I've misunderstood something fundamental?
I'd be eternally grateful for any help anyone is willing to spare...
My initialization code looks like this:
cgEnabled = true;
//glShadeModel(GL_SMOOTH);
//glEnable(GL_TEXTURE_2D);
//glEnable(GL_TEXTURE_RECTANGLE_ARB);
// Initialize FBO
// Create FBO (off-screen framebuffer)
glGenFramebuffersEXT(1, &fb);
// Bind offscreen framebuffer (that is, skip the window-specific render target)
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
//glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); // Must be placed here?
// Init Cg.
cgSetErrorCallback(cgErrorCallback);
// get the best profile for this hardware
vtex_profile = cgGLGetLatestProfile(CG_GL_VERTEX);
frag_profile = cgGLGetLatestProfile(CG_GL_FRAGMENT);
// Make certain profiles exist...
assert((vtex_profile != CG_PROFILE_UNKNOWN) && (frag_profile != CG_PROFILE_UNKNOWN));
cgGLSetOptimalOptions(vtex_profile);
cgGLSetOptimalOptions(frag_profile);
printf("BeeSystem: Latest vertex Profile loaded - %s \n", cgGetProfileString(vtex_profile));
printf("BeeSystem: Latest fragment Profile loaded - %s \n", cgGetProfileString(frag_profile));
g_context = cgCreateContext();
// Load Cg Programs
testFProg = cgCreateProgramFromFile(g_context, CG_SOURCE, "moveBees.cg", frag_profile, "main", NULL);
if(testFProg != NULL)
{
/* Vertex shader only needs to be loaded once */
cgGLLoadProgram(testFProg);
TextureParam = cgGetNamedParameter(testFProg, "beeTexture");
}
textureFProg = cgCreateProgramFromFile(g_context, CG_SOURCE, "textureDisplay.cg", frag_profile, "main", NULL);
if(textureFProg != NULL)
{
/* Vertex shader only needs to be loaded once */
cgGLLoadProgram(textureFProg);
anotherTextureParam = cgGetNamedParameter(textureFProg, "aTexture");
}
// Create Landscape Texture
int bmpStatus;
scenarioBmp = new BMPImg();
printf("DEBUG IMG Pointer: %p \n", scenarioBmp->GetImg());
bmpStatus = scenarioBmp->Load("beeworld0.bmp");
printf("DEBUG IMG Pointer: %p \n", scenarioBmp->GetImg());
printf("DEBUG IMG INFEW: BPP %i | Width %i | Height %i \n", scenarioBmp->GetBPP(), scenarioBmp->GetWidth(), scenarioBmp->GetHeight());
if (bmpStatus == 1) {
printf("BeeSystem: Bmp Load succeeded! \n");
} else {
printf("BeeSystem: Bmp Load failed: %i \n", bmpStatus);
}
glGenTextures(1, &scenarioTex);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, scenarioTex);
glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // GL_CLAMP_TO_EDGE
glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // GL_CLAMP_TO_EDGE
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
// CRASH: In all likelyhood due to img being 24bit for RGB and computer expecting RGBA
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_FLOAT_RGBA32_NV, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, scenarioBmp->GetImg());
imdebugTexImagef(GL_TEXTURE_RECTANGLE_ARB, scenarioTex, GL_RGBA, 0);
The actual rendering of the quad with the supposed texture looks as following
// Draw a Quad with Ortho that fills screen!
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 512, 0.0, 512);
// width / height
float ratio = 1.0* 512 / 512;
// Set the viewport to be the entire window
glViewport(0, 0, 512, 512);
// Set the correct perspective.
// FOV, Aspect Ratio, Znear, Zfar
//gluPerspective(90,ratio,0.1,10000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Vec3 eyePos, Vec3 SceneCenter, Vec3 ViewUpVector
gluLookAt(0.0,0.0,1.0, 0.0,0.0,-1.0, 0.0f,1.0f,0.0f);
glColor4f(0.2f,0.2f,0.2f,1.0f);
glDisable(GL_TEXTURE_RECTANGLE_ARB);
glEnable(GL_TEXTURE_RECTANGLE_ARB);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, scenarioTex);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0);
glVertex2f(0.0, 0.0);
glTexCoord2f(512.0, 0.0);
glVertex2f(512.0, 0.0);
glTexCoord2f(512.0, 512.0);
glVertex2f(512, 512);
glTexCoord2f(0.0, 512.0);
glVertex2f(0.0, 512);
glEnd();
I perform a flushing after the rendering and make sure that values aren't clamped... Other than that I am not sure what I am missing...
Thanks in advance,
Gazoo