Generating a texture from a matrix

Started by
4 comments, last by pogo_bounce 16 years, 9 months ago
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
Advertisement
What problem exactly are you having? For example, what combination of parameters to pass to glTexImage?
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
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.
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.
thank you very much... i understand now... and i also found a useful example in the "red book"... it isn`t even that hard:D

This topic is closed to new replies.

Advertisement