Jirr & E_MATERIAL_TYPE

Discussion about Irrlicht's Java wrapper
Post Reply
Serg Nechaeff
Posts: 162
Joined: Wed Nov 26, 2003 5:24 pm
Location: Europe

Jirr & E_MATERIAL_TYPE

Post by Serg Nechaeff »

Hi everyone,
I am playing with the JIRR thing at the moment and everything works fine, Jirr is grear, Irr is great but there is no shaders example in the Jirr distribution package. I tried to convert it myself and I am stuck on the following line:

Code: Select all

node.setMaterialType((E_MATERIAL_TYPE)newMaterialType1);
Java doesn't perform such a cast, I tried to do the

Code: Select all

node.setMaterialType(E_MATERIAL_TYPE.swigToEnum(newMaterialType1));
that gave me the exception: No enum class net.sf.jirr.E_MATERIAL_TYPE with value 23

If anyone knows how to solve this or has had luck with shaders code for Jirr, your help would be highly appreciated. Thanks!
http://www.javazing.com
P-III-950, WinXP, GeForce FX5600 128 MB ForceWare 52.16, DX9, Eclipse IDE, JRE 1.6
Browndog
Posts: 74
Joined: Thu Aug 18, 2005 2:53 am

Post by Browndog »

try

E_MATERIAL_TYPE.EMT_TRANSPARENT_ADD_COLOR
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

I think maybe Jirr just doesn't work for some things, things that Stefan hasn't got round to fixing up quite yet, and this may be one of them. I think i ran into something similar myself a while ago. Have you asked on the Jirr forum?
Image Image Image
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

But there must be a way to change the material type!
Serg Nechaeff
Posts: 162
Joined: Wed Nov 26, 2003 5:24 pm
Location: Europe

solved ^)

Post by Serg Nechaeff »

Thanks everyone. However I have decompiled the Shaders example code that for some reason is not in the Jirr source package. Here you go:

Code: Select all

/*jode*/
/* TestShaders - Decompiled by JODE
 * Visit http://jode.sourceforge.net/
 */
import java.io.IOException;

import net.sf.jirr.E_DRIVER_TYPE;
import net.sf.jirr.E_MATERIAL_TYPE;
import net.sf.jirr.E_PIXEL_SHADER_TYPE;
import net.sf.jirr.E_TEXTURE_CREATION_FLAG;
import net.sf.jirr.E_TRANSFORMATION_STATE;
import net.sf.jirr.E_VERTEX_SHADER_TYPE;
import net.sf.jirr.E_VIDEO_DRIVER_FEATURE;
import net.sf.jirr.ICameraSceneNode;
import net.sf.jirr.IGPUProgrammingServices;
import net.sf.jirr.IGUIEnvironment;
import net.sf.jirr.IMaterialRendererServices;
import net.sf.jirr.ISceneManager;
import net.sf.jirr.ISceneNode;
import net.sf.jirr.ISceneNodeAnimator;
import net.sf.jirr.IShaderConstantSetCallBack;
import net.sf.jirr.IVideoDriver;
import net.sf.jirr.IrrlichtDevice;
import net.sf.jirr.Jirr;
import net.sf.jirr.SColor;
import net.sf.jirr.SColorf;
import net.sf.jirr.matrix4;
import net.sf.jirr.vector3df;

public class TestShaders
{
    static IrrlichtDevice device;
    static boolean UseHighLevelShaders;
    
    static class MyShaderCallBack extends IShaderConstantSetCallBack
    {
	public void OnSetConstants
	    (IMaterialRendererServices imaterialrendererservices, int i) {
	    IVideoDriver ivideodriver
		= imaterialrendererservices.getVideoDriver();
	    matrix4 var_matrix4
		= ivideodriver.getTransform(E_TRANSFORMATION_STATE.ETS_WORLD);
	    var_matrix4.makeInverse();
	    if (TestShaders.UseHighLevelShaders)
		imaterialrendererservices.setVertexShaderConstant("mInvWorld",
								  var_matrix4
								      .getM(),
								  16);
	    else
		imaterialrendererservices
		    .setVertexShaderConstant(var_matrix4.getM(), 0, 4);
	    matrix4 var_matrix4_0_
		= ivideodriver
		      .getTransform(E_TRANSFORMATION_STATE.ETS_PROJECTION);
	    var_matrix4_0_
		= var_matrix4_0_.multiply(ivideodriver.getTransform
					  (E_TRANSFORMATION_STATE.ETS_VIEW));
	    var_matrix4_0_
		= var_matrix4_0_.multiply(ivideodriver.getTransform
					  (E_TRANSFORMATION_STATE.ETS_WORLD));
	    if (TestShaders.UseHighLevelShaders)
		imaterialrendererservices.setVertexShaderConstant
		    ("mWorldViewProj", var_matrix4_0_.getM(), 16);
	    else
		imaterialrendererservices
		    .setVertexShaderConstant(var_matrix4_0_.getM(), 4, 4);
	    vector3df var_vector3df
		= TestShaders.device.getSceneManager().getActiveCamera()
		      .getAbsolutePosition();
	    float[] fs = new float[3];
	    fs[0] = var_vector3df.getX();
	    fs[1] = var_vector3df.getY();
	    fs[2] = var_vector3df.getZ();
	    if (TestShaders.UseHighLevelShaders)
		imaterialrendererservices.setVertexShaderConstant("mLightPos",
								  fs, 3);
	    else
		imaterialrendererservices.setVertexShaderConstant(fs, 8, 1);
	    SColorf scolorf = new SColorf(0.0F, 1.0F, 1.0F, 0.0F);
	    float[] fs_1_ = new float[4];
	    fs_1_[0] = scolorf.getR();
	    fs_1_[1] = scolorf.getG();
	    fs_1_[2] = scolorf.getB();
	    fs_1_[3] = scolorf.getA();
	    if (TestShaders.UseHighLevelShaders)
		imaterialrendererservices
		    .setVertexShaderConstant("mLightColor", fs_1_, 4);
	    else
		imaterialrendererservices.setVertexShaderConstant(fs_1_, 9, 1);
	    matrix4 var_matrix4_2_
		= ivideodriver.getTransform(E_TRANSFORMATION_STATE.ETS_WORLD);
	    var_matrix4_2_ = var_matrix4_2_.getTransposed();
	    if (TestShaders.UseHighLevelShaders)
		imaterialrendererservices.setVertexShaderConstant
		    ("mTransWorld", var_matrix4_2_.getM(), 16);
	    else
		imaterialrendererservices
		    .setVertexShaderConstant(var_matrix4_2_.getM(), 10, 4);
	}
    }
    
    public static void main(String[] strings) {
	E_DRIVER_TYPE e_driver_type = E_DRIVER_TYPE.EDT_SOFTWARE;
	System.out.println
	    ("Please select the driver you want for this example:\n (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.2\n (d) Software Renderer\n (e) NullDevice\n (otherKey) exit\n\n");
	try {
	    int i = System.in.read();
	    switch (i) {
	    case 97:
		e_driver_type = E_DRIVER_TYPE.EDT_DIRECT3D9;
		break;
	    case 98:
		e_driver_type = E_DRIVER_TYPE.EDT_DIRECT3D8;
		break;
	    case 99:
		e_driver_type = E_DRIVER_TYPE.EDT_OPENGL;
		break;
	    case 100:
		e_driver_type = E_DRIVER_TYPE.EDT_SOFTWARE;
		break;
	    case 101:
		e_driver_type = E_DRIVER_TYPE.EDT_NULL;
		break;
	    default:
		System.exit(0);
	    }
	} catch (IOException ioexception) {
	    ioexception.printStackTrace();
	}
	if (e_driver_type == E_DRIVER_TYPE.EDT_DIRECT3D9) {
	    System.out.println
		("Please press 'y' if you want to use high level shaders.\n");
	    try {
		int i = System.in.read();
		if (i == 121)
		    UseHighLevelShaders = true;
	    } catch (IOException ioexception) {
		ioexception.printStackTrace();
	    }
	}
	device = Jirr.createDeviceJava(e_driver_type, 640, 480, 32L, false,
				       false, false, null);
	if (device == null)
	    System.exit(1);
	IVideoDriver ivideodriver = device.getVideoDriver();
	ISceneManager iscenemanager = device.getSceneManager();
	IGUIEnvironment iguienvironment = device.getGUIEnvironment();
	String string = null;
	String string_3_ = null;
	if (e_driver_type == E_DRIVER_TYPE.EDT_DIRECT3D8) {
	    string_3_ = "../media/d3d8.psh";
	    string = "../media/d3d8.vsh";
	} else if (e_driver_type == E_DRIVER_TYPE.EDT_DIRECT3D9) {
	    if (UseHighLevelShaders) {
		string_3_ = "../media/d3d9.hlsl";
		string = string_3_;
	    } else {
		string_3_ = "../media/d3d9.psh";
		string = "../media/d3d9.vsh";
	    }
	} else if (e_driver_type == E_DRIVER_TYPE.EDT_OPENGL) {
	    string_3_ = "../media/opengl.psh";
	    string = "../media/opengl.vsh";
	}
	if (!ivideodriver
		 .queryFeature(E_VIDEO_DRIVER_FEATURE.EVDF_PIXEL_SHADER_1_1)
	    && !ivideodriver.queryFeature(E_VIDEO_DRIVER_FEATURE
					  .EVDF_ARB_FRAGMENT_PROGRAM_1)) {
	    device.getLogger().log
		("WARNING: Pixel shaders disabled because of missing driver/hardware support.");
	    string_3_ = null;
	}
	if (!ivideodriver
		 .queryFeature(E_VIDEO_DRIVER_FEATURE.EVDF_VERTEX_SHADER_1_1)
	    && !ivideodriver.queryFeature(E_VIDEO_DRIVER_FEATURE
					  .EVDF_ARB_VERTEX_PROGRAM_1)) {
	    device.getLogger().log
		("WARNING: Vertex shaders disabled because of missing driver/hardware support.");
	    string = null;
	}
	IGPUProgrammingServices igpuprogrammingservices
	    = ivideodriver.getGPUProgrammingServices();
	int i = 0;
	int i_4_ = 0;
	if (igpuprogrammingservices != null) {
	    MyShaderCallBack myshadercallback = new MyShaderCallBack();
	    if (UseHighLevelShaders) {
		i = (igpuprogrammingservices
			 .addHighLevelShaderMaterialFromFiles
		     (string, "vertexMain", E_VERTEX_SHADER_TYPE.EVST_VS_1_1,
		      string_3_, "pixelMain", E_PIXEL_SHADER_TYPE.EPST_PS_1_1,
		      myshadercallback, E_MATERIAL_TYPE.EMT_SOLID));
		i_4_
		    = (igpuprogrammingservices
			   .addHighLevelShaderMaterialFromFiles
		       (string, "vertexMain", E_VERTEX_SHADER_TYPE.EVST_VS_1_1,
			string_3_, "pixelMain",
			E_PIXEL_SHADER_TYPE.EPST_PS_1_1, myshadercallback,
			E_MATERIAL_TYPE.EMT_TRANSPARENT_ADD_COLOR));
	    } else {
		i = (igpuprogrammingservices.addShaderMaterialFromFiles
		     (string, string_3_, myshadercallback,
		      E_MATERIAL_TYPE.EMT_SOLID));
		i_4_ = (igpuprogrammingservices.addShaderMaterialFromFiles
			(string, string_3_, myshadercallback,
			 E_MATERIAL_TYPE.EMT_TRANSPARENT_ADD_COLOR));
	    }
	    myshadercallback.drop();
	}
	ISceneNode iscenenode = iscenemanager.addTestSceneNode(50.0F);
	iscenenode.setPosition(new vector3df(0.0F, 0.0F, 0.0F));
	iscenenode.setMaterialTexture(0, ivideodriver
					     .getTexture("../media/wall.jpg"));
	iscenenode.setMaterialTypeByInt(i);
	iscenemanager.addTextSceneNode(iguienvironment.getBuiltInFont(),
				       "PS & VS & EMT_SOLID",
				       new SColor(255, 255, 255, 255),
				       iscenenode);
	ISceneNodeAnimator iscenenodeanimator
	    = iscenemanager.createRotationAnimator(new vector3df(0.0F, 0.3F,
								 0.0F));
	iscenenode.addAnimator(iscenenodeanimator);
	iscenenodeanimator.drop();
	iscenenode = iscenemanager.addTestSceneNode(50.0F);
	iscenenode.setPosition(new vector3df(0.0F, -10.0F, 50.0F));
	iscenenode.setMaterialTexture(0, ivideodriver
					     .getTexture("../media/wall.jpg"));
	iscenenode.setMaterialTypeByInt(i_4_);
	iscenemanager.addTextSceneNode(iguienvironment.getBuiltInFont(),
				       "PS & VS & EMT_TRANSPARENT",
				       new SColor(255, 255, 255, 255),
				       iscenenode);
	iscenenodeanimator
	    = iscenemanager.createRotationAnimator(new vector3df(0.0F, 0.3F,
								 0.0F));
	iscenenode.addAnimator(iscenenodeanimator);
	iscenenodeanimator.drop();
	iscenenode = iscenemanager.addTestSceneNode(50.0F);
	iscenenode.setPosition(new vector3df(0.0F, 50.0F, 25.0F));
	iscenenode.setMaterialTexture(0, ivideodriver
					     .getTexture("../media/wall.jpg"));
	iscenemanager.addTextSceneNode(iguienvironment.getBuiltInFont(),
				       "NO SHADER",
				       new SColor(255, 255, 255, 255),
				       iscenenode);
	ivideodriver.setTextureCreationFlag((E_TEXTURE_CREATION_FLAG
					     .ETCF_CREATE_MIP_MAPS),
					    false);
	iscenemanager.addSkyBoxSceneNode
	    (ivideodriver.getTexture("../media/irrlicht2_up.bmp"),
	     ivideodriver.getTexture("../media/irrlicht2_dn.bmp"),
	     ivideodriver.getTexture("../media/irrlicht2_lf.bmp"),
	     ivideodriver.getTexture("../media/irrlicht2_rt.bmp"),
	     ivideodriver.getTexture("../media/irrlicht2_ft.bmp"),
	     ivideodriver.getTexture("../media/irrlicht2_bk.bmp"));
	ivideodriver.setTextureCreationFlag((E_TEXTURE_CREATION_FLAG
					     .ETCF_CREATE_MIP_MAPS),
					    true);
	ICameraSceneNode icamerascenenode
	    = iscenemanager.addCameraSceneNodeFPS(null, 100.0F, 100.0F);
	icamerascenenode.setPosition(new vector3df(-100.0F, 50.0F, 100.0F));
	icamerascenenode.setTarget(new vector3df(0.0F, 0.0F, 0.0F));
	device.getCursorControl().setVisible(false);
	int i_5_ = -1;
	while (device.run()) {
	    if (device.isWindowActive()) {
		ivideodriver.beginScene(true, true, new SColor(255, 0, 0, 0));
		iscenemanager.drawAll();
		ivideodriver.endScene();
		int i_6_ = ivideodriver.getFPS();
		if (i_5_ != i_6_) {
		    String string_7_
			= "Irrlicht Engine @Java - Vertex and pixel shader example [";
		    string_7_ += ivideodriver.getName();
		    string_7_ += "] FPS:";
		    string_7_ += i_6_;
		    device.setWindowCaption(string_7_);
		    i_5_ = i_6_;
		}
	    }
	}
	device.drop();
	System.exit(0);
    }
    
    static {
	System.loadLibrary("irrlicht_wrap");
	device = null;
	UseHighLevelShaders = false;
    }
}


/***** DECOMPILATION REPORT *****
	LOCATION: D:\leadercode\code\particle editor\jirr_classes.jar!TestShaders
	TOTAL TIME: 0 ms
 ********************************/
http://www.javazing.com
P-III-950, WinXP, GeForce FX5600 128 MB ForceWare 52.16, DX9, Eclipse IDE, JRE 1.6
Post Reply