Main Menu

Recent posts

#11
Support / Re: Software Render Color Dept...
Last post by EgonOlsen - February 26, 2025, 06:29:10 AM
That's because the GL renderer discards a texture's actual pixel data once it has been uploaded to the GPU. There's a 'keepPixelData()' method in Texture to prevent this.
#12
Support / Re: Software Render Color Dept...
Last post by AGP - February 26, 2025, 02:38:36 AM
Now I want the same code to also work with OpenGL. But I'm getting:
QuoteException in thread "main" java.lang.NullPointerException: Cannot read the array length because "this.texels" is null
#13
Support / Is there any magic to compile(...
Last post by AGP - February 24, 2025, 08:52:34 PM
I can do compile(true) and not lose animations on Raft's bones. But it breaks the animations on my GLB models with my own bone structure. Is there anything that I should be overriding and adding? If not, would you have a clue as to what's doing this?
#14
Support / Re: Software Render Color Dept...
Last post by EgonOlsen - February 19, 2025, 06:58:07 AM
Yes, a little bit...  ;) It's actually a performance issue. The "old" transparency code is optimized for speed and not accuracy, which is why its results are  not on par with what the GL renderer could do. The alpha stuff has been added much later. It's more flexible but also slower.
#15
Support / Re: Software Render Color Dept...
Last post by AGP - February 16, 2025, 09:52:21 PM
Thanks a lot. It is unnecessarily complicated, though, isn't it?
#16
Support / Re: Software Render Color Dept...
Last post by EgonOlsen - February 13, 2025, 07:54:51 AM
setAlpha really means the alpha value as it's represented in the texture, i.e. shifted up by 24. Here's an example of how it works:

import java.awt.*;
import java.awt.event.*;
import com.threed.jpct.*;

public class Transparency extends Frame implements WindowListener {
    private World theWorld;
    private FrameBuffer buffer;
    private Camera cam;
    private Object3D obj;
    private boolean keepGoing, turnRight, turnLeft;
    private com.threed.jpct.util.KeyMapper keyMapper;
    private Texture boxMap;
    private int transparency = 0;

    public Transparency() {
      this.setTitle("BR's");
      theWorld = new World();
      buffer = new FrameBuffer(1440, 900, FrameBuffer.SAMPLINGMODE_NORMAL);
      obj = com.threed.jpct.util.ExtendedPrimitives.createBox(new SimpleVector(2f, 2f, 2f));//Primitives.getCube(1f);
      TextureManager.getInstance().addTexture("boxMap", (boxMap=new Texture("test.jpg", true)));
      obj.setTexture("boxMap");
      obj.setTransparency(0);
      //obj.setTransparencyMode(Object3D.TRANSPARENCY_MODE_ADD);
      obj.build();
      Object3D backgroundPlane = Primitives.getPlane(1, 4f);
      backgroundPlane.build();
      backgroundPlane.translate(0f, -2f, 0f);
      theWorld.addObject(backgroundPlane);
      cam = theWorld.getCamera();
      cam.moveCamera(Camera.CAMERA_MOVEOUT, 8f);
      theWorld.addObject(obj);
      theWorld.setAmbientLight(255, 255, 255);
      keyMapper = new com.threed.jpct.util.KeyMapper(this);
      this.addWindowListener(this);
      this.setSize(buffer.getWidth(), buffer.getHeight());
      this.setVisible(true);
      loop();
    }

    public void loop() {
      keepGoing = true;
      transparency=0;
      int dir = 1;
      int its= 0;
      while (keepGoing) {
          buffer.clear();
          com.threed.jpct.util.KeyState keyState = keyMapper.poll();
          if (keyState.getState() == com.threed.jpct.util.KeyState.PRESSED)
              keyPressed(keyState.getKeyCode());
          else if (keyState.getState() == com.threed.jpct.util.KeyState.RELEASED)
              keyReleased(keyState.getKeyCode());
          if (turnRight)
              obj.rotateY(-.01f);
          if (turnLeft)
              obj.rotateY(.01f);
          theWorld.renderScene(buffer);
          theWorld.draw(buffer);
          //theWorld.drawWireframe(buffer, Color.yellow);
          buffer.display(this.getGraphics());
          its++;
              if (its>10)  {
              transparency+=dir;
              if (Math.abs(transparency)>255 || transparency==0) {
                  dir*=-1;
              }
              //obj.setTransparency(transparency);
              TextureManager.getInstance().getTexture("boxMap").setAlpha(transparency<<24);
              System.out.println("Trans: "+transparency);
              its = 0;
          }
          Thread.yield();
      }
      buffer.dispose();
      this.dispose();
      System.exit(0);
    }

    private void keyPressed(int keyCode) {
      if (keyCode == KeyEvent.VK_RIGHT)
          turnRight = true;
      if (keyCode == KeyEvent.VK_LEFT)
          turnLeft = true;
    }
    private void keyReleased(int keyCode) {
      if (keyCode == KeyEvent.VK_RIGHT)
          turnRight = false;
      if (keyCode == KeyEvent.VK_LEFT)
          turnLeft = false;
    }
    public void windowClosing(WindowEvent e) {
      keepGoing = false;
    }
    public void windowClosed(WindowEvent e) {}
    public void windowOpened(WindowEvent e) {}
    public void windowActivated(WindowEvent e) {}
    public void windowDeactivated(WindowEvent e) {}
    public void windowIconified(WindowEvent e) {}
    public void windowDeiconified(WindowEvent e) {}

    public static void main(String[] args) {
      new Transparency();
    }
}

#17
Support / Re: Software Render Color Dept...
Last post by AGP - February 12, 2025, 07:21:56 AM
I tried texture.setAlpha(). Even tried replacing the texture in the texture manager. It doesn't change the object's opacity in any way.
#18
Support / Re: Software Render Color Dept...
Last post by EgonOlsen - February 10, 2025, 06:48:51 AM
Either use a texture with no alpha channel and do setTransparency()...but that might look a bit coarse. Or use a texture with alpha and use Texture.setAlpha(). But that will alter the texture, which is slower and might not be feasible if you intend to do that on objects of which some are supposed to fade out while others won't.
#19
Support / Re: Software Render Color Dept...
Last post by AGP - February 09, 2025, 08:47:48 PM
So is there no way to do a proper fadeout?
#20
Support / Re: Software Render Color Dept...
Last post by EgonOlsen - February 09, 2025, 02:07:09 PM
That's because the usage of alpha in the texture itself overrides the global transparency setting. Or in other words, if a texture uses an alpha channel, it doesn't allow for setting the global transparency using setTransparency(). IIRC, this is a limitation of the software renderer. However, transpancy using setTransparency is pretty coarse anyway. But that's not related to color depth but to the way in which it's applied.