Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

Renderer::StarVertexBuffer Class Reference

#include <render.h>

Collaboration diagram for Renderer::StarVertexBuffer:

Collaboration graph
List of all members.

Public Member Functions

void addStar (const Point3f &, const Color &, float)
void finish ()
void render ()
void setBillboardOrientation (const Quatf &)
void start (bool _usePoints)
 StarVertexBuffer (unsigned int _capacity)
 ~StarVertexBuffer ()

Private Attributes

unsigned int capacity
unsigned char * colors
unsigned int nStars
float * texCoords
bool usePoints
Vec3f v0
Vec3f v1
Vec3f v2
Vec3f v3
float * vertices

Constructor & Destructor Documentation

Renderer::StarVertexBuffer::StarVertexBuffer unsigned int  _capacity  ) 
 

Definition at line 7048 of file render.cpp.

References capacity, colors, nStars, texCoords, and vertices.

07048                                                                  :
07049     capacity(_capacity),
07050     vertices(NULL),
07051     texCoords(NULL),
07052     colors(NULL),
07053     usePoints(false)
07054 {
07055     nStars = 0;
07056     vertices = new float[capacity * 12];
07057     texCoords = new float[capacity * 8];
07058     colors = new unsigned char[capacity * 16];
07059 
07060     // Fill the texture coordinate array now, since it will always have
07061     // the same contents.
07062     for (unsigned int i = 0; i < capacity; i++)
07063     {
07064         unsigned int n = i * 8;
07065         texCoords[n    ] = 0; texCoords[n + 1] = 0;
07066         texCoords[n + 2] = 1; texCoords[n + 3] = 0;
07067         texCoords[n + 4] = 1; texCoords[n + 5] = 1;
07068         texCoords[n + 6] = 0; texCoords[n + 7] = 1;
07069     }
07070 }

Renderer::StarVertexBuffer::~StarVertexBuffer  ) 
 

Definition at line 7072 of file render.cpp.

References colors, texCoords, and vertices.

07073 {
07074     if (vertices != NULL)
07075         delete vertices;
07076     if (colors != NULL)
07077         delete colors;
07078     if (texCoords != NULL)
07079         delete texCoords;
07080 }


Member Function Documentation

void Renderer::StarVertexBuffer::addStar const Point3f ,
const Color ,
float 
 

Definition at line 7130 of file render.cpp.

References capacity, colors, nStars, render(), usePoints, v0, v1, v2, v3, vertices, Vector3< T >::x, Vector3< T >::y, and Vector3< T >::z.

Referenced by StarRenderer::process().

07133 {
07134     if (nStars < capacity)
07135     {
07136         if (usePoints)
07137         {
07138             int n = nStars * 3;
07139             vertices[n + 0] = pos.x;
07140             vertices[n + 1] = pos.y;
07141             vertices[n + 2] = pos.z;
07142             color.get(colors + nStars * 4);
07143         }
07144         else
07145         {
07146             int n = nStars * 12;
07147             vertices[n + 0]  = pos.x + v0.x * size;
07148             vertices[n + 1]  = pos.y + v0.y * size;
07149             vertices[n + 2]  = pos.z + v0.z * size;
07150             vertices[n + 3]  = pos.x + v1.x * size;
07151             vertices[n + 4]  = pos.y + v1.y * size;
07152             vertices[n + 5]  = pos.z + v1.z * size;
07153             vertices[n + 6]  = pos.x + v2.x * size;
07154             vertices[n + 7]  = pos.y + v2.y * size;
07155             vertices[n + 8]  = pos.z + v2.z * size;
07156             vertices[n + 9]  = pos.x + v3.x * size;
07157             vertices[n + 10] = pos.y + v3.y * size;
07158             vertices[n + 11] = pos.z + v3.z * size;
07159             n = nStars * 16;
07160             color.get(colors + n);
07161             color.get(colors + n + 4);
07162             color.get(colors + n + 8);
07163             color.get(colors + n + 12);
07164         }
07165         nStars++;
07166     }
07167 
07168     if (nStars == capacity)
07169     {
07170         render();
07171         nStars = 0;
07172     }
07173 }

void Renderer::StarVertexBuffer::finish  ) 
 

Definition at line 7120 of file render.cpp.

References render(), and usePoints.

Referenced by Renderer::renderStars().

07121 {
07122     render();
07123     glDisableClientState(GL_COLOR_ARRAY);
07124     glDisableClientState(GL_VERTEX_ARRAY);
07125     glDisableClientState(GL_TEXTURE_COORD_ARRAY);
07126     if (usePoints)
07127         glEnable(GL_TEXTURE_2D);
07128 }

void Renderer::StarVertexBuffer::render  ) 
 

Definition at line 7108 of file render.cpp.

References nStars, and usePoints.

Referenced by addStar(), and finish().

07109 {
07110     if (nStars != 0)
07111     {
07112         if (usePoints)
07113             glDrawArrays(GL_POINTS, 0, nStars);
07114         else
07115             glDrawArrays(GL_QUADS, 0, nStars * 4);
07116         nStars = 0;
07117     }
07118 }

void Renderer::StarVertexBuffer::setBillboardOrientation const Quatf  ) 
 

Definition at line 7175 of file render.cpp.

References v0, v1, v2, and v3.

Referenced by Renderer::renderStars().

07176 {
07177     Mat3f m = q.toMatrix3();
07178     v0 = Vec3f(-1, -1, 0) * m;
07179     v1 = Vec3f( 1, -1, 0) * m;
07180     v2 = Vec3f( 1,  1, 0) * m;
07181     v3 = Vec3f(-1,  1, 0) * m;
07182 }

void Renderer::StarVertexBuffer::start bool  _usePoints  ) 
 

Definition at line 7082 of file render.cpp.

References colors, texCoords, usePoints, and vertices.

Referenced by Renderer::renderStars().

07083 {
07084     usePoints = _usePoints;
07085 
07086     glEnableClientState(GL_VERTEX_ARRAY);
07087     glVertexPointer(3, GL_FLOAT, 0, vertices);
07088     glEnableClientState(GL_COLOR_ARRAY);
07089     glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors);
07090     if (!usePoints)
07091     {
07092         glEnableClientState(GL_TEXTURE_COORD_ARRAY);
07093         glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
07094     }
07095     else
07096     {
07097         // An option to control the size of the stars would be helpful.
07098         // Which size looks best depends a lot on the resolution and the
07099         // type of display device.
07100         // glPointSize(2.0f);
07101         // glEnable(GL_POINT_SMOOTH);
07102         glDisableClientState(GL_TEXTURE_COORD_ARRAY);
07103         glDisable(GL_TEXTURE_2D);
07104     }
07105     glDisableClientState(GL_NORMAL_ARRAY);
07106 }


Member Data Documentation

unsigned int Renderer::StarVertexBuffer::capacity [private]
 

Definition at line 225 of file render.h.

Referenced by addStar(), and StarVertexBuffer().

unsigned char* Renderer::StarVertexBuffer::colors [private]
 

Definition at line 229 of file render.h.

Referenced by addStar(), start(), StarVertexBuffer(), and ~StarVertexBuffer().

unsigned int Renderer::StarVertexBuffer::nStars [private]
 

Definition at line 226 of file render.h.

Referenced by addStar(), render(), and StarVertexBuffer().

float* Renderer::StarVertexBuffer::texCoords [private]
 

Definition at line 228 of file render.h.

Referenced by start(), StarVertexBuffer(), and ~StarVertexBuffer().

bool Renderer::StarVertexBuffer::usePoints [private]
 

Definition at line 231 of file render.h.

Referenced by addStar(), finish(), render(), and start().

Vec3f Renderer::StarVertexBuffer::v0 [private]
 

Definition at line 230 of file render.h.

Referenced by addStar(), and setBillboardOrientation().

Vec3f Renderer::StarVertexBuffer::v1 [private]
 

Definition at line 230 of file render.h.

Referenced by addStar(), and setBillboardOrientation().

Vec3f Renderer::StarVertexBuffer::v2 [private]
 

Definition at line 230 of file render.h.

Referenced by addStar(), and setBillboardOrientation().

Vec3f Renderer::StarVertexBuffer::v3 [private]
 

Definition at line 230 of file render.h.

Referenced by addStar(), and setBillboardOrientation().

float* Renderer::StarVertexBuffer::vertices [private]
 

Definition at line 227 of file render.h.

Referenced by addStar(), start(), StarVertexBuffer(), and ~StarVertexBuffer().


The documentation for this class was generated from the following files:
Generated on Sat Jan 14 22:33:34 2006 for Celestia by  doxygen 1.4.1