PDA

View Full Version : Binding Textures in opengl window



beginQT
29th September 2011, 13:52
Hello,

I am trying to display an Image in the Opengl window for that I have created the .QRC file and named it as Texture array. And remaining code is as below.

1st I am trying to precompile the textures:
I am calling 2 functions from the PaintGL method.
preCompile_Textures() for setting up a quad for my Imaage dimensions.
Draw_Textures() for drawing the actual image for given positions

void GLWidget::paintGL()
{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslated(0.0f,0.0f, 0.0f);
//glScaled(scale,scale,scale);
glRotated(0.0f, 1.0f, 0.0f, 0.0f);
glRotated(0.0f, 0.0f, 1.0f, 0.0f);
glRotated(0.0f, 0.0f, 0.0f, 1.0f);

// Generate Lists required for Pre-Compilation

gen_texture= glGenLists( 17);

// Car Texture - Position will be loaded later
// Use Length for Width and changes in ConFig file does not modify width
struct_Dimensions.Init( 200*2.0946, 400*1.10 );
preCompile_Textures( gen_texture + 0, struct_Dimensions , Textures[0] );



Draw_Textures(struct_Postions, struct_Rotations, struct_Color,gen_texture + 0);
}

And, preCompile_Textures( )

void GLWidget::preCompile_Textures
(
int _iIndex ,
sDimensions _sDim ,
GLuint _iPicID
)
{
// Call NewList to compile the data below
glNewList(_iIndex , GL_COMPILE );

// Enable certian co-ordinates for Belnd
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);

// Blend along with Alpha Channel Enabled
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

// Bind Texture of the picture with the quad drawn
glBindTexture(GL_TEXTURE_2D, _iPicID );

// Begin Drawing the Quad
glBegin(GL_QUADS);

glTexCoord2d(0.0,1.0);
glVertex3f( -_sDim.fWidth/2 , -_sDim.fHeight/2 , 0.0f);

glTexCoord2d(0.0,0.0);
glVertex3f( -_sDim.fWidth/2 , +_sDim.fHeight/2 , 0.0f);

glTexCoord2d(1.0,0.0);
glVertex3f( +_sDim.fWidth/2 , +_sDim.fHeight/2 , 0.0f);

glTexCoord2d(1.0,1.0);
glVertex3f( +_sDim.fWidth/2 , -_sDim.fHeight/2 , 0.0f);

glEnd();

// End CallList
glEndList();
}

Draw_Textures:

void GLWidget::vDrawTex
(
sPos _sP ,
sRot _sRot ,
sColor _sClr ,
int _iIndex
)
{


glPushMatrix( );


glTranslated( _sP.fX , _sP.fY , _sP.fZ );
glRotatef( _sRot.fAngle , _sRot.fX_R , _sRot.fY_R , _sRot.fZ_R );
glColor4f( _sClr.fR , _sClr.fG , _sClr.fB , 1.0f );

// Call the required texture from the list
glCallList( _iIndex );
updateGL();
//Return the Screen back to normal scenario
glPopMatrix();
}

After doing this it compiles well but I cannot see any Image being loaded and sometimes it crashes too.

Please let me know what went wrong in the above code and also let me know if I can do the same differently using some QT API's.

Thanks in Advance!

beginQT
4th October 2011, 14:30
I think I have confused a lot, I dint get any reply,

Here actually my problem is I need to load some images on to my Opengl Window, I am using Devil IL, ILU and ILUT libraries for doing that stuff. But unfortunately there is an error saying that "ilutGLLoadImage" cannot be resolved.

Can anyone please help me how to use Devil libraries in QT for acheiving this task?

Thanks in Advance!