(OpenGL) texture from matrix

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • brixton
    New Member
    • Nov 2006
    • 35

    (OpenGL) texture from matrix

    Hello,

    I've got the following code that creates a texture from a .RAW file:
    Code:
    GLuint MyGLCanvas::LoadTextureRAW( const char * filename, int wrap )
    {
        GLuint texture;
        int width, height;
        BYTE * data;
        FILE * file;
    
        // open texture data
        file = fopen( filename, "rb" );
        if ( file == NULL ) return 0;
    
        // allocate buffer
        width = 64;
        height = 64;
        data = (BYTE*)malloc( width * height * 3 );
    
        // read texture data
        fread( data, width * height * 3, 1, file );
        fclose( file );
    
        // allocate a texture name
        glGenTextures( 1, &texture );
    
        // select our current texture
        glBindTexture( GL_TEXTURE_2D, texture );
    
        // select modulate to mix texture with color for shading
        glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
    
        // when texture area is small, bilinear filter the closest mipmap
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                         GL_LINEAR_MIPMAP_NEAREST );
        // when texture area is large, bilinear filter the first mipmap
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    
        // if wrap is true, the texture wraps over at the edges (repeat)
        //       ... false, the texture ends at the edges (clamp)
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
                         wrap ? GL_REPEAT : GL_CLAMP );
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
                         wrap ? GL_REPEAT : GL_CLAMP );
    
        // build our texture mipmaps
        gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height,
                           GL_RGB, GL_UNSIGNED_BYTE, data );
    
        // free buffer
        free( data );
    
        return texture;
    }
    That works fine. However, I want to generate a texture from a matrix of double values (using a matrix library) instead. It's stored indexed like Matrix(x,y).

    So, the question is: how do I modify this to get my matrix values into the "data" array? Can "data" be of double type?

    Apologies if it's a silly question, but I'm new to all things OpenGL.

    Thanks.
Working...