Jump to content
  • Advertisement
Sign in to follow this  
ConorH

OpenGL OpenGL woes! Blank image

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

Iv been trying to get OpenGL up and running with SDL, and be able to basically draw textured quads as images would be for SDL. I get this screen when i blit a little 128*128 image Any idea in what im doing wrong. Would it be the blitting code, or the actual setting up OpenGL code? Setup Code
	//Set up the screen 
	if (Renderer==OpenGL)
	{
	Screen = SDL_SetVideoMode( Width, Height, Depth, SDL_OPENGL | SDL_HWSURFACE | SDL_HWPALETTE | SDL_DOUBLEBUF );
	SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
	//Initialize OpenGL 
	//Set clear color
    glClearColor( 0, 0, 0, 0 );
    
    //Set projection
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    glOrtho( 0, Width, Height, 0, -1, 1 );
    
    //Initialize modelview matrix
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();
    
		//If there was any errors
		if( glGetError() != GL_NO_ERROR )
	    {
			WriteLine(Error,"Error in OpenGL setup");    
		}
		else
		{
			WriteLine(Custom,"OpenGL setup");
		}
	}


Loading image code ogl=GLuint class member sdl=SDL_Surface* class member
	sdl = IMG_Load(filename.c_str());
	
        //Transform the image to the current dislay settings
	sdl = SDL_DisplayFormat( sdl );
	
        //Store width and height
	w=sdl->w;
	h=sdl->h;
		

	// Have OpenGL generate a texture object handle for us
		glGenTextures( 1, &ogl );
 
		// Bind the texture object
		glBindTexture( GL_TEXTURE_2D, ogl );
 
		// Set the texture's stretching properties
        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
 
		// Edit the texture object's image data using the information SDL_Surface gives us
		glTexImage2D( GL_TEXTURE_2D, 0, 3, sdl->w, sdl->h, 0,
	                    GL_RGB, GL_UNSIGNED_BYTE, sdl->pixels );

Drawing Code
		// Bind the texture to which subsequent calls refer to
		glBindTexture( GL_TEXTURE_2D, ogl );
 
		glBegin( GL_QUADS );
			//Top-left vertex (corner)
			glTexCoord2i( 0, 0 );
			glVertex3f( xx, yy, 0.0f );
			
			//Bottom-left vertex (corner)
			glTexCoord2i( 1, 0 );
			glVertex3f( xx, yy+h, 0 );
			
			//Bottom-right vertex (corner)
			glTexCoord2i( 1, 1 );
			glVertex3f( xx+w, yy+h, 0 );
			
			//Top-right vertex (corner)
			glTexCoord2i( 0, 1 );
			glVertex3f( xx+w, yy, 0 );
		glEnd();

[Edited by - ConorH on October 2, 2007 11:00:50 AM]

Share this post


Link to post
Share on other sites
Advertisement
hmm, I _think_ the problem is with glTexCoord2i. glTexCoord2i texture coordinates are in pixels, right? glTexCoord2f would range from 0 to 1.

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!