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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [demo_app/] [main_cubes.c] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 specular
//=======================================================================
2
// Project Monophony
3
//   Wire-Frame 3D Graphics Accelerator IP Core
4
//
5
// File:
6
//   main_cubes.c
7
//
8
// Abstract:
9
//   3D model(Cubes) rendering sample program.
10
//
11
// Author:
12 9 specular
//   Kenji Ishimaru (info.info.wf3d@gmail.com)
13 2 specular
//
14
//======================================================================
15
//
16
// Copyright (c) 2015, Kenji Ishimaru
17
// All rights reserved.
18
//
19
// Redistribution and use in source and binary forms, with or without
20
// modification, are permitted provided that the following conditions are met:
21
//
22
//  -Redistributions of source code must retain the above copyright notice,
23
//   this list of conditions and the following disclaimer.
24
//  -Redistributions in binary form must reproduce the above copyright notice,
25
//   this list of conditions and the following disclaimer in the documentation
26
//   and/or other materials provided with the distribution.
27
//
28
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
30
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
32
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
35
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
36
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
37
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
38
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
//
40
// Revision History
41
 
42 4 specular
#include "mp_hwdep.h"
43
#include "mp_lib.h"
44 2 specular
#include <stdio.h>
45
 
46
float triangle[] = {
47
  // front
48
  0.25,  0.25, 0.25,  // trianmpe0
49
  -0.25,  0.25, 0.25,
50
  -0.25, -0.25, 0.25,
51
   0.25,  0.25, 0.25,  // trianmpe1
52
  -0.25, -0.25, 0.25,
53
   0.25, -0.25, 0.25,
54
  // top
55
   0.25,  0.25, 0.0,      // trianmpe0
56
  -0.25,  0.25, 0.0,
57
  -0.25,  0.25, 0.25,
58
   0.25,  0.25, 0.0,      // trianmpe1
59
  -0.25,  0.25, 0.25,
60
   0.25,  0.25, 0.25,
61
  // bottom
62
   0.25, -0.25, 0.25,  // trianmpe0
63
  -0.25, -0.25, 0.25,
64
  -0.25, -0.25, 0,
65
  0.25, -0.25, 0.25,  // trianmpe1
66
  -0.25, -0.25, 0,
67
  0.25, -0.25, 0,
68
  // left
69
  -0.25, 0.25, 0.25,  // trianmpe0
70
  -0.25, 0.25, 0,
71
  -0.25, -0.25, 0,
72
  -0.25, 0.25, 0.25,  // trianmpe1
73
  -0.25, -0.25, 0,
74
  -0.25, -0.25, 0.25,
75
  // right
76
  0.25, 0.25, 0,  // trianmpe0
77
  0.25, 0.25, 0.25,
78
  0.25, -0.25, 0.25,
79
  0.25, 0.25, 0,  // trianmpe1
80
  0.25, -0.25, 0.25,
81
  0.25, -0.25, 0,
82
  // back
83
  -0.25, 0.25, 0,  // trianmpe0
84
  0.25, 0.25, 0,
85
  0.25, -0.25, 0,
86
  -0.25, 0.25, 0,  // trianmpe1
87
  0.25, -0.25, 0,
88
  -0.25, -0.25, 0
89
};
90
 
91
void mp_loop() {
92
  int i,m,k,l;
93
  int frame  = 0;
94 5 specular
  unsigned char uc;
95
  mpClearColor(0.0, 0.0, 0.1);
96 2 specular
  mpViewport(640, 480);
97
  mpMatrixMode(MP_PROJECTION);
98
  mpPerspective(30.0, 4.0 / 3.0, 1, 100);
99
  mpVertexPointer(triangle);
100
  while(1) {
101
    for (i = 0; i <360; i++) {
102
      printf("frame %d\n",frame++);
103
      mpClear();
104
      mpMatrixMode(MP_MODELVIEW);
105
      mpLoadIdentity();
106
      mpLookAt(0, 0, 1, 0, 0, 0, 0, 1, 0);
107 5 specular
      mpTranslate(-1.5,1.5,-8);
108
      uc = 0xff;
109 2 specular
      for (m = 0; m < 4; m++) {
110
        mpPushMatrix();
111
        for (k = 0; k < 4; k++) {
112
          mpPushMatrix();
113
          for (l = 0; l < 4; l++) {
114
            mpTranslate(1.0*l, 0,0);
115
            mpRotate((float)i, 0,0,1);
116
            mpRotate((float)i, 1,0,0);
117 5 specular
            mpRenderColorU (uc);
118
            uc -= 4;
119 2 specular
            mpDrawArrays(36);
120
            mpPopMatrix();
121
            mpPushMatrix();
122
          }
123
          mpPopMatrix();
124
          mpTranslate(0, -1,0);
125
        }
126
        mpPopMatrix();
127
        mpTranslate(0, 0, -1);
128
      }
129
      mpSwapBuffers();
130
    }
131
  }
132
}
133
 
134
int main()
135
{
136
 
137 4 specular
  printf("Cubes Demo\n");
138
  mpInit();
139 2 specular
  buffer_clear(0x00000000,0);
140
  buffer_clear(0x00000000,1);
141
  mp_loop();
142
  return 0;
143
}
144
 
145
 

powered by: WebSVN 2.1.0

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