@@ -1,7 +1,7 @@
package com.skardach.ro.resource;

import java.nio.Buffer;
import javax.media.opengl.GL2;
import com.jogamp.opengl.GL2;

/**
* Interface for accessing texture data.
@@ -7,8 +7,8 @@
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;

import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL2;

import com.jogamp.opengl.util.texture.TextureData;
import com.jogamp.opengl.util.texture.TextureIO;
@@ -24,7 +24,7 @@ public class TextureImpl implements Texture {
TextureData _data;
com.jogamp.opengl.util.texture.Texture _joglTexture;
Integer _GLName = null;
private boolean _convertMagenta;
private boolean _convertMagenta=false;
/**
* Construct the texture with given relative path (name) and base path
* @param iName Name of the texture, being the relative path to the
@@ -40,8 +40,9 @@ public class TextureImpl implements Texture {
public TextureImpl(
String iName,
String iBasePath,
boolean iConvertMagenta) {
_name = iName;
boolean iConvertMagenta) {// int271
//iTextureName=iTextureName.replaceAll("\0", "").replaceAll("ÿ", "").replaceAll(".bmp", "");
_name = iName.replaceAll("\0", "").replaceAll("ÿ", "").replaceAll(".bmp", "");
_path = iBasePath;
_convertMagenta = iConvertMagenta;
}
@@ -92,6 +93,9 @@ public synchronized void load(GL2 iGLContext) throws ResourceException {
try {
// Read the image
File textureFile = new File(_path, _name);
if(!textureFile.exists()) {
textureFile = new File("%userprofile%\\Pictures\\pentalogo1.png");
}
_data = TextureIO.newTextureData(
iGLContext.getGLProfile(),
textureFile,
@@ -101,7 +105,7 @@ public synchronized void load(GL2 iGLContext) throws ResourceException {
throw new ResourceException(
"Could not read texture " + _name);
if(_convertMagenta)
convertMagentaToAlphaIfNeeded();
;//convertMagentaToAlphaIfNeeded(); int271
// create the texture
_joglTexture = TextureIO.newTexture(_data);
// set some parameters
@@ -116,11 +120,14 @@ public synchronized void load(GL2 iGLContext) throws ResourceException {
_joglTexture.setTexParameterf(
iGLContext,
GL.GL_TEXTURE_MAG_FILTER,
GL.GL_NEAREST);
GL.GL_LINEAR);
//_joglTexture.setTexParameterf(iGLContext, GL.GL_BLEND,1.f);
iGLContext.glTexEnvf(
GL2.GL_TEXTURE_ENV,
GL2.GL_TEXTURE_ENV_MODE,
GL2.GL_MODULATE);

iGLContext.glColor3f(0, 1, 1);
} catch (IOException e) {
throw new ResourceException(
"Error loading texture from file: "
@@ -55,7 +55,7 @@ public enum AnimationType {
* aniframe = value - lasttex * n;</pre>
*/
TYPE_5;

static AnimationType fromInt(int iMode)
{
switch(iMode) {
@@ -70,4 +70,19 @@ static AnimationType fromInt(int iMode)
return UNKNOWN;
}
}
}


@Override
public String toString()
{
switch(this) {
case NO_CHANGE: return "Static";
case TYPE_1: return "??TYPE_1";
case TYPE_2: return "Play Once";
case TYPE_3: return "Loop";
case TYPE_4: return "??Play backwards?";
case TYPE_5: return "Loop back and forth";
default: return "?(see Log)";
}
}
}
@@ -228,21 +228,21 @@ public String toString() {
*/
public String toString(String iPrefix) {
return
iPrefix + "<keyFrame "
+ " _framenum=\"" + _framenum + "\""
+ " _frameType=\"" + _frameType + "\""
+ " _position=\"" + _position + "\""
+ " _textureUVMapping=\"" + _textureUVMapping + "\""
+ " _textureUVMapping2=\"" + _textureUVMapping2 + "\""
+ " _drawingRectangle=\"" + _drawingRectangle + "\""
+ " _textureId=\"" + _textureId + "\""
+ " _animationType=\"" + _animationType + "\""
+ " _animationDelta=\"" + _animationDelta + "\""
+ " _rotation=\"" + _rotation + "\""
+ " _color=\"" + _color + "\""
+ " _sourceBlend=\"" + _sourceBlend + "\""
+ " _destBlend=\"" + _destBlend + "\""
+ " _multiTexturePreset=\"" + _multiTexturePreset + "\""
iPrefix + (_frameType== _frameType.BASIC ? "<keyFrame ":"<morphFr. ")
//+ " Type=\"" + _frameType + "\""
+ " Fr#=\"" + _framenum + "\""
+ " tex#=\"" + _textureId + "\""
+ (_animationType!= _animationType.NO_CHANGE ?
(" aniType=\"" + _animationType + "\" aniDelta=\"" + _animationDelta + "\"" ):"")
+ " pos=\"" + _position + "\""
+ " texUV=\"" + _textureUVMapping.get_a() + _textureUVMapping.get_d() + "\""
+ " texUV2=\"" + _textureUVMapping2.get_a() + _textureUVMapping2.get_d() + "\""
+ " Rectangle=\"" + _drawingRectangle.get_a() + _drawingRectangle.get_d() + "\""
+ " rotation=\"" + _rotation + "\""
+ " color=\"" + _color + "\""
+ " sourceBlend=\"" + _sourceBlend + "\""
+ " destBlend=\"" + _destBlend + "\""
+ (_multiTexturePreset!= _multiTexturePreset.NO_CHANGE ? (" multiTexturePreset=" + _multiTexturePreset ):"")
+ " />";
}

@@ -24,9 +24,9 @@ public enum KeyFrameType {
*/
public static KeyFrameType fromInt(int iType)
{
if(iType == 1)
if( ( iType % 2) == 1 ) //int271
return MORPH;
else
else
return BASIC;
}
}
@@ -50,18 +50,21 @@ public String toString() {
* @return String representation
*/
public String toString(String iPrefix) {
String result = iPrefix + "<layer>\n"
+ iPrefix + " <_textures>\n";
for(Texture t : _textures)
result += t.toString(iPrefix + " ") + "\n";

result += iPrefix + " </_textures>\n"
+ iPrefix + " <_keyFrames>\n";
for(KeyFrame kf : _keyFrames)
result += kf.toString(iPrefix + " ") + "\n";

result += iPrefix + " </_keyFrames>\n";
result += iPrefix + "</layer>";
String result=iPrefix + "<Empty Layer/>";
if (_keyFrames.size()!=0) {
result = iPrefix + "<layer>\n"
+ iPrefix + " <_textures>\n";
for(Texture t : _textures)
result += t.toString(iPrefix + " ") + "\n";

result += iPrefix + " </_textures>\n"
+ iPrefix + " <_Frames>\n";
for(KeyFrame kf : _keyFrames)
result += kf.toString(iPrefix + " ") + "\n";

result += iPrefix + " </_Frames>\n";
result += iPrefix + "</layer>";
}
return result;
}
}
@@ -85,8 +85,8 @@ public Str readFromStream(ResourceManager iResourceManager, InputStream iStream)
if(result.get_fps() <= 0)
result.set_fps(DEFAULT_FPS);
result.set_frameCount(stream.readInt());
if(result.get_frameCount() < 0)
throw new ParseException("Framecount less than 0");
if(result.get_frameCount() < 1) result.set_frameCount(1);
//throw new ParseException("Framecount less than 0");
// read layers
int layerCount = stream.readInt();
if(layerCount < 0)
@@ -124,6 +124,10 @@ private Layer readLayer(TextureManager textureManager,
{
layer.get_textures().add(readTexture(textureManager, stream));
}
if (textureCount == 0) {
layer.get_textures().add(genericTexture(textureManager));
}

int keyFrameCount = stream.readInt();
if(keyFrameCount > Layer.MAX_KEYFRAME_COUNT)
throw new ParseException("Too many key frames: " + keyFrameCount);
@@ -146,6 +150,22 @@ private Texture readTexture(TextureManager textureManager,
stream.read(textureNameBuffer);
String textureName = // this should use UTF8
new String(textureNameBuffer, 0, TEXTURE_NAME_SIZE).trim();

Texture texture =
textureManager.getTexture(textureName);
if(texture == null) // if no such texture found
throw new ResourceException(
String.format(
"Texture [%s] could not be located",
textureName));
return texture;
}

private Texture genericTexture(TextureManager textureManager) throws IOException, ResourceException {

String textureName = // this should use UTF8
new String("C:\\Users\\int\\Pictures\\miro.jpg").trim();

Texture texture =
textureManager.getTexture(textureName);
if(texture == null) // if no such texture found
@@ -169,19 +189,20 @@ private KeyFrame readKeyFrame(LittleEndianInputStreamAdapter stream) throws IOEx
float y = stream.readFloat();
keyFrame.set_position(new Point2D(x, y));
float u = stream.readFloat();
float v = stream.readFloat();
float us = stream.readFloat();
float vs = stream.readFloat();
float v = -stream.readFloat(); //imgs were flipped vert. int271
float us = stream.readFloat(); //"u size"
float vs = -stream.readFloat();
keyFrame.set_textureUVMapping(
new Rectangle<Point2D>(
new Point2D(u, v),
new Point2D(us,v),
new Point2D(u,vs),
new Point2D(us,vs)));
new Point2D((u+us),v),
new Point2D(u,(v+vs)),
new Point2D((u+us),(v+vs))));

u = stream.readFloat();
v = stream.readFloat();
v = -stream.readFloat();
us = stream.readFloat();
vs = stream.readFloat();
vs = -stream.readFloat();
keyFrame.set_textureUVMapping2(
new Rectangle<Point2D>(
new Point2D(u, v),
@@ -208,7 +229,7 @@ private KeyFrame readKeyFrame(LittleEndianInputStreamAdapter stream) throws IOEx
keyFrame.set_textureId(stream.readFloat());
keyFrame.set_animationType(AnimationType.fromInt(stream.readInt()));
keyFrame.set_animationDelta(stream.readFloat());
keyFrame.set_rotation(stream.readFloat());
keyFrame.set_rotation(stream.readFloat());
// Read color
float r = stream.readFloat();
float g = stream.readFloat();
@@ -1,6 +1,7 @@
package com.skardach.ro.tools;

import java.awt.Button;
import java.awt.Dimension;
import java.awt.FileDialog;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
@@ -14,7 +15,7 @@
import java.io.InputStream;


import javax.media.opengl.awt.GLCanvas;
import com.jogamp.opengl.awt.GLCanvas;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
@@ -39,6 +40,14 @@
* @author Stanislaw Kardach
*
*/

/*
* public static void main(String[] args) { java.awt.EventQueue.invokeLater(new
* Runnable() { public void run() { FrameWithBorderLayout frame = new
* FrameWithBorderLayout(); frame.setVisible(true); } }); }
*/


public class STRViewer extends JFrame {
private static final long serialVersionUID = -9077621002191789823L;
/**
@@ -83,7 +92,7 @@ private void run() {
*/
public STRViewer() {
setTitle(Settings.WINDOW_TITLE);
getContentPane().setLayout(new GridLayout(2, 1));
getContentPane().setLayout(new GridLayout(1, 2));
_glWrapper = OpenGLWrapper.createDesktopWrapper(Settings.FPS);
// OpenGL canvas
_canvas = _glWrapper.createGLCanvasWithAnimator();
@@ -92,11 +101,13 @@ public STRViewer() {
_infoArea = new JTextArea();
_infoArea.setDoubleBuffered(true);
_infoArea.setEditable(false);
_infoArea.setSize(40, 100);
JScrollPane scrollPane = new JScrollPane(_infoArea);
scrollPane.setDoubleBuffered(true);
JPanel panel = new JPanel(true);
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
panel.add(scrollPane);
panel.setSize(28,28);
// vertical stack panel for start/stop, pause/resume buttons
JPanel buttonPanel = new JPanel(true);
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS));
@@ -157,14 +168,14 @@ public void actionPerformed(ActionEvent e) {

addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
public void windowClosing( WindowEvent e ) {
stop();
// FIXME: I'm making a shortcut here... proper cleaning needed
System.exit(0);
}
});
pack();
setSize(800, 600);
setSize(1300, 600);
}

private void start() {