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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [demo_app/] [simple_cube.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
//   simple_cube.c
7
//
8
// Abstract:
9
//   simple rendering sample
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,  // triangle0
49
  -0.25,  0.25, 0.25,
50
  -0.25, -0.25, 0.25,
51
   0.25,  0.25, 0.25,  // triangle1
52
  -0.25, -0.25, 0.25,
53
   0.25, -0.25, 0.25,
54
  // top
55
   0.25,  0.25, 0.0,      // triangle0
56
  -0.25,  0.25, 0.0,
57
  -0.25,  0.25, 0.25,
58
   0.25,  0.25, 0.0,      // triangle1
59
  -0.25,  0.25, 0.25,
60
   0.25,  0.25, 0.25,
61
  // bottom
62
   0.25, -0.25, 0.25,  // triangle0
63
  -0.25, -0.25, 0.25,
64
  -0.25, -0.25, 0,
65
  0.25, -0.25, 0.25,  // triangle1
66
  -0.25, -0.25, 0,
67
  0.25, -0.25, 0,
68
  // left
69
  -0.25, 0.25, 0.25,  // triangle0
70
  -0.25, 0.25, 0,
71
  -0.25, -0.25, 0,
72
  -0.25, 0.25, 0.25,  // triangle1
73
  -0.25, -0.25, 0,
74
  -0.25, -0.25, 0.25,
75
  // right
76
  0.25, 0.25, 0,  // triangle0
77
  0.25, 0.25, 0.25,
78
  0.25, -0.25, 0.25,
79
  0.25, 0.25, 0,  // triangle1
80
  0.25, -0.25, 0.25,
81
  0.25, -0.25, 0,
82
  // back
83
  -0.25, 0.25, 0,  // triangle0
84
  0.25, 0.25, 0,
85
  0.25, -0.25, 0,
86
  -0.25, 0.25, 0,  // triangle1
87
  0.25, -0.25, 0,
88
  -0.25, -0.25, 0
89
};
90
 
91
void mp_loop() {
92
  int i;
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 4 specular
      //printf("frame %d\n",frame++);
102 2 specular
 
103
      mpClear();
104
      mpMatrixMode(MP_MODELVIEW);
105
      mpLoadIdentity();
106
      mpLookAt(0, 0, 1, 0, 0, 0, 0, 1, 0);
107
      mpTranslate(0, 0, -2);
108
      mpRotate(i, 1, 0, 0);
109
      mpRotate(i, 0, 0, 1);
110 4 specular
      mpDrawArrays(36);//12 triangles
111
      //printf("drawarray done.\n");
112 2 specular
 
113
      mpSwapBuffers();
114
    }
115
  }
116
}
117
 
118
int main()
119
{
120
 
121 4 specular
  printf("Simple Cube\n");
122
  mpInit();
123 2 specular
  buffer_clear(0x00000000,0);
124
  buffer_clear(0x00000000,1);
125
  mp_loop();
126
  return 0;
127
}

powered by: WebSVN 2.1.0

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