Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - ZiklonE

Pages: [1]
1
Graphics / Problem converting sf::Image into Opengl Texture (SOLVED)
« on: December 28, 2011, 05:38:22 pm »
Hey there,
 
I've been stuck in the following problem for awhile, hopefully you guys can help me out :)  
 
I'm trying to load an image using sf::Image function, and then use the image values to create a texture in opengl (I pretty much copy pasted the code found on sfml 1.6 sdk opengl example).  
 
Here's what I get:  


What I should be getting, however, would be a square with several tones of gray in the background and an orange letter in the middle, as opposed to a constant gray colour with no letter.  
 
The png I've made is 64x64 32 bits.  
 
Here's the code I'm using:

outside the game loop
Code: [Select]

sf::Image Image;
if (!Image.LoadFromFile("images/tex1.png"))
cout << "fail" << endl;

GLuint Texture = 1;
{
glGenTextures(1, &Texture);
glBindTexture(GL_TEXTURE_2D, Texture);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, Image.GetWidth(), Image.GetHeight(), GL_RGBA, GL_UNSIGNED_BYTE, Image.GetPixelsPtr());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
}

// Enable Z-buffer read and write
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glClearDepth(1.f);

        //(initX, initY, objW, objH, sf::Image*)
DrawableObj test = DrawableObj(10, 10, 64, 64, &Image);



Inside the loop
Code: [Select]

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

test.update(time);
test.draw(&Texture);

appWindow->Display();



draw functio of DrawableObj
Code: [Select]

void DrawableObj::draw( GLuint* tex )
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, *tex);
glColor4f(1.f, 1.f, 1.f, 1.f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glBegin(GL_QUADS);                      // Draw A Quad
glVertex3d( posX - drawW/2, posY - drawH/2, 0.0);              // Top Left
glVertex3d( posX + drawW/2, posY - drawH/2, 0.0);              // Top Right
glVertex3d( posX + drawW/2, posY + drawH/2, 0.0);              // Bottom Right
glVertex3d( posX - drawW/2, posY + drawH/2, 0.0);              // Bottom Left
glEnd();
}


I'm really at a loss of what's going on, from what I can tell, the square is having all of his pixels painted with the first pixel of the texture, but have no clue where I'm messing up : /  
 
Thanks in advance,
ZiklonE

Edit: Found out what was wrong by refreshing my memory with pure opengl tutorials. I was missing:
glTexCoord2d(u, v); before each vertex definition.

Pages: [1]