aboutsummaryrefslogtreecommitdiffstats
path: root/demos/MiscDemos/gearsOffScreen2Tga.java
blob: 21ed42f32b903d3ba55d3e4c121bfaf6a39ff5d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
 * @(#) gearsOffScreen2Tga.java
 * @(#) author: Brian Paul (converted to Java by Ron Cemer and Sven Goethel)
 *
 * This version is equal to Brian Paul's version 1.2 1999/10/21
 */

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import java.util.*;
import java.io.*;
import gl4java.*;
import gl4java.drawable.*;
import gl4java.awt.*;
import gl4java.utils.textures.*;

public class gearsOffScreen2Tga 
{
	GLOffScreenDrawable canvas;

	public void snapshot()
	{
		canvas = new GLOffScreenDrawable(new Dimension(400,400));

		gearRenderer gear = new gearRenderer(true);
		canvas.addGLEventListener(gear);

		canvas.initDrawable();

		if(canvas.cvsIsInit())
		{
			canvas.repaint();
			GLContext glj = canvas.getGLContext();

			if( glj.gljMakeCurrent() )
			{
				TGATextureGrabber textgrab = 
					new TGATextureGrabber(canvas.getGL());
				textgrab.grabPixels(
				    glj.isDoubleBuffer()?GLEnum.GL_BACK:GLEnum.GL_FRONT,
				    0, 0, 
				    canvas.getSize().width, 
				    canvas.getSize().height);
				textgrab.write2File("gears.tga");
				System.out.println("written gears.tga");
				glj.gljCheckGL();
				glj.gljFree();
			}
		}
	}

	public static void main( String args[] ) 
	{
		int i = 0;
		String gljLib = null;
		String glLib = null;
		String gluLib = null;

	        GLContext.gljNativeDebug = false;
	        GLContext.gljClassDebug = false;
	        GLContext.gljThreadDebug = false;

		while(args.length>i)
		{
			if(args[i].equals("-gljLib"))
			{
				i++;
				if(args.length>i)
					gljLib=args[i];
			} else if(args[i].equals("-glLib"))
			{
				i++;
				if(args.length>i)
					glLib=args[i];
			} else if(args[i].equals("-gluLib"))
			{
				i++;
				if(args.length>i)
					gluLib=args[i];
			} else {
			  System.out.println("illegal arg "+i+": "+args[i]);
			}
			i++;
		}

		GLContext.doLoadNativeLibraries(gljLib, glLib, gluLib);

		/**
		 * yes .. we need an AWT Frame,
		 * to let java get in touch with the underlying 
		 * windowing system for initialisation !
		 */
		Frame mainFrame = new Frame("gears offscreen");

		Dimension ps = new Dimension(20,20);
		mainFrame.setBounds(-100,-100,99,99);
		mainFrame.setVisible(true);
		mainFrame.setVisible(false);
		mainFrame.setVisible(true);
		Insets is = mainFrame.getInsets();
		mainFrame.setBounds(0,0,
			    ps.width+is.left+is.right, 
		            ps.height+is.top+is.bottom);
		mainFrame.setVisible(true);

		gearsOffScreen2Tga applet = new gearsOffScreen2Tga();
		applet.snapshot();

		mainFrame.dispose();
		System.exit(0);
	}
}