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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [demo_app/] [simple_cube.c] - Blame information for rev 2

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
//   simple_cube.c
7
//
8
// Abstract:
9
//   simple rendering sample
10
//
11
// Author:
12
//   Kenji Ishimaru (kenji.ishimaru@prtissimo.com)
13
//
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
#include <stdio.h>
43
#include <unistd.h>
44
#include <system.h>
45
#include "mp_lib.h"
46
#include "mp_hwdep.h"
47
 
48
float triangle[] = {
49
  // front
50
  0.25,  0.25, 0.25,  // triangle0
51
  -0.25,  0.25, 0.25,
52
  -0.25, -0.25, 0.25,
53
   0.25,  0.25, 0.25,  // triangle1
54
  -0.25, -0.25, 0.25,
55
   0.25, -0.25, 0.25,
56
  // top
57
   0.25,  0.25, 0.0,      // triangle0
58
  -0.25,  0.25, 0.0,
59
  -0.25,  0.25, 0.25,
60
   0.25,  0.25, 0.0,      // triangle1
61
  -0.25,  0.25, 0.25,
62
   0.25,  0.25, 0.25,
63
  // bottom
64
   0.25, -0.25, 0.25,  // triangle0
65
  -0.25, -0.25, 0.25,
66
  -0.25, -0.25, 0,
67
  0.25, -0.25, 0.25,  // triangle1
68
  -0.25, -0.25, 0,
69
  0.25, -0.25, 0,
70
  // left
71
  -0.25, 0.25, 0.25,  // triangle0
72
  -0.25, 0.25, 0,
73
  -0.25, -0.25, 0,
74
  -0.25, 0.25, 0.25,  // triangle1
75
  -0.25, -0.25, 0,
76
  -0.25, -0.25, 0.25,
77
  // right
78
  0.25, 0.25, 0,  // triangle0
79
  0.25, 0.25, 0.25,
80
  0.25, -0.25, 0.25,
81
  0.25, 0.25, 0,  // triangle1
82
  0.25, -0.25, 0.25,
83
  0.25, -0.25, 0,
84
  // back
85
  -0.25, 0.25, 0,  // triangle0
86
  0.25, 0.25, 0,
87
  0.25, -0.25, 0,
88
  -0.25, 0.25, 0,  // triangle1
89
  0.25, -0.25, 0,
90
  -0.25, -0.25, 0
91
};
92
 
93
void mp_loop() {
94
  int i;
95
  int frame  = 0;
96
  mpClearColor(0.1, 0.1, 0.1);
97
  mpViewport(640, 480);
98
  mpMatrixMode(MP_PROJECTION);
99
  mpPerspective(30.0, 4.0 / 3.0, 1, 100);
100
  mpVertexPointer(triangle);
101
  while(1) {
102
    for (i = 0; i <360; i++) {
103
      printf("frame %d\n",frame++);
104
 
105
      mpClear();
106
      mpMatrixMode(MP_MODELVIEW);
107
      mpLoadIdentity();
108
      mpLookAt(0, 0, 1, 0, 0, 0, 0, 1, 0);
109
      mpTranslate(0, 0, -2);
110
      mpRotate(i, 1, 0, 0);
111
      mpRotate(i, 0, 0, 1);
112
 
113
      mpDrawArrays(36);//12 triangles
114
      mpSwapBuffers();
115
    }
116
  }
117
}
118
 
119
int main()
120
{
121
 
122
  printf("Hello from Nios II!\n");
123
  buffer_clear(0x00000000,0);
124
  buffer_clear(0x00000000,1);
125
  mpInit();
126
  mp_loop();
127
  return 0;
128
}

powered by: WebSVN 2.1.0

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