Jump to content
  • Advertisement
Sign in to follow this  
Scribe

OpenGL Help, malloc and textures

This topic is 4839 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

I've recently hit a snag in my coding. I read fonts from 8-bit bitmap info in memory and place into a malloc'd array in 32-bit rgba format. However, i constantly receive memory errors, if i use free(OpenGL_Texture) and also if i dont, the next malloc returns and error. to do this i use:
GLuint *OpenGL_Texture = (GLuint*)malloc( font_rows * font_width * 4 );
// 4 for the number of bytes (rgba)

i then run a loop like this( taking this out solves my problem!!! so error is prob here lol):

Uint32 Count = 0;

for( Sint32 y = font_rows-1; y > -1; y-- ) //read backwards for texture layout
{
   for( Sint32 x = 0; x < font_width; x++ )
   {
     OpenGL_Texture[Count] = 255; // or other number up2 255

     Count++;

     OpenGL_Texture[Count] = 255; // or other number up2 255

     Count++;

     OpenGL_Texture[Count] = 255; // or other number up2 255

     Count++;

     OpenGL_Texture[Count] = 255; // or other number up2 255

     Count++;

   }
}

any idea where im overstepping my bounds here? [Edited by - phantom on August 17, 2005 9:04:48 PM]

Share this post


Link to post
Share on other sites
Advertisement
Your array is declared as a gluint, i.e. a 32-bit int. You are requesting enough memory for rows*width*4 *bytes*. In your loop, you are writing rows*width*4 *integers*. There's the problem. Just declare your OpenGL_Texture as GLubyte*.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!