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
115
116
117
118
119
120
121
122
123
124
125
126
|
import gl4java.*;
import gl4java.awt.*;
import gl4java.utils.textures.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
public class GLImageViewerCanvas extends Frame
implements ActionListener, ItemListener
{
GLImageCanvas glImageCanvas = null;
private Choice fileTypeChoice = null;
private Button loadButton = null;
private Button saveButton = null;
private Button normalButton = null;
private Checkbox aspectCheck = null;
public GLImageViewerCanvas(String title)
{
super(title);
setSize(500, 300);
Dimension d = getSize();
setLayout(new BorderLayout());
addWindowListener( new WindowAdapter()
{
public void windowClosed(WindowEvent e)
{
System.exit(0);
}
public void windowClosing(WindowEvent e)
{
windowClosed(e);
}
}
);
Panel filePanel = new Panel();
filePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
fileTypeChoice = new Choice();
fileTypeChoice.add("any");
fileTypeChoice.add("tga");
fileTypeChoice.add("png");
fileTypeChoice.add("ppm");
filePanel.add(fileTypeChoice);
loadButton = new Button("load..");
loadButton.addActionListener(this);
filePanel.add(loadButton);
saveButton = new Button("save..");
saveButton.addActionListener(this);
filePanel.add(saveButton);
normalButton = new Button("normal");
normalButton.addActionListener(this);
filePanel.add(normalButton);
aspectCheck = new Checkbox("aspect", true);
aspectCheck.addItemListener(this);
filePanel.add(aspectCheck);
add("North", filePanel);
glImageCanvas = new GLImageCanvas(d.width, d.height);
glImageCanvas.setName("GLImageCanvas");
glImageCanvas.setKeepAspectRatio(aspectCheck.getState());
add("Center", glImageCanvas);
pack();
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
Object src = e.getSource();
if(src.equals(loadButton))
{
FileDialog fd = new FileDialog(this,"Bitmap Load Menu",
FileDialog.LOAD);
fd.show();
String fname = fd.getDirectory() + fd.getFile() ;
fname = fname.replace('\\','/');
fname = fname.trim();
setTitle(fname);
glImageCanvas.loadTexture(fname,
fileTypeChoice.getSelectedItem() );
repaint();
} else if(src.equals(saveButton))
{
FileDialog fd = new FileDialog(this,"TGA-Image Save Menu",
FileDialog.SAVE);
fd.show();
String fname = fd.getDirectory() + fd.getFile() ;
fname = fname.replace('\\','/');
fname = fname.trim();
setTitle(fname);
glImageCanvas.snapshot( new TGATextureGrabber(glImageCanvas.gl),
fname);
repaint();
} else if(src.equals(normalButton))
{
glImageCanvas.setOriginalSize();
}
}
public void itemStateChanged(ItemEvent e)
{
if(aspectCheck.equals(e.getItemSelectable()))
{
glImageCanvas.setKeepAspectRatio(aspectCheck.getState());
}
}
public static void main( String args[] )
{
GLContext.gljNativeDebug = true;
GLContext.gljClassDebug = true;
GLImageViewerCanvas applet =
new GLImageViewerCanvas("GLImageViewerCanvas");
}
}
|