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 6

Go to most recent revision | 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
            orgfx_point3 offset = {200, 500, 0};
201
            orgfx_point3 scale = {25.0, 25.0, 25.0};
202
            orgfx_point3 rot = {-1.5,0,rad};
203
 
204
            mesh.scale = scale;
205
            mesh.translation = offset;
206
            mesh.rotation = rot;
207
 
208
            orgfx3d_draw_mesh(&mesh, 0, 0);
209
 
210
            orgfx_clear_zbuffer();
211
            for(i = 0; i < 1500000; ++i);
212
 
213
            orgfx_enable_zbuffer(1);
214
 
215
            mesh.translation.x += 300;
216
            mesh.rotation.z = -rad;
217
 
218
            orgfx3d_draw_mesh(&mesh, 1, 0);
219
 
220
            orgfx_enable_zbuffer(0);
221
            break;
222
        }
223
        }
224
 
225
        // Increment state
226
        stateTimer++;
227
        if(stateTimer >= stateTimerMax)
228
        {
229
            stateTimer = 0;
230
            state++;
231
            if(state >= LAST_STATE)
232
                state = STATE_ORSOC_SPLASH;
233
        }
234
 
235
        rad += 0.05;
236
        if(rad >= M_PI*2) rad -= M_PI*2;
237
 
238
        for(i = 0; i < 500000; ++i);
239
        // Swap buffers
240
        orgfxplus_flip();
241
    }
242
}
243
 
244
 

powered by: WebSVN 2.1.0

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