File: Stars.cpp

package info (click to toggle)
sear 0.5.0-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,408 kB
  • ctags: 2,580
  • sloc: cpp: 14,902; sh: 10,890; makefile: 172
file content (64 lines) | stat: -rw-r--r-- 1,313 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifdef HAVE_CONFIG_H
    #include "config.h"
#endif

#include "Stars.h"


#include <sage/GL.h>
#include <wfmath/vector.h>
#include <wfmath/MersenneTwister.h>

namespace Sear {

Stars::Stars()
{
    m_locations = new Vertex_3[1000];
    m_colors = new Color_4[1000];
    
    WFMath::MTRand twister;
    
    for (unsigned int S=0; S < 1000; ++S) {
        WFMath::Vector<3> dir(twister.rand(), twister.rand(), twister.rand());
        dir -= WFMath::Vector<3>(0.5, 0.5, 0.5);
        dir = dir.normalize() * 100;
        
        m_locations[S].x = dir.x();
        m_locations[S].y = dir.y();
        m_locations[S].z = dir.z();
        
        m_colors[S].r = twister.randInt(128) + 128;
        m_colors[S].g = m_colors[S].b = m_colors[S].r; // always white for now
        m_colors[S].a = 0xff;
    }

}

Stars::~Stars()
{
    delete[] m_locations;
    delete[] m_colors;

}

void Stars::render()
{
    glDepthMask(GL_FALSE);

    
    glEnableClientState(GL_COLOR_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);
    
    glColorPointer(4, GL_UNSIGNED_BYTE, 0, m_colors);
    glVertexPointer(3, GL_FLOAT, 0, m_locations);

    glDrawArrays(GL_POINTS, 0, 1000);

    glDisableClientState(GL_COLOR_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);
    
    glDepthMask(GL_TRUE);
 
}

} // of namespace Sear