Jump to content
  • Advertisement
Sign in to follow this  
pogo_bounce

OpenGL Generating a texture from a matrix

This topic is 4165 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone... i`m new to Gamedev.net and to OpenGL. But i started to experiment with Procedural Generation and of course i ran across some problems. So if anyone can help me: I'm currently experimenting with 2D Perlin Noise for texture generation (for planets), I did all the functions and the results are saved in a matrix(128x128 or whatever). My problem is that i don`t know how to generate a real texture from that matrix, because i want to put the texture on a quadric sphere. I`ve been searching the net for the last couple of days and found nothing helpful... So i`d be really grateful if anyone could tell me how to load the matrix as a texture, which i can later map onto the sphere. please:D

Share this post


Link to post
Share on other sites
Advertisement
a texture is just a sequential ordering of pixel data. so just arrange your pixels in a single array in memory that has row major ordering (i.e. first row of pixels are the first pixels in the array). after that you just have to bind the texture using the correct enumerations to let openGL or whatever know your data density.

just take a look at chapter 9 in the red book:
http://fly.cc.fer.hr/~unreal/theredbook/

-me

Share this post


Link to post
Share on other sites
well, i have a ordered array [128x128 for example] and my problem is exactly that i do not know the correct ennumerations. And i didn`t find a clear answer... I know how to create a texture from a .bmp but i don`t know how to create a texture from an array. i don`t know the predefined functions that OpenGL has because i`ve just started using it.

Share this post


Link to post
Share on other sites
But there's not much to chose from, really. The type parameter (second last) must match the type of the data; GL_FLOAT for floatingpoint values, GL_UNSIGNED_CHAR for unsigned chars for example. The format parameter (third last) must match the format of the data; GL_LUMINANCE for a grayscale image, GL_RGBA for 4-channel RGBA data for example. Internal format usually match the format parameter.

From OpenGL's point of view, there is no BMP image. It's just a big chunk of data, just like the array with noise you have. So if you know how to load the image data array from a BMP, there's no reason why you can't load custom generated image data.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!