1 package com.insanityengine.ghia.renderer;
2
3 import java.awt.*;
4 import java.awt.image.*;
5
6 import com.insanityengine.ghia.m3.*;
7 import com.insanityengine.ghia.pixels.*;
8 import com.insanityengine.ghia.libograf.*;
9
10 /***
11 *
12 * <P>
13 * Super cheap wireframe implementation of RendererInterface.
14 * </P>
15 *
16 * <table border="1">
17 * <topic>TestResults</topic>
18 * <TH>TestName</TH>
19 * <TH>Results</TH>
20 * <TH>SnapShot</TH>
21 * <TR valign="top">
22 * <TD>Light</TD>
23 * <TD>1593 fps</TD>
24 * <TD><img src="http://ghia.sourceforge.net/images/old_snaps/WireFuRender_Light.gif"/></TD>
25 * </TR>
26 * <TR valign="top">
27 * <TD>GeomLoader</TD>
28 * <TD>2370/60.817=38.969368 * 4725 = 184130 tps = 184 kts</TD>
29 * <TD><img src="http://ghia.sourceforge.net/images/old_snaps/WireFuRender_Geom.gif"/></TD>
30 * </TR>
31 * </TABLE>
32 *
33 * @author BrianHammond
34 *
35 * $Header: /usr/local/cvsroot/ghia/src/java/com/insanityengine/ghia/renderer/WireFuRenderer.java,v 1.8 2005/03/26 23:42:41 brian Exp $
36 *
37 */
38
39 public class WireFuRenderer implements RendererInterface, PixelBufferReadInterface {
40
41 /***
42 *
43 * Constructor
44 *
45 */
46 public WireFuRenderer() {
47 }
48
49 /***
50 *
51 * Constructor
52 *
53 * @param width of the display
54 * @param height of the display
55 * @param component to use to create offscreen buffer
56 *
57 */
58 public WireFuRenderer( int width, int height, Component component ) {
59 init( width, height, component );
60 }
61
62 /***
63 *
64 * Initialize this WireFuRenderer, call this *after* the component
65 * has been made visible or you will suffer!
66 *
67 * @param width of the display
68 * @param height of the display
69 * @param component to use to create offscreen buffer
70 *
71 */
72 public void init( int width, int height, Component component ) {
73 setObserver( component );
74
75 w = width;
76 h = height;
77 frustrum.setSize( w, h );
78
79 image = null;
80 this.component = component;
81 }
82
83 /***
84 *
85 * Render the next scene
86 *
87 * @param gl to use to render
88 *
89 */
90 public void render( LiboGraf gl ) {
91 if ( graphicsReady() ) {
92 invokeDrawers( gl );
93 gl.getGraphics().drawImage( image, 0, 0, observer );
94 }
95 }
96
97 /***
98 *
99 * Get the clear color
100 *
101 * @return the clear color
102 *
103 */
104 public int getClearColor() {
105 return 0;
106 }
107
108 /***
109 *
110 * Set the clear color
111 *
112 * @return color to clear with
113 *
114 */
115 public void setClearColor( int color ) {
116 }
117
118 /***
119 *
120 * Set depth testing policy
121 *
122 * @param testDepth false disables test
123 *
124 */
125 public void setDepthTesting( boolean testDepth ) { }
126
127 /***
128 *
129 * Clear the depth buffer
130 *
131 */
132 public void clearDepthBuffer() {
133 }
134
135 /***
136 *
137 * Clear the pixel/color buffer
138 *
139 */
140 public void clearColorBuffer() {
141 clear();
142 }
143
144 /***
145 *
146 * Set the shading method
147 *
148 * @param method may be listed in M3_Constants
149 *
150 */
151 public void setShadingMethod( int method ) {
152 }
153
154 /***
155 *
156 * Set the texture function
157 *
158 * @param function may be listed in M3_Constants
159 *
160 */
161 public void setTextureFunction( int function ) {
162 }
163
164 /***
165 *
166 * Draw a polygon
167 *
168 * @param count of points
169 * @param ptz the array of Pt3 to draw
170 *
171 */
172 public void drawPolygon( int count, Pt3[] ptz ) {
173 if ( graphicsReady() ) {
174
175 frustrum.toScreen( count, ptz );
176
177 Polygon poly = new Polygon();
178 graphics.setColor( Color.green );
179 for ( int i = 0 ; i < count ; ++i ) {
180 poly.addPoint( ( int ) ptz[ i ].x , ( int ) ptz[ i ].y );
181 }
182 graphics.drawPolygon( poly );
183 }
184 }
185
186 /***
187 *
188 * Set the current normal
189 *
190 * @param point to use as the current normal
191 *
192 */
193 public void setNormal( Pt3 point ) {
194 }
195
196 /***
197 *
198 * Set the current ImageSkin
199 *
200 * @param imageskin to use
201 *
202 */
203 public void setSkin( ImageSkin skin ) {
204 }
205
206
207
208
209 /***
210 *
211 * Clear the buffer
212 *
213 */
214 public void clear() {
215 if ( graphicsReady() ) {
216 graphics.setColor( Color.black );
217 graphics.fillRect( 0, 0, w, h );
218 }
219 }
220
221 /***
222 *
223 * Set the image observer
224 *
225 * @param observer to use
226 *
227 */
228 public void setObserver( java.awt.image.ImageObserver observer ) {
229 this.observer = observer;
230 }
231
232 /***
233 *
234 * Determines the width of the buffer.
235 *
236 * @return the width of this buffer
237 *
238 */
239 public int getWidth() {
240 return w;
241 }
242
243 /***
244 *
245 * Determines the height of the buffer.
246 *
247 * @return the height of this buffer
248 *
249 */
250 public int getHeight() {
251 return h;
252 }
253
254 /***
255 *
256 * Because this uses a PixelGrabber it may be slow-ish...
257 *
258 * @return array of pixel data
259 *
260 */
261 public int[] getPixels() {
262 ImageSkin skin = new ImageSkin( image, observer );
263 return skin.getPixels();
264 }
265
266
267
268
269 /***
270 *
271 * Some renderers are big babys about when it is ok to mess with their goodies.
272 * Hence this cheesy add/remove Drawer mess
273 *
274 * @param drawer to call per frame
275 *
276 */
277 public void addDrawer( DrawingInterface drawer ) {
278 registry.addDrawer( drawer );
279 }
280
281 /***
282 *
283 * Some renderers are big babys about when it is ok to mess with their goodies.
284 * Hence this cheesy add/remove Drawer mess
285 *
286 * @param drawer to call per frame
287 *
288 */
289 public void removeDrawer( DrawingInterface drawer ) {
290 registry.removeDrawer( drawer );
291 }
292
293 /***
294 *
295 * Invoke any registered DrawingInterfaces
296 *
297 */
298 public void invokeDrawers( LiboGraf gl ) {
299 registry.invokeDrawers( gl );
300 }
301
302
303
304 private int w, h;
305 private Image image = null;
306 private Graphics graphics = null;
307 private ImageObserver observer = null;
308 private Component component = null;
309 private DrawerRegistry registry = new DrawerRegistry();
310 private Frustrum frustrum = new Frustrum();
311
312
313
314 private final boolean graphicsReady() {
315 boolean ok = false;
316 if ( null == graphics ) {
317 image = component.createImage( w, h );
318 if ( null == image ) {
319 } else {
320 ok = true;
321 graphics = image.getGraphics();
322 }
323 System.out.println( "" + " image = " + image + " graphics = " + graphics );
324 } else {
325 ok = true;
326 }
327 return ok;
328 }
329
330 };
331
332 /***
333 *
334 * $Log: WireFuRenderer.java,v $
335 * Revision 1.8 2005/03/26 23:42:41 brian
336 * fix links
337 *
338 * Revision 1.7 2005/03/19 17:50:02 brian
339 * repackaging
340 *
341 * Revision 1.6 2004/09/16 11:00:20 brian
342 * added expensive getPixels impl... but how to mark it as such programmaticly?
343 *
344 * Revision 1.5 2004/09/13 03:06:41 brian
345 * fix up Frustrum.toScreen, still working on JoglRenderer's texture support... sigh...
346 *
347 * Revision 1.4 2004/09/05 03:41:31 brian
348 * refactored to have the render method of the renderers invoke the drawingIfz
349 *
350 * Revision 1.3 2004/09/03 03:38:13 brian
351 * fixed typo
352 *
353 * Revision 1.2 2004/09/03 02:42:12 brian
354 * remove cruft
355 *
356 * Revision 1.1 2004/09/02 13:17:16 brian
357 * the big reorg
358 *
359 * Revision 1.6 2004/09/01 02:18:57 brian
360 * javadoc
361 *
362 * Revision 1.5 2004/09/01 01:52:47 brian
363 * added test results (ok, and images) to javadoc
364 *
365 * Revision 1.4 2004/09/01 01:10:42 brian
366 * fix class level javadoc placement
367 *
368 * Revision 1.3 2004/09/01 00:11:06 brian
369 * author, log and header stuff
370 *
371 *
372 */