This way the texture can be activated with the glBindTexture function ( documentation of glBindTexture). The id is a handle to the OpenGL driver's texture. In the end we want to fill the following data structure: This way the loading code can deal with palettes, grayscale, 16 bit per color channel and transparent color masks as well. While loading the image file, libpng will be told to convert various image formats to RGB or RGBA, depending on whether they have transparency information. Void glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid * data)ĭata is the argument for the pixel values, width, height and format (e.g. Make sure to read the documentation of glTexImage2D. The OpenGL API offers the function glTexImage2D to perform this upload. It first needs to get transferred from main memory to video memory (on the graphics chip). Libpng has a really terrible API, but all we basically need it to do is give us the width, height, color format and pixel values.Īlthough the texture has been parsed it's not ready for drawing yet. In this tutorial libpng will be used to parse PNG image files. Given an image file, parse its meta information (dimensions, color format) and get an array of pixel values. Loading a texture in OpenGL consists of two phases. You can find more information about this optimization in the "Texture Formats" article Overview However, this tutorial should be useful to get you started with drawing things on the screen. Please note that it is recommended to use compressed textures instead to save some memory. texture0 SOILloadOGLtexture(. SOILloadOGLtexture returns a texture id, so you could do this instead. Then you will normally feed this data to gl using glGenerateTextures, assign texture IDs, calling glTexImage2D. In this tutorial you will learn how to load a PNG file and display it using OpenGL. SOILloadimage will return unsigned char yes, array holding your image data.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |