add PGFrameStyle::set_texture

This commit is contained in:
David Rose 2003-06-25 20:35:02 +00:00
parent 1f1b51321c
commit 2e38ab36eb
3 changed files with 90 additions and 1 deletions

View File

@ -38,6 +38,7 @@ INLINE PGFrameStyle::
PGFrameStyle(const PGFrameStyle &copy) : PGFrameStyle(const PGFrameStyle &copy) :
_type(copy._type), _type(copy._type),
_color(copy._color), _color(copy._color),
_texture(copy._texture),
_width(copy._width) _width(copy._width)
{ {
} }
@ -51,6 +52,7 @@ INLINE void PGFrameStyle::
operator = (const PGFrameStyle &copy) { operator = (const PGFrameStyle &copy) {
_type = copy._type; _type = copy._type;
_color = copy._color; _color = copy._color;
_texture = copy._texture;
_width = copy._width; _width = copy._width;
} }
@ -113,6 +115,49 @@ get_color() const {
return _color; return _color;
} }
////////////////////////////////////////////////////////////////////
// Function: PGFrameStyle::set_texture
// Access: Published
// Description: Specifies a texture that should be applied to the
// frame.
////////////////////////////////////////////////////////////////////
INLINE void PGFrameStyle::
set_texture(Texture *texture) {
_texture = texture;
}
////////////////////////////////////////////////////////////////////
// Function: PGFrameStyle::has_texture
// Access: Published
// Description: Returns true if a texture has been applied to the
// frame.
////////////////////////////////////////////////////////////////////
INLINE bool PGFrameStyle::
has_texture() const {
return !_texture.is_null();
}
////////////////////////////////////////////////////////////////////
// Function: PGFrameStyle::get_texture
// Access: Published
// Description: Returns the texture that has been applied to the
// frame, or NULL if no texture has been applied.
////////////////////////////////////////////////////////////////////
INLINE Texture *PGFrameStyle::
get_texture() const {
return _texture;
}
////////////////////////////////////////////////////////////////////
// Function: PGFrameStyle::clear_texture
// Access: Published
// Description: Removes the texture from the frame.
////////////////////////////////////////////////////////////////////
INLINE void PGFrameStyle::
clear_texture() {
_texture.clear();
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PGFrameStyle::set_width // Function: PGFrameStyle::set_width
// Access: Published // Access: Published

View File

@ -24,6 +24,14 @@
#include "transparencyAttrib.h" #include "transparencyAttrib.h"
#include "pointerTo.h" #include "pointerTo.h"
#include "nodePath.h" #include "nodePath.h"
#include "textureAttrib.h"
#include "renderState.h"
// Specifies the UV range of textures applied to the frame. Maybe
// we'll have a reason to make this a parameter of the frame style one
// day, but for now it's hardcoded to fit the entire texture over the
// rectangular frame.
static const LVecBase4f uv_range = LVecBase4f(0.0f, 1.0f, 0.0f, 1.0f);
ostream & ostream &
operator << (ostream &out, PGFrameStyle::Type type) { operator << (ostream &out, PGFrameStyle::Type type) {
@ -58,6 +66,9 @@ operator << (ostream &out, PGFrameStyle::Type type) {
void PGFrameStyle:: void PGFrameStyle::
output(ostream &out) const { output(ostream &out) const {
out << _type << " color = " << _color << " width = " << _width; out << _type << " color = " << _color << " width = " << _width;
if (has_texture()) {
out << " texture = " << *get_texture();
}
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -167,7 +178,7 @@ generate_flat_geom(const LVecBase4f &frame) {
float bottom = frame[2]; float bottom = frame[2];
float top = frame[3]; float top = frame[3];
PTA_int lengths=PTA_int::empty_array(0); PTA_int lengths;
lengths.push_back(4); lengths.push_back(4);
PTA_Vertexf verts; PTA_Vertexf verts;
@ -184,6 +195,25 @@ generate_flat_geom(const LVecBase4f &frame) {
PTA_Colorf colors; PTA_Colorf colors;
colors.push_back(_color); colors.push_back(_color);
geom->set_colors(colors, G_OVERALL); geom->set_colors(colors, G_OVERALL);
if (has_texture()) {
// Generate UV's.
left = uv_range[0];
right = uv_range[1];
bottom = uv_range[2];
top = uv_range[3];
PTA_TexCoordf uvs;
uvs.push_back(TexCoordf(left, top));
uvs.push_back(TexCoordf(left, bottom));
uvs.push_back(TexCoordf(right, top));
uvs.push_back(TexCoordf(right, bottom));
geom->set_texcoords(uvs, G_PER_VERTEX);
CPT(RenderState) state =
RenderState::make(TextureAttrib::make(get_texture()));
gnode->set_geom_state(0, state);
}
return gnode.p(); return gnode.p();
} }
@ -344,6 +374,9 @@ generate_bevel_geom(const LVecBase4f &frame, bool in) {
geom->set_lengths(lengths); geom->set_lengths(lengths);
geom->set_coords(verts); geom->set_coords(verts);
geom->set_colors(colors, G_PER_COMPONENT); geom->set_colors(colors, G_PER_COMPONENT);
// For now, beveled and grooved geoms don't support textures. Easy
// to add if anyone really wants this.
return gnode.p(); return gnode.p();
} }
@ -573,6 +606,9 @@ generate_groove_geom(const LVecBase4f &frame, bool in) {
geom->set_lengths(lengths); geom->set_lengths(lengths);
geom->set_coords(verts); geom->set_coords(verts);
geom->set_colors(colors, G_PER_COMPONENT); geom->set_colors(colors, G_PER_COMPONENT);
// For now, beveled and grooved geoms don't support textures. Easy
// to add if anyone really wants this.
return gnode.p(); return gnode.p();
} }

View File

@ -22,6 +22,8 @@
#include "pandabase.h" #include "pandabase.h"
#include "luse.h" #include "luse.h"
#include "texture.h"
#include "pointerTo.h"
class PandaNode; class PandaNode;
class NodePath; class NodePath;
@ -54,6 +56,11 @@ PUBLISHED:
INLINE void set_color(const Colorf &color); INLINE void set_color(const Colorf &color);
INLINE const Colorf &get_color() const; INLINE const Colorf &get_color() const;
INLINE void set_texture(Texture *texture);
INLINE bool has_texture() const;
INLINE Texture *get_texture() const;
INLINE void clear_texture();
INLINE void set_width(float x, float y); INLINE void set_width(float x, float y);
INLINE void set_width(const LVecBase2f &width); INLINE void set_width(const LVecBase2f &width);
INLINE const LVecBase2f &get_width() const; INLINE const LVecBase2f &get_width() const;
@ -72,6 +79,7 @@ private:
private: private:
Type _type; Type _type;
Colorf _color; Colorf _color;
PT(Texture) _texture;
LVecBase2f _width; LVecBase2f _width;
}; };