I am trying to create a floating point texture and display it full screen but it doesn’t want to work, it shows the quad but the quad is completely white.
So I tried uploading unsigned bytes but that also doesn’t want to work. I have created many OpenGL programs before but for some weird reason this code doesn’t want to work.
Thanks.
Code (Using SDL) : main.cpp
#include <iostream>
#include <cmath>
#include <SDL/SDL.h>
#include <GL/gl.h>
void init();
void cycle();
bool quit = false;
int main(int argc, char** args)
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_Surface* buffer = SDL_SetVideoMode(1024, 768, 0, SDL_OPENGL);
init();
while (true)
{
SDL_Event event;
while (SDL_PollEvent(&event))
if (event.type == SDL_QUIT)
quit = true;
if (quit) break;
cycle();
SDL_GL_SwapBuffers();
}
SDL_Quit();
}
void init()
{
}
void cycle()
{
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
float *buffer = new float[2 * 2 * 3];
buffer[ 0] = 0.0f; buffer[ 1] = 0.0f, buffer[ 2] = 0.0f;
buffer[ 3] = 1.0f; buffer[ 4] = 0.0f, buffer[ 5] = 0.0f;
buffer[ 6] = 0.0f; buffer[ 7] = 1.0f, buffer[ 8] = 0.0f;
buffer[ 9] = 0.0f; buffer[10] = 0.0f, buffer[11] = 1.0f;
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F_ARB, 2, 2, 0, GL_RGB, GL_FLOAT, buffer);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glBindTexture(GL_TEXTURE_2D, texture);
glBegin(GL_QUADS);
glTexCoord2f(0.0f,0.0f); glVertex2f(-1.0f,-1.0f);
glTexCoord2f(1.0f,0.0f); glVertex2f( 1.0f,-1.0f);
glTexCoord2f(1.0f,1.0f); glVertex2f( 1.0f, 1.0f);
glTexCoord2f(0.0f,1.0f); glVertex2f(-1.0f, 1.0f);
glEnd();
glDeleteTextures(1, &texture);
delete buffer;
}