Hi all!
I'm trying to load a png image with OpenSG and then use it for
texture a Cube (i'm doing some testing...) in plain OpenGL. Can this
be done?
I have been looking for through the mailing list archives but i've
not found the right answers :(
Here is a snippet of my code:
#define MAX_NO_TEXTURES 1
#define CUBE_TEXTURE 0
GLuint texture_id[MAX_NO_TEXTURES];
void init(void){
glEnable ( GL_TEXTURE_2D );
glGenTextures (1, texture_id);
ImagePtr im=Image::create();
im->read("the_image.png");
glBindTexture ( GL_TEXTURE_2D, texture_id[CUBE_TEXTURE] );
glTexImage2D ( GL_TEXTURE_2D, 0, GL_RGB, im->getWidth(),
im->getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, im->getData() );
}
This
function is called after creating a glut window and all the opengl
context. The display function is something similar to the next:
void display( void )
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glLoadIdentity ( );
glPushMatrix();
glTranslatef ( 0.0, 0.0, -5.0 );
glBindTexture ( GL_TEXTURE_2D, texture_id[0] );
glBegin ( GL_QUADS );
// Front Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
// Back Face
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
// Top Face...
// Bottom Face...
// Right face...
// Left Face ...
glEnd();
glPopMatrix();
glutSwapBuffers();
}
What I'm doing wrong? What I'm getting is a white cube :(
The original code is from the nehe's 6th tutorial (texture mapping)
in the glut version.
I'm compiling in Linux with the 1.8 version of OpenSG.
--
Chus Puras
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users