OpenCores
URL https://opencores.org/ocsvn/orsoc_graphics_accelerator/orsoc_graphics_accelerator/trunk

Subversion Repositories orsoc_graphics_accelerator

[/] [orsoc_graphics_accelerator/] [trunk/] [sw/] [examples/] [bare/] [demo.c] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 maiden
#include "orgfx_plus.h"
2
#include "orgfx_3d.h"
3
#include "orgfx.h"
4
#include "orgfx_bitmap_font.h"
5
#include <math.h>
6
 
7
#include "cube.obj.h"
8
#include "humanoid_tri.obj.h"
9
#include "Bahamut_cc.png.h"
10
 
11
#include "franklin_font.h"
12
 
13
// State defines
14
enum
15
{
16
    STATE_ORSOC_SPLASH = 0,
17
    STATE_GEOMETRY,
18
    STATE_FILLMODES,
19
    STATE_COLORKEY,
20
    STATE_3D,
21
 
22
    LAST_STATE
23
};
24
 
25
// Color defines
26
#define C_RED 0xf800
27
#define C_WHITE 0xffff
28
#define C_BLACK 0x0000
29
#define C_BLUE 0x003f
30
#define C_GREEN 0x07c0
31
 
32
int main(void)
33
{
34
    // Initialize screen, with double buffering
35
    int screen = orgfxplus_init(640, 480, 16, 1, 1);
36
 
37
    orgfx_enable_cliprect(1);
38
 
39
    // Initialize bahamut_sprite
40
    int bahamut_sprite = init_Bahamut_cc_sprite();
41
 
42
    // Initialize franklin_font
43
    orgfx_bitmap_font franklin_font = init_franklin_font(2, 16);
44
 
45
    // Initialize mesh
46
    orgfx_mesh mesh = init_humanoid_tri_mesh();
47
 
48
    int state = STATE_ORSOC_SPLASH;
49
//    int state = STATE_3D;
50
    int stateTimer = 0;
51
    const int stateTimerMax = 20;
52
    int i;
53
 
54
    orgfxplus_fill(0,0,640*FIXEDW,480*FIXEDW,C_WHITE);
55
    orgfxplus_flip();
56
 
57
    float rad = 0;
58
 
59
    while(1)
60
    {
61
        // Clear screen
62
        orgfxplus_fill(0,0,640*FIXEDW,480*FIXEDW,C_WHITE);
63
        for(i = 0; i < 1500000; ++i);
64
 
65
        orgfxplus_colorkey(0xf81f, 1);
66
 
67
        // State specific logic
68
        switch(state)
69
        {
70
        case STATE_ORSOC_SPLASH:
71
        {
72
            // Add a logo
73
 
74
            orgfx_put_bitmap_text(&franklin_font, 50*FIXEDW, 300*FIXEDW,
75
                            L"ORSOC Graphics Accelerator Demo");
76
        for(i = 0; i < 500000; ++i);
77
 
78
            orgfx_put_bitmap_text(&franklin_font, 50*FIXEDW, 340*FIXEDW,
79
                            L"Per Lenander & Anton Fosselius, 2012");
80
            break;
81
        }
82
        case STATE_GEOMETRY:
83
        {
84
            orgfxplus_fill(50*FIXEDW, 50*FIXEDW,
85
                            150*FIXEDW, 150*FIXEDW,
86
                            C_RED);
87
 
88
            orgfxplus_line(-350*FIXEDW,50*FIXEDW,
89
                            450*FIXEDW,100*FIXEDW,
90
                            C_RED);
91
            orgfxplus_line(400*FIXEDW,50*FIXEDW,
92
                            450*FIXEDW,150*FIXEDW,
93
                            C_GREEN);
94
            orgfxplus_line(450*FIXEDW,100*FIXEDW,
95
                            350*FIXEDW,150*FIXEDW,
96
                            C_BLUE);
97
 
98
            orgfxplus_triangle(100*FIXEDW,-250*FIXEDW,
99
                                200*FIXEDW,250*FIXEDW,
100
                                150*FIXEDW,350*FIXEDW,
101
                                C_RED);
102
 
103
            orgfxplus_colorkey(0xf81f, 0);
104
            orgfxplus_draw_surface(300*FIXEDW, 200*FIXEDW,
105
                                    bahamut_sprite);
106
 
107
            break;
108
        }
109
        case STATE_FILLMODES:
110
        {
111
            orgfx_point3 offset = {200, 200, 0};
112
            orgfx_point3 rotation = {0,0,rad};
113
 
114
            orgfx_enable_transform(1);
115
 
116
            orgfx_matrix m = orgfx3d_identity();
117
            m = orgfx3d_rotateX(m, rotation.x);
118
            m = orgfx3d_rotateY(m, rotation.y);
119
            m = orgfx3d_rotateZ(m, rotation.z);
120
            m = orgfx3d_translate(m, offset);
121
            orgfx3d_set_matrix(m);
122
 
123
            orgfx_set_colors(C_RED, C_GREEN, C_BLUE);
124
 
125
            // Flat color (Red)
126
            orgfx_triangle(-50*FIXEDW, -50*FIXEDW,
127
                            50*FIXEDW, -50*FIXEDW,
128
                            0*FIXEDW, 50*FIXEDW,
129
                            0);
130
 
131
            offset.x = 50;
132
 
133
            m = orgfx3d_identity();
134
            m = orgfx3d_rotateX(m, rotation.x);
135
            m = orgfx3d_rotateY(m, rotation.y);
136
            m = orgfx3d_rotateZ(m, rotation.z);
137
            m = orgfx3d_translate(m, offset);
138
            orgfx3d_set_matrix(m);
139
 
140
            // Interpolated color RGB
141
            orgfxplus_alpha(0x00ffffff, 1);
142
 
143
            orgfx_triangle(-50*FIXEDW, -50*FIXEDW,
144
                            50*FIXEDW, -50*FIXEDW,
145
                            0*FIXEDW, 50*FIXEDW,
146
                            1);
147
            orgfxplus_alpha(GFX_OPAQUE, 0);
148
 
149
            offset.x = 300;
150
            offset.y = 300;
151
 
152
            m = orgfx3d_identity();
153
            m = orgfx3d_rotateX(m, rotation.x);
154
            m = orgfx3d_rotateY(m, rotation.y);
155
            m = orgfx3d_rotateZ(m, rotation.z);
156
            m = orgfx3d_translate(m, offset);
157
            orgfx3d_set_matrix(m);
158
 
159
            orgfx_enable_tex0(1);
160
            orgfxplus_bind_tex0(bahamut_sprite);
161
 
162
            // Textured triangle
163
            orgfx_uv(0,0,186,0,0,248);
164
            orgfx_triangle(-98*FIXEDW, -124*FIXEDW,
165
                            98*FIXEDW, -124*FIXEDW,
166
                            -98*FIXEDW, 124*FIXEDW,
167
                            1);
168
 
169
            orgfx_uv(186,0,186,248,0,248);
170
            orgfx_triangle(98*FIXEDW, -124*FIXEDW,
171
                            98*FIXEDW, 124*FIXEDW,
172
                            -98*FIXEDW, 124*FIXEDW,
173
                            1);
174
 
175
            orgfx_enable_tex0(0);
176
 
177
            orgfx_enable_transform(0);
178
 
179
            break;
180
        }
181
        case STATE_COLORKEY:
182
        {
183
 
184
            orgfxplus_colorkey(0xf81f, 0);
185
            orgfxplus_draw_surface(-50*FIXEDW, -50*FIXEDW,
186
                                    bahamut_sprite);
187
 
188
            orgfxplus_colorkey(0xf81f, 1);
189
            orgfxplus_draw_surface(250*FIXEDW, 50*FIXEDW,
190
                                    bahamut_sprite);
191
 
192
            orgfxplus_alpha(0xffffff00 | (unsigned int)((1+sin(2*rad))/2.0*0xff), 1);
193
            orgfxplus_draw_surface(150*FIXEDW, 250*FIXEDW,
194
                                    bahamut_sprite);
195
            orgfxplus_alpha(GFX_OPAQUE, 0);
196
            break;
197
        }
198
        case STATE_3D:
199
        {
200 9 maiden
            orgfx_point3 translation = {200, 500, 0};
201
            orgfx_point3 rotation = {-1.5,0,rad};
202 5 maiden
            orgfx_point3 scale = {25.0, 25.0, 25.0};
203
 
204 9 maiden
            orgfx3d_draw_mesh(&mesh, translation, rotation, scale, 0, 0);
205 5 maiden
 
206
            orgfx_clear_zbuffer();
207
            for(i = 0; i < 1500000; ++i);
208
 
209
            orgfx_enable_zbuffer(1);
210
 
211 9 maiden
            translation.x += 300;
212
            rotation.z = -rad;
213 5 maiden
 
214 9 maiden
            orgfx3d_draw_mesh(&mesh, translation, rotation, scale, 1, 0);
215 5 maiden
 
216
            orgfx_enable_zbuffer(0);
217
            break;
218
        }
219
        }
220
 
221
        // Increment state
222
        stateTimer++;
223
        if(stateTimer >= stateTimerMax)
224
        {
225
            stateTimer = 0;
226
            state++;
227
            if(state >= LAST_STATE)
228
                state = STATE_ORSOC_SPLASH;
229
        }
230
 
231
        rad += 0.05;
232
        if(rad >= M_PI*2) rad -= M_PI*2;
233
 
234
        for(i = 0; i < 500000; ++i);
235
        // Swap buffers
236
        orgfxplus_flip();
237
    }
238
}
239
 
240
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.