~glmark2-dev/glmark2/libmatrix-util

« back to all changes in this revision

Viewing changes to scenetexture.cpp

  • Committer: Alexandros Frantzis
  • Date: 2010-07-07 10:32:18 UTC
  • Revision ID: git-v1:d2683504fc3cc84e7f3aefd917147037706cecf0
Initial release of original OpenGL code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "scene.h"
 
2
 
 
3
SceneTexture::~SceneTexture()
 
4
{
 
5
    for(unsigned i = 0; i < 3; i++)
 
6
        glDeleteTextures(1, &mTexture[i]);
 
7
}
 
8
 
 
9
int SceneTexture::load()
 
10
{
 
11
    Model model;
 
12
    
 
13
    if(!model.load_3ds("data/models/cube.3ds"))
 
14
        return 0;
 
15
    
 
16
    if(!load_texture("data/textures/crate-base.bmp", mTexture))
 
17
        return 0;
 
18
    
 
19
    model.calculate_normals();
 
20
    model.convert_to_mesh(&mCubeMesh);
 
21
    mCubeMesh.build_list();
 
22
    
 
23
    mRotationSpeed = Vector3f(36.0f, 36.0f, 36.0f);
 
24
    
 
25
    mRunning = false;
 
26
    
 
27
    mPartsQty = 3;
 
28
    mPartDuration = new double[mPartsQty];
 
29
    mAverageFPS = new unsigned[mPartsQty];
 
30
    mScoreScale = new float[mPartsQty];
 
31
    
 
32
    mScoreScale[0] = 0.471f;
 
33
    mScoreScale[1] = 0.533f;
 
34
    mScoreScale[2] = 0.405f;
 
35
    
 
36
    mScore = 0;
 
37
    
 
38
    mPartDuration[0] = 10.0;
 
39
    mPartDuration[1] = 10.0;
 
40
    mPartDuration[2] = 10.0;
 
41
    
 
42
    mCurrentPart = 0;
 
43
    
 
44
    return 1;
 
45
}
 
46
 
 
47
void SceneTexture::start()
 
48
{
 
49
    GLfloat lightAmbient[] = {0.0f, 0.0f, 0.0f, 1.0f};
 
50
    GLfloat lightDiffuse[] = {0.8f, 0.8f, 0.8f, 1.0f};
 
51
    GLfloat lightPosition[] = {20.0f, 20.0f, 10.0f, 1.0f};
 
52
    
 
53
    glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
 
54
    glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);
 
55
    glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
 
56
    glEnable(GL_LIGHT0);
 
57
    
 
58
    glEnable(GL_TEXTURE_2D);
 
59
    
 
60
    mCurrentFrame = 0;
 
61
    mRunning = true;
 
62
    mStartTime = SDL_GetTicks() / 1000.0;
 
63
    mLastTime = mStartTime;
 
64
}
 
65
 
 
66
void SceneTexture::update()
 
67
{
 
68
    mCurrentTime = SDL_GetTicks() / 1000.0;
 
69
    mDt = mCurrentTime - mLastTime;
 
70
    mLastTime = mCurrentTime;
 
71
    
 
72
    mElapsedTime = mCurrentTime - mStartTime;
 
73
    
 
74
    if(mElapsedTime >= mPartDuration[mCurrentPart])
 
75
    {
 
76
        mAverageFPS[mCurrentPart] = mCurrentFrame / mElapsedTime;
 
77
        
 
78
        switch(mCurrentPart)
 
79
        {
 
80
        case 0:
 
81
            printf("Texture filtering\n");
 
82
            printf("    Nearest                       FPS: %u\n",  mAverageFPS[mCurrentPart]);
 
83
            break;
 
84
        case 1:
 
85
            printf("    Linear                        FPS: %u\n",  mAverageFPS[mCurrentPart]);
 
86
            break;
 
87
        case 2:
 
88
            printf("    Mipmapped                     FPS: %u\n",  mAverageFPS[mCurrentPart]);
 
89
            break;
 
90
        }
 
91
        mScore += mAverageFPS[mCurrentPart];
 
92
        mCurrentPart++;
 
93
        start();
 
94
        if(mCurrentPart >= mPartsQty)
 
95
            mRunning = false;
 
96
    }
 
97
    
 
98
    mRotation += mRotationSpeed * mDt;
 
99
    
 
100
    mCurrentFrame++;
 
101
}
 
102
 
 
103
void SceneTexture::draw()
 
104
{
 
105
    glLoadIdentity();
 
106
    glColor3f(1.0f, 1.0f, 1.0f);
 
107
    glTranslatef(0.0f, 0.0f, -4.0f);
 
108
    
 
109
    glRotatef(mRotation.x, 1.0f, 0.0f, 0.0f);
 
110
    glRotatef(mRotation.y, 0.0f, 1.0f, 0.0f);
 
111
    glRotatef(mRotation.z, 0.0f, 0.0f, 1.0f);
 
112
    
 
113
    switch(mCurrentPart)
 
114
    {
 
115
    case 0:
 
116
        glBindTexture(GL_TEXTURE_2D, mTexture[0]);
 
117
        glCallList(mCubeMesh.mBuildList);
 
118
        break;
 
119
    case 1:
 
120
        glBindTexture(GL_TEXTURE_2D, mTexture[1]);
 
121
        glCallList(mCubeMesh.mBuildList);
 
122
    case 2:
 
123
        glBindTexture(GL_TEXTURE_2D, mTexture[2]);
 
124
        glCallList(mCubeMesh.mBuildList);
 
125
        break;
 
126
    }    
 
127
}