Jump to content
  • Advertisement
Sign in to follow this  
Scribe

OpenGL Image does not render

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

Hi, I've recently made some revisions to the way my program handles openGL textures. As such it now will not render any image. As it was working previously, i can be pretty sure that the issue is in the code samples below and i'm hoping someone can spot what i'm doing wrong. Any error checks are not returning errors btw. Thanks. Code that initiates OpenGL:
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // Load OpenGL
    glViewport( 0, 0, ScreenX, ScreenY );                                       // Setup the OpenGL Window
    glMatrixMode( GL_PROJECTION );                                              // Set OpenGL for 2d Projection mode
    glLoadIdentity();                                                           // Set the default Screen Matrix
    glOrtho( 0, 1024, 768, 0, -10, 10 );                                        // Apply the Matrix to the Screen
    glMatrixMode( GL_MODELVIEW );                                               // Set OpenGL for Model mode
    glLoadIdentity();                                                           // Set the default Screen Matrix
    glClearColor( 0, 0, 0, 0 );                                                 // Create a Black clear colour
    glClearDepth( 0 );                                                          // Create the default depth at 0
    glDepthFunc( GL_LEQUAL );                                                   // Allows images infront only to show    
    glEnable( GL_DEPTH_TEST );                                                  // Activates the above system
    glShadeModel( GL_SMOOTH );                                                  // Allow pixels to blend together
    glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );                        // Give the nicest vibrance
    glColor4i( 255, 255, 255, 255 );                                            // Set the current colour to white
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );                        // Set Alpha and pixel Blending
    glEnable( GL_BLEND );                                                       // Activates the above system
    glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
    glEnable( GL_TEXTURE_2D );

    Error_Number = glGetError();                                                // Check for Error

    if( Error_Number != 0 )                                                     // If any of the above returned a
                                                                                // value
    {

        Error.New_Error( 6 );                                                   // Run Error Handler
         
        return 0;                                                               // Return main ( end program )

    }


Code that loads the texture:
            glGenTextures( 1, &this->Files[File_Number].Images[Image_Number].Image_ID );
            glBindTexture( GL_TEXTURE_2D, this->Files[File_Number].Images[Image_Number].Image_ID );

            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Filtered
            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Linear Filtered

            errorCode = glGetError();

            if ( errorCode != 0 )
            {

                glDeleteTextures (1, 
					&this->Files[File_Number].Images[Image_Number].Image_ID);

				Error.New_Error( 32 );                                          // Run Error Handler
        
                return 0;                                                       // Return Load_Image as 0

            }

            gluBuild2DMipmaps
				( GL_TEXTURE_2D, 4, Width, Height, GL_RGBA, 
				  GL_UNSIGNED_BYTE, (GLuint*)pbImageData );

            errorCode = glGetError();
            if ( errorCode != 0 )
            {

                glDeleteTextures (1, 
					&this->Files[File_Number].Images[Image_Number].Image_ID);

				Error.New_Error( 33 );                                          // Run Error Handler
        
                return 0;                                                       // Return Load_Image as 0

            }


Code that draws the texture:
glBindTexture( GL_TEXTURE_2D, Image );				// Load the image as the current
                                                    // texture

		glBegin( GL_QUADS );                        // Begin creating a Quad

		// Top-left vertex (corner)
		glTexCoord2i( 0, 1 );
		glVertex3i(  0, 0, 10 );

		// Bottom-left vertex (corner)
		glTexCoord2i( 0, 0 );
		glVertex3i( 0, 50, 10 );
 
		// Bottom-right vertex (corner)
		glTexCoord2i( 1, 0 );
		glVertex3i( 50,50, 10 );
 
		// Top-right vertex (corner)
		glTexCoord2i( 1, 1 );
		glVertex3i( 50, 0, 10 );

		glEnd();                                   // End creating a Quad


Also, checked that the texture identifier is correct and valied. Thanks for any help guys. Switched code tags to source tags, you're lucky i'm in a good mood or I would have increased your warning some more [Edited by - phantom on August 21, 2005 12:35:48 PM]

Share this post


Link to post
Share on other sites
Advertisement
glClearDepth( 0 );
glDepthFunc( GL_LEQUAL );

hmm that doesn't make much sence to me - first you set depth buffer to 0 (to be precise, value to which depth buffer will be cleared when glClear is called with depth_buffer_bit) and set depth function to 0? that means only fragment with depth 0 would pass and imo that's not what you want (and comparing float equallity of float values has it's problems too)

Share this post


Link to post
Share on other sites
thx 4 that, but that still doesnt sort my problem :(

And it would help having it advertised when i post that a tag such as [ source lang="cpp"] even exists, i guessed that [ code] was one.
[/source]

Share this post


Link to post
Share on other sites
Right, i've cleared the noise out of this thread, so lets now stay on topic, the issue of right and wrong wrt the correct posting method isnt on the table for discussion [smile]

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!