[Plib-users] texture on pui button
Brought to you by:
sjbaker
|
From: <Rol...@t-...> - 2002-07-23 07:21:28
|
Hello,
I would like to draw a puButton with a texture on it. Somehow it reflects the
color of the texture, i.e. if I use a dark blue marble image the button has a
flat dark blue surface, but I cannot see the texture itself.
What am I doing wrong ?
I use the following to create textured button :
puImageButton.h:
#ifndef INCL_PUIMAGEBUTTON_H
#define INCL_PUIMAGEBUTTON_H
#include <plib/pu.h>
#include <plib/ssg.h>
class puImageButton : public puButton
{
public:
puImageButton(int,int,int,int,const char *);
void draw(int dx,int dy);
protected:
ssgTexture *texture;
};
#endif
puImageButton.cpp:
#include "puImageButton.h"
#include <iostream.h>
puImageButton::puImageButton(int minx,int miny,int maxx,int maxy,const char
*image) : puButton(minx,miny,maxx,maxy)
{
texture=new ssgTexture(image);
cerr << "texture handle : " << texture->getHandle() << endl;
}
void puImageButton::draw(int dx,int dy)
{
if (!visible || (window!=puGetWindow())) return;
puButton::draw(dx,dy);
int m=4;
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture->getHandle());
glColor4f(1.0,1.0,1.0,1.0);
glBegin(GL_QUADS);
glTexCoord2f(dx+abox.min[0]+m,dy+abox.min[1]+m); // top left
glVertex2i(dx+abox.min[0]+m,dy+abox.min[1]+m);
glTexCoord2f(dx+abox.min[0]+m,dy+abox.max[1]-m); // bottom left
glVertex2i(dx+abox.min[0]+m,dy+abox.max[1]-m);
glTexCoord2f(dx+abox.max[0]-m,dy+abox.max[1]-m); // bottom right
glVertex2i(dx+abox.max[0]-m,dy+abox.max[1]-m);
glTexCoord2f(dx+abox.max[0]-m,dy+abox.min[1]+m); // top right
glVertex2i(dx+abox.max[0]-m,dy+abox.min[1]+m);
glEnd();
glDisable(GL_TEXTURE_2D);
}
and finally in the main program after puInit():
new puImageButton(SCREEN_WIDTH-75,11,SCREEN_WIDTH-11,75,"data/key.rgb");
When called it outputs:
texture handle : 2
so, the texture should have been loaded ok.
Thanks for hints,
Rolf
--
Rolf Jakob at home (rj...@du...)
WWW : http://www.franken.de/users/duffy1/rjakob (KDE-Utils and CCS)
|