468,532 Members | 1,663 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,532 developers. It's quick & easy.

(OpenGL) texture from matrix

35
Hello,

I've got the following code that creates a texture from a .RAW file:
Expand|Select|Wrap|Line Numbers
  1. GLuint MyGLCanvas::LoadTextureRAW( const char * filename, int wrap )
  2. {
  3.     GLuint texture;
  4.     int width, height;
  5.     BYTE * data;
  6.     FILE * file;
  7.  
  8.     // open texture data
  9.     file = fopen( filename, "rb" );
  10.     if ( file == NULL ) return 0;
  11.  
  12.     // allocate buffer
  13.     width = 64;
  14.     height = 64;
  15.     data = (BYTE*)malloc( width * height * 3 );
  16.  
  17.     // read texture data
  18.     fread( data, width * height * 3, 1, file );
  19.     fclose( file );
  20.  
  21.     // allocate a texture name
  22.     glGenTextures( 1, &texture );
  23.  
  24.     // select our current texture
  25.     glBindTexture( GL_TEXTURE_2D, texture );
  26.  
  27.     // select modulate to mix texture with color for shading
  28.     glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
  29.  
  30.     // when texture area is small, bilinear filter the closest mipmap
  31.     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
  32.                      GL_LINEAR_MIPMAP_NEAREST );
  33.     // when texture area is large, bilinear filter the first mipmap
  34.     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
  35.  
  36.     // if wrap is true, the texture wraps over at the edges (repeat)
  37.     //       ... false, the texture ends at the edges (clamp)
  38.     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
  39.                      wrap ? GL_REPEAT : GL_CLAMP );
  40.     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
  41.                      wrap ? GL_REPEAT : GL_CLAMP );
  42.  
  43.     // build our texture mipmaps
  44.     gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height,
  45.                        GL_RGB, GL_UNSIGNED_BYTE, data );
  46.  
  47.     // free buffer
  48.     free( data );
  49.  
  50.     return texture;
  51. }
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.
Oct 17 '08 #1
0 1336

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Mark L | last post: by
1 post views Thread by Myk Quayce | last post: by
2 posts views Thread by matt.casella | last post: by
reply views Thread by ...:::JA:::... | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.