Results 1 to 6 of 6

Thread: Floating point textures

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2008
    Posts
    4

    Floating point textures

    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
    Code :
    #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(&amp;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, &amp;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, &amp;texture);
     
    	delete buffer;
    }

  2. #2
    Senior Member Frequent Contributor _NK47's Avatar
    Join Date
    Mar 2008
    Posts
    574

    Re: Floating point textures

    something is wrong with your code. buffer contains 12 values where your texture is 2x2 = 4 values. only 4 of them are taken on glTexImage2D. also you create and delete texture every time on cycle(). what is the point of that?

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2008
    Posts
    4

    Re: Floating point textures

    Aren't there three values per pixel, for each channel (RGB)?

    This is only a test. Is it OK to call glTexImage2D() every frame destroying the previous data or is it just overwritten?

    Later on the values in the buffer will change each frame, so assume they changing each frame

  4. #4
    Senior Member Frequent Contributor _NK47's Avatar
    Join Date
    Mar 2008
    Posts
    574

    Re: Floating point textures

    actually your right sorry. what im thinking early in the morning? what hardware your on? test if the floating point format is supported by your hardware. it totally ok to do so, will give you the worst performance though. better create once and update texture with glTexSubImage2D.

  5. #5
    Junior Member Newbie
    Join Date
    Dec 2008
    Posts
    4

    Re: Floating point textures

    Graphics Card: NVIDIA GeForce 7300GT 256MB

    Will change the texture creation.

    EDIT: Changed

    Code :
    GLuint texture;
     
    void init()
    {
        glGenTextures(1, &amp;texture);
    }
     
    void end()
    {
        glDeleteTextures(1, &amp;texture);
    }
     
    void cycle()
    {
        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_RGB16F_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);
     
        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();
     
        delete buffer;
    }

  6. #6
    Junior Member Newbie
    Join Date
    Dec 2008
    Posts
    4

    Re: Floating point textures

    Found the problem. I forgot:
    glEnable(GL_TEXTURE_2D);

    Thanks anyway

Similar Threads

  1. working with floating point textures
    By ehsan2004 in forum OpenGL: Advanced Coding
    Replies: 7
    Last Post: 02-14-2007, 07:54 AM
  2. Floating point textures and FBO
    By christl in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 05-09-2006, 06:19 PM
  3. Floating point textures and GLSL
    By paintor in forum OpenGL: GLSL
    Replies: 2
    Last Post: 11-25-2004, 01:35 AM
  4. Floating Point textures in Cg
    By Zeross in forum OpenGL: GLSL
    Replies: 1
    Last Post: 05-20-2004, 08:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean