A strange problem with loading textures.

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
LarryTM
Posts: 30
Joined: Tue Jul 04, 2006 4:05 am
Contact:

A strange problem with loading textures.

Post by LarryTM »

Hi.

Im trying to load fonts using FreeType2 and PSPGL and I have a strange problem:

http://img441.imageshack.us/my.php?image=testsq9.jpg

The text should look like this: Test Text

My loading code (a part of) :

Code: Select all


GLuint * tex_base;

 (...)

GLubyte* expanded_data = new GLubyte[ 2 * width * height];

(...)

 glBindTexture( GL_TEXTURE_2D, tex_base[(int)ch]);		
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,  GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, expanded_data );
	gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, width, height,  GL_RGBA, GL_UNSIGNED_BYTE, expanded_data);
Without the last line (gluBuild2DMipMaps) my psp just hangs up when I try to use my font texture;

Display code :

Code: Select all

string tekst;

(...)

/* FontData.textury=tex_base; */

glPushMatrix();
  glTranslatef((float)a*h/3.0f,litery[(int)tekst.at(a)].y,0.0f);
  glBindTexture(GL_TEXTURE_2D,FontData.textury[(int)tekst.at(a)]);
  glBegin(GL_TRIANGLE_FAN);		
    glTexCoord2f(0,0);
    glVertex2f(0,litery[(int)tekst.at(a)].vert_y);
    glTexCoord2f(0,(float)litery[(int)tekst.at(a)].tx_cord_y);
   glVertex2f(0,0);
glTexCoord2f((float)litery[(int)tekst.at(a)].tx_cord_x,(float)litery[(int)tekst.at(a)].tx_cord_y);    glVertex2f(litery[(int)tekst.at(a)].vert_x,0);
    glTexCoord2f((float)litery[(int)tekst.at(a)].tx_cord_x,0);
    glVertex2f(litery[(int)tekst.at(a)].vert_x,litery[(int)tekst.at(a)].vert_y);
  glEnd();	
glPopMatrix();
Anyone have any ideas how to fix it?

Thanx!
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

One problem is your array is only 2*w*h in size, but then you call gluBuild2DMipmaps which is expecting 4*w*h of data.
Can you post how you initialise tex_base?

Jim
Post Reply