1 | /****************************************************************************** |
---|
2 | * SAGE - Scalable Adaptive Graphics Environment |
---|
3 | * Copyright (C) 2004 Electronic Visualization Laboratory, |
---|
4 | * University of Illinois at Chicago |
---|
5 | * |
---|
6 | * All rights reserved. |
---|
7 | * |
---|
8 | * Redistribution and use in source and binary forms, with or without |
---|
9 | * modification, are permitted provided that the following conditions are met: |
---|
10 | * |
---|
11 | * * Redistributions of source code must retain the above copyright |
---|
12 | * notice, this list of conditions and the following disclaimer. |
---|
13 | * * Redistributions in binary form must reproduce the above |
---|
14 | * copyright notice, this list of conditions and the following disclaimer |
---|
15 | * in the documentation and/or other materials provided with the distribution. |
---|
16 | * * Neither the name of the University of Illinois at Chicago nor |
---|
17 | * the names of its contributors may be used to endorse or promote |
---|
18 | * products derived from this software without specific prior written permission. |
---|
19 | * |
---|
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
---|
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
31 | * |
---|
32 | * Direct questions, comments etc about SAGE to sage_users@listserv.uic.edu |
---|
33 | *****************************************************************************/ |
---|
34 | |
---|
35 | |
---|
36 | //A simple test program that pushes pixels to SAGE frame buffer |
---|
37 | //written by Byung-il Jeong |
---|
38 | //Feb 2005 |
---|
39 | |
---|
40 | #include <stdio.h> |
---|
41 | #include <math.h> |
---|
42 | #include <stdlib.h> |
---|
43 | |
---|
44 | // headers for SAGE |
---|
45 | #include "sail.h" |
---|
46 | #include "misc.h" |
---|
47 | |
---|
48 | int main(int argc, char *argv[]) |
---|
49 | { |
---|
50 | double t1, t2, fps; |
---|
51 | sail sageInf; // sail object |
---|
52 | int nodeID; |
---|
53 | |
---|
54 | if (argc < 2) |
---|
55 | nodeID = 0; |
---|
56 | else |
---|
57 | nodeID = atoi(argv[1]); |
---|
58 | |
---|
59 | int resX = 400, resY = 400; |
---|
60 | if (argc >= 4) { |
---|
61 | resX = atoi(argv[2]); |
---|
62 | resY = atoi(argv[3]); |
---|
63 | } |
---|
64 | double rate = 10.0; |
---|
65 | if (argc >= 5) { |
---|
66 | rate = atof(argv[4]); |
---|
67 | } |
---|
68 | |
---|
69 | std::cout << std::endl << "ResX = " << resX << " ResY = " << resY << std::endl; |
---|
70 | |
---|
71 | sailConfig scfg; |
---|
72 | scfg.init("checker.conf"); |
---|
73 | scfg.setAppName("checker"); |
---|
74 | scfg.rank = nodeID; |
---|
75 | |
---|
76 | scfg.resX = resX; |
---|
77 | scfg.resY = resY; |
---|
78 | |
---|
79 | sageRect renderImageMap; |
---|
80 | renderImageMap.left = 0.0; |
---|
81 | renderImageMap.right = 1.0; |
---|
82 | renderImageMap.bottom = 0.0; |
---|
83 | renderImageMap.top = 1.0; |
---|
84 | |
---|
85 | scfg.imageMap = renderImageMap; |
---|
86 | scfg.pixFmt = PIXFMT_888; |
---|
87 | scfg.rowOrd = BOTTOM_TO_TOP; |
---|
88 | scfg.master = true; |
---|
89 | scfg.nwID = 1; |
---|
90 | scfg.frameRate = rate; |
---|
91 | |
---|
92 | sageInf.init(scfg); |
---|
93 | std::cout << "sail initialized " << std::endl; |
---|
94 | |
---|
95 | void *buffer = sageInf.getBuffer(); |
---|
96 | unsigned char color = 200; |
---|
97 | |
---|
98 | while(1) { |
---|
99 | t1 = sage::getTime(); |
---|
100 | memset(buffer, color, resX*resY*3); |
---|
101 | sageInf.swapBuffer(); |
---|
102 | buffer = sageInf.getBuffer(); |
---|
103 | color = (color + 1) % 129; |
---|
104 | sageMessage msg; |
---|
105 | if (sageInf.checkMsg(msg, false) > 0) { |
---|
106 | switch (msg.getCode()) { |
---|
107 | case APP_QUIT : { |
---|
108 | sageInf.shutdown(); |
---|
109 | exit(0); |
---|
110 | break; |
---|
111 | } |
---|
112 | } |
---|
113 | } |
---|
114 | t2 = sage::getTime(); |
---|
115 | fps = (1000000.0/(t2-t1)); |
---|
116 | if (fps > rate) { |
---|
117 | sage::usleep( (1000000.0/rate) - (t2-t1) ); |
---|
118 | } |
---|
119 | } |
---|
120 | |
---|
121 | return 0; |
---|
122 | } |
---|