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

Subversion Repositories wf3d

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

Go to most recent revision | 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 4 specular
//   Kenji Ishimaru (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
  mpClearColor(0.1, 0.1, 0.1);
95
  mpViewport(640, 480);
96
  mpMatrixMode(MP_PROJECTION);
97
  mpPerspective(30.0, 4.0 / 3.0, 1, 100);
98
  mpVertexPointer(triangle);
99
  while(1) {
100
    for (i = 0; i <360; i++) {
101
      printf("frame %d\n",frame++);
102
 
103
      mpClear();
104
      mpMatrixMode(MP_MODELVIEW);
105
      mpLoadIdentity();
106
      mpLookAt(0, 0, 1, 0, 0, 0, 0, 1, 0);
107
      mpTranslate(-2, 2,-10);
108
      for (m = 0; m < 4; m++) {
109
        mpPushMatrix();
110
        for (k = 0; k < 4; k++) {
111
          mpPushMatrix();
112
          for (l = 0; l < 4; l++) {
113
            mpTranslate(1.0*l, 0,0);
114
            mpRotate((float)i, 0,0,1);
115
            mpRotate((float)i, 1,0,0);
116
            mpDrawArrays(36);
117
            mpPopMatrix();
118
            mpPushMatrix();
119
          }
120
          mpPopMatrix();
121
          mpTranslate(0, -1,0);
122
        }
123
        mpPopMatrix();
124
        mpTranslate(0, 0, -1);
125
      }
126
      mpSwapBuffers();
127
    }
128
  }
129
}
130
 
131
int main()
132
{
133
 
134 4 specular
  printf("Cubes Demo\n");
135
  mpInit();
136 2 specular
  buffer_clear(0x00000000,0);
137
  buffer_clear(0x00000000,1);
138
  mp_loop();
139
  return 0;
140
}
141
 
142
 

powered by: WebSVN 2.1.0

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