473,785 Members | 2,466 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

(OpenGL) texture from matrix

35 New Member
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 1562

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

Similar topics

1
5038
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 256x256x3 of the value 255 to create a completely white texture. When I do this in C it works fine but in PHP I get a array of red, blue, green and black lines texturing the cube. I have built a webpage detailing this problem:...
9
3195
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 programs. To do this I need to draw pictures of the molecules, typically using OpenGL, and do some basic control, using some widget set. The code currently uses GTK, and runs on Macintosh OS X under Fink, and Linux. I would like to support the...
1
3219
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. -- Myk Quayce "If we can't be free, at least we can be cheap." - Frank Zappa
0
3645
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 for VC++ application project // generated using an Application Wizard. #include "stdafx.h" #include <stdlib.h>
1
5616
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: 'RenderScence': undeclared identifier. Please help and tell me (1) what it is wrong with my coding in this program and how to correct the problem, and (2) whether the functions/commands of the OpenGL v1.1 (existing in Microsoft Visual C++ .NET 2002) and GLUT...
3
1390
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 loaded, but not how to get the textures from VB into the shader. If i set up two samplers in the shader with no associated texture then when I compile the shader from string works fine. but when the shader actually runs both sample the same texture...
2
2148
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 complicated, but I can do so if necessary. Basically what I'm writing involves a simple sprite fielder trying to catch a thrown ball. The ball and the fielder are each in their respective coordinate frames, and I'm using the matrix stack to keep
0
1467
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 import *
1
4210
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 resolution to a certain
0
9485
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10161
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8986
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5523
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4058
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2890
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.