472,789 Members | 1,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,789 software developers and data experts.

(OpenGL) texture from matrix


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;
  8.     // open texture data
  9.     file = fopen( filename, "rb" );
  10.     if ( file == NULL ) return 0;
  12.     // allocate buffer
  13.     width = 64;
  14.     height = 64;
  15.     data = (BYTE*)malloc( width * height * 3 );
  17.     // read texture data
  18.     fread( data, width * height * 3, 1, file );
  19.     fclose( file );
  21.     // allocate a texture name
  22.     glGenTextures( 1, &texture );
  24.     // select our current texture
  25.     glBindTexture( GL_TEXTURE_2D, texture );
  27.     // select modulate to mix texture with color for shading
  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 );
  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 );
  43.     // build our texture mipmaps
  44.     gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height,
  45.                        GL_RGB, GL_UNSIGNED_BYTE, data );
  47.     // free buffer
  48.     free( data );
  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.

Oct 17 '08 #1
0 1489

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

Similar topics

by: Mark L | last post by:
I am trying to create a graphics engine using OpenGL and PHP. I am currently trying to create a completly white texture to test out the texturing capabilities. My idea is to create an array...
by: Rick Muller | last post by:
I have a problem that I would like to get some advice on from other Pythonistas. I currently manage a (soon to be) open source project for displaying molecular graphics for a variety of different...
by: Myk Quayce | last post by:
I have a four-sided polygon that rotates and zooms as the user moves the mouse. Is there a way to incorporate a texture-mapped image without DirectX? The GDI+ doesn't seem to support this. -- ...
by: Scott Chang | last post by:
Hi all, I tried to use Managed C++ coding of VC++.NET (2002)and OpenGL version 1.2 to draw a hexagon shape of benzene. My OpenGLdrawBenzene.cpp is the following: // This is the main project file...
by: Scott Chang | last post by:
Hi All I tried to use the attached OpenGL code to draw a Star-shaped figure on my Microsoft Visual C++ .NET 2002-Windows XP Pro PC. When I did 'Build' in Debug Mode, I got an error C2065:...
by: x | last post by:
Still fairly new at this, I have been trying to find out how to compile and effect with multiple samplers. Been able to find loads of examples that show the HSL code once the samplers are...
by: matt.casella | last post by:
Hi, I've having a *small* problem with a small simulation/game I'm trying to write in C++ using OpenGL. I'm not sure if I need to include code yet, as it might just make things more...
by: ...:::JA:::... | last post by:
Hello, Is there any real easy example for loading an texture in your directpython window??? For example this is my code: # loading directpython modules import d3dx import d3d from d3dc...
by: linksterman | last post by:
hey, I was experimenting with pyglet, and was trying out their opengl, but cant figure out how to scale images... #!/usr/bin/python # $Id:$ '''Demonstrates one way of fixing the display...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: lllomh | last post by:
How does React native implement an English player?
by: Mushico | last post by:
How to calculate date of retirement from date of birth
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.