Jump to content
  • Advertisement
Sign in to follow this  
c_young

AUX_RGBImageRec to GLuint

This topic is 4339 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 posted a while ago about having problems with loading textures using libpng on mac, i ended up just caving in and going pc. im using tutorials from nehe (lesson 6 in particular), the lesson uses auxDibLoadImage() function (from glaux i think). when compiling my program i get errors in converting the returned AUX_RGBImageRec to a GLuint to be used in creating the texture. i also get an error in conversion from AUX_RGBImageRec to 'non scalar type' AUX_RGBImageRec. the code is almost straight out of the lesson 6 tutorial, i have all the correct libraries installed and linked (im using devc++ ). can anyone help? heres the functions which return errors, i commented in the errors
AUX_RGBImageRec load_BMP( char *fileName )
{
     FILE *file = NULL;
     file = fopen( fileName, "r" );
     
     return auxDIBImageLoad( fileName ); /*conversion from AUX_RGBImageRec to
                                           'non scalar type' AUX_RGBImageRec */
}

GLvoid load_Textures( GLvoid )
{
       AUX_RGBImageRec *texture[ 0 ];
       memset( texture[ 0 ], 0, sizeof( void *) * 1 );
       
       texture = load_BMP( "texture.bmp" ); /*assignment of AUX_RGBImageRec to 
                                              AUX_RGBImageRec *[Ou] */
       
       glGenTextures( 1, &texture[ 0 ] ); /* cannot convert AUX_RGBImageRec** to                                 
                                             GLuint* */
       glBindTexture( GL_TEXTURE_2D, texture[ 0 ] ); /* AUX_RGBImageRex* to  
                                                        GLuint */
       glTexImage2D( GL_TEXTURE_2D, 0, 3, texture[ 0 ]->sizeX,
                     texture[ 0 ]->sizeY, 0, GL_RGB, 
                     GL_UNSIGNED_BYTE, texture[ 0 ]->data );
                     
       glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
       glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );

       free( texture[ 0 ]->data );
       free( texture[ 0 ] );
}

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Quote:

AUX_RGBImageRec *texture[ 0 ];


Firstly you are declaring an array of zero objects. What you want is


AUX_RGBImageRec *texture[ 1 ];


Secondly when loading the texture you need to assign to the element of the array you want, not to the array itself.

Quote:

texture = load_BMP( "texture.bmp" ); /*assignment of AUX_RGBImageRec to
AUX_RGBImageRec *[Ou] */

should become

texture[ 0 ] = load_BMP( "texture.bmp" );


Thirdly you can't use the AUX_RGBImageRec pointer as a GLuint. The first is a pointer to a texture in memory, the second refers to an OpenGL texture object. You have to get a GLuint using glGenTextures. So do this:

GLuint gl_texture[ 1 ];
// put the id number of a new texture into gl_texture
glGenTextures( 1, &(gl_texture[ 0 ]) );
// now tell OpenGL we want to use this texture from now on,
glBindTexture( GL_TEXTURE_2D, gl_texture[ 0 ] );


Fourthly your load_BMP returns an AUX_RGBImageRec when it should return a pointer to an AUX_RGBImageRec (according to the definition of auxDIBImageLoad I found on the web) so change your first function definition from
Quote:

AUX_RGBImageRec load_BMP( char* fileName )

to

AUX_RGBImageRec* load_BMP( char* fileName )


The rest should be OK I think but I can't say for sure.

Share this post


Link to post
Share on other sites
hmmm...

AUX_RGBImageRec *texture[ 0 ];

i guess u can't allocate array for 0 element =\
try this:

AUX_RGBImageRec *texture[ 1 ];
texture[0] = load_BMP( "texture.bmp" );


or u can try this :

AUX_RGBImageRec *texture;


remove
memset( texture[ 0 ], 0, sizeof( void *) * 1 );
cause u don't need it i guess =\.

take care.


Share this post


Link to post
Share on other sites
ok i did what anonymous said and it worked, but im getting an error saying auxDIBImageLoad() is undefined, but i have the include gluax.h so does this mean theirs something wrong with the linker settings?

my only other question is if i already have a GLuint texture[ 1 ], why did i need to declare another GLuint gl_texture[ 1 ]? couldnt i just use the one variable for both?

**edit- i changed the linker settings, i dont think it was includeing glaux before. now the program compiles and runs but closes and windows prompts an error "textures has encountered an error and needs to close". does this most likley have to do with an error loading the bmp? i didnt put any kind of error checking in my program, what should i be checking for?

Share this post


Link to post
Share on other sites
Search your source code for the string, "textures has encountered an error and needs to close", and you'll find where things went wrong. Check the condition that causes that message to appear and that's your problem.

Share this post


Link to post
Share on other sites
no, its a windows error not an error form my program. its one of those errors were windows asks if i want to send an error report.

Share this post


Link to post
Share on other sites
from the code u showed us u have :

texture of type AUX_RGBImageRec not of type unsigned int

u need this to keep track of the texture by saving its id so yes u need
another varible of type uint for the id .

u need to check red book for more information about this .
check the forum faqs.

take care.

Share this post


Link to post
Share on other sites
First of all, stop using the aux library: it's old and it plain just sucks. There are plenty of libraries and code snippets that will load just about any image file or format you throw at them, with proper error handling. Popular examples are DevIL and FreeImage.

Second, the error looks like memory corruption. Check your code for any use of null pointers (i.e. the image fails to load yet you use the invalid pointer anyhow).

Third, there's a difference between both variables. The first stores a pointer to image data (AUX_RGBImageRec), while the second variable stores a handle to an OpenGL texture. After uploading the texture with a call to glTexImage2D, OpenGL has no need for the AUX_RGBImageRec anymore, so you may (and should) release it.

In your code however, instead of CHECKING for success, you go about and free what could possibly be an undetermined pointer. The code from the tutorial does this right. This could be the source of the error, but even if it isn't, you should always CHECK what you set free:


if (TextureImage[0])
{
if (TextureImage[0]->data)
{
free( TextureImage[0]->data );
}

free( TextureImage[0] );
}

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!