Textures

Hello

I load textures like this:

QImage b;
		QImage t;
		
		if ( !b.load( "ffont.bmp" ) )
		{
			b = QImage( 16, 16, 32);
			b.fill( Qt::red.rgb() );
		}
		
		t = QGLWidget::convertToGLFormat( b );
		glGenTextures( 1, &texture[0]);
		glBindTexture( GL_TEXTURE_2D, texture[0]);
		glTexImage2D( GL_TEXTURE_2D, 0,3, t.width(), t.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, t.bits());
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );  

I would like to store more than just one Texture in a (1) BMP file (e.g. for fonts) and I just dont know how…

I thought I could just write 32 instead of t.width() and it should give me the first 32 pixels of the bitmap. However its not working so far… Or is there a function like glTexCoord2 to set the width and height of the Texture later?

I use Fedora Core 4 and QT.

Thank you for your help!!!

How about uploading the whole large texture as one texture object and use texture coordinates to select which sub texture you wish to use (this is how I do it for texture fonts)? This will be more efficient anyway as it reduces the number of texture binds.

Look up “texture atlases.”

-SirKnight

Hi

I tried to do it like this:

     glTexCoord2i(0,0);
			    glVertex2d(0,0);			    
			    glTexCoord2i(1/40,0);
			    glVertex2d(22,0);			    
	    		    glTexCoord2i(1/40,1);
			    glVertex2d(22,32);		
			    glTexCoord2i(0,1);			    
			    glVertex2d(0,32);			    
			    glEnd();	 

…But it doesnt work. It gives me a very distorted texture. What am i doing wrong?

Thank you for your help!

IT WORKS!!!

i have to use float instead of int! :rolleyes:

 

			    glBindTexture(GL_TEXTURE_2D, texture[0]);
			    glBegin(GL_QUADS);
			    glTexCoord2f(0.0f,0.0f);
			    glVertex2f(0.0f,0.0f);			    
			    glTexCoord2f(0.025f,0.0f);
			    glVertex2f(22.0f,0.0f);			    
	    		    glTexCoord2f(0.025f,1.0f);
			    glVertex2f(22.0f,32.0f);		
			    glTexCoord2f(0.0f,1.0f);			    
			    glVertex2f(0.0f,32.0f);			    
			    glEnd();	
 

Thank you!!! :slight_smile:

it has nothing to do with ogl, but with c+ :wink: when you divide two integers, then the result is also an integer :wink: when at least one of them is float, then the result is float.

so it would be 1/40.0f or 1.0f/40 or 1.0f/40.0f …

Originally posted by madmadmod:
IT WORKS!!!
I’ve been having quite a few of those moments recently, cool huh? :slight_smile:

BTW, Glad it works.

-SirKnight