www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: AGP on September 05, 2012, 01:37:29 am

Title: Transparency Revisited
Post by: AGP on September 05, 2012, 01:37:29 am
Not having solved the shadow problem yet, I decided to move on to this one. :- ) The following image shows the result of a pressed button not set and set to TRANSPARENCY_MODE_ADD. Obviously, neither is the desired result. I've also tried making the Texture with alpha information (currently, the background is a solic black), but that didn't help either. Please help. Edit: I should mention that these buttons are being blitted onto the FrameBuffer.

(http://ratto.co/TransparencyRevisited.jpg)
Title: Re: Transparency Revisited
Post by: EgonOlsen on September 05, 2012, 08:33:13 am
You have to use an alpha channel and create the texture with appropriate constructor (the one that takes the useAlpha-parameter) and blit it in default mode.
Title: Re: Transparency Revisited
Post by: AGP on September 05, 2012, 10:16:02 am
Thanks a lot, that did it. Now, I'm trying to get blitting to work on the same screen with the software renderer, but the result is as follows. I'm using the FrameBuffer's Graphics object, in this case, to draw the position of my buttons, because the OpenGL-rendered ones seem to be in the wrong place (does the FrameBuffer use a different coordinate system or should I just translate my mouse coordinates by the title bar's height?). Anyway, either way, it's not working in software.

(http://ratto.co/BlittingSoftware.jpg)
Title: Re: Transparency Revisited
Post by: AGP on September 05, 2012, 10:42:32 am
I should mention that I removed the references to the FrameBuffer's Graphics object to see if it made a difference (did not)  and that the background image is 1024x1024 is 32-bits (which, come to think of it, must be the problem!).
Title: Re: Transparency Revisited
Post by: AGP on September 05, 2012, 08:21:48 pm
OK, I converted the image to 8 bits and it still looks like the above screenshot. The following is the code that works for hardware but that hasn't been working for the software renderer:

Code: [Select]
     public void draw(java.awt.Canvas glCanvas) {
buffer.clear(java.awt.Color.black);
buffer.update();
buffer.blit(background, 0, 0, 0, 0, background.getWidth(), background.getHeight(), buffer.getOutputWidth(), buffer.getOutputHeight(), -1, false);
playButton.draw(buffer);
loadButton.draw(buffer);
introButton.draw(buffer);
quitButton.draw(buffer);
if (buffer.usesRenderer(IRenderer.RENDERER_OPENGL)) {
     buffer.displayGLOnly();
     glCanvas.repaint();
}
else buffer.display(glCanvas.getGraphics());
     }
Title: Re: Transparency Revisited
Post by: EgonOlsen on September 05, 2012, 09:05:25 pm
Scaled blitting in the software renderer uses an Overlay internally. Maybe that doesn't work right (anymore). I'll take a look...
Title: Re: Transparency Revisited
Post by: EgonOlsen on September 05, 2012, 09:23:46 pm
I made myself a test case blitting a 512*512 texture to a 128*128 quad and one 1024*1024 as a backdrop in 1920*1200...works perfectly fine!? How are you initializing the software renderer? It somehow looks as if you are using the legacy mode instead of opengl. Can you post the part that enables the software renderer?
Title: Re: Transparency Revisited
Post by: AGP on September 05, 2012, 09:40:33 pm
Isn't OpenGL default, now? I'm not setting it to legacy.

Code: [Select]
     buffer = new FrameBuffer((int)(1024*engineData.widthMul +.5d), (int)(768*engineData.heightMul +.5d), FrameBuffer.SAMPLINGMODE_NORMAL);
Title: Re: Transparency Revisited
Post by: EgonOlsen on September 05, 2012, 09:42:36 pm
Yes openGL mode is default. There's no additonal enableRenderer call in your code?
Title: Re: Transparency Revisited
Post by: AGP on September 05, 2012, 09:46:18 pm
No.
Title: Re: Transparency Revisited
Post by: EgonOlsen on September 05, 2012, 09:48:30 pm
Can you please post the complete log output!?
Title: Re: Transparency Revisited
Post by: AGP on September 05, 2012, 10:10:11 pm
Sure:

Java version is: 1.7.0_01
-> support for BufferedImage
Version helper for 1.5+ initialized!
-> using BufferedImage
Software renderer (OpenGL mode) initialized
Loading Texture...NewLevel\barkA.png
Loading Texture...NewLevel\grassA.png
Loading Texture...NewLevel\grassB.png
Loading Texture...NewLevel\grassC.png
Loading Texture...NewLevel\ground.png
Loading Texture...NewLevel\plantA.png
Loading Texture...NewLevel\plantB.png
Loading Texture...NewLevel\treeHa.png
Loading Texture...NewLevel\treeHb.png
Loading Texture...NewLevel\treeHc.png
Loading Texture...NewLevel\treeHd.png
Loading Texture...Silmaria\arbusto_001.png
Loading Texture...Silmaria\Banco_difuse1_copy.png
Loading Texture...Silmaria\Barco_Porto_001.png
Loading Texture...Silmaria\Barrel_difuse_copy.png
Loading Texture...Silmaria\Canal.png
Loading Texture...Silmaria\Carroτa_Frutas_difuse_copy.png
Loading Texture...Silmaria\CasaPrincipal1_difuse.png
Loading Texture...Silmaria\casa_bandeira_difuse1_copy.png
Loading Texture...Silmaria\casa_tenda_difuse1_copy.png
Loading Texture...Silmaria\DIfuse_Casa1.png
Loading Texture...Silmaria\Difuse_Casa2.png
Loading Texture...Silmaria\difuse_Casa3.png
Loading Texture...Silmaria\Difuse_CasaPrincipal.png
Loading Texture...Silmaria\difuse_condominio_copy.png
Loading Texture...Silmaria\Difuse_muralhaeprops_copy.png
Loading Texture...Silmaria\Difuse_MuralhaPrincipal.png
Loading Texture...Silmaria\Difuse_Muralhas1_2.png
Loading Texture...Silmaria\Difuse_prefeitura1.png
Loading Texture...Silmaria\Difuse_props1copy.png
Loading Texture...Silmaria\Difuse_teatro1_copy.png
Loading Texture...Silmaria\escadaria_dfuse1_copy.png
Loading Texture...Silmaria\folhagem_002.png
Loading Texture...Silmaria\Museu01_difuse_copy.png
Loading Texture...Silmaria\palmeira_001.png
Loading Texture...Silmaria\pedras_001.png
Loading Texture...Silmaria\pinheiro_001.png
Loading Texture...Silmaria\ponte_difuse_copy.png
Loading Texture...Silmaria\rio_001.png
Loading Texture...Silmaria\Solo_001.png
Loading Texture...Silmaria\Solo_002.png
Loading Texture...Silmaria\Solo_003.png
Loading Texture...Silmaria\Solo_004.png
Loading Texture...Silmaria\splash_001.png
Loading Texture...Silmaria\telhadoprincipal_difuse_copy.png
Loading Texture...Silmaria\Templo_difuse_copy.png
Loading Texture...Silmaria\Tenda1_difuse_copy.png
Loading Texture...Silmaria\tonel_difuse_copy.png
Loading Texture...Girl.jpg
Loading Texture...GirlLingerie.jpg
Loading Texture...MaleQGHero.png
Loading Texture...MistressBrown.png
Loading Texture...SunnySky/left.jpg
[ Wed Sep 05 17:12:03 EDT 2012 ] - WARNING: Unsupported Texture width (600)...re
sizing to a width of 256 pixels!
Loading Texture...SunnySky/front.jpg
[ Wed Sep 05 17:12:03 EDT 2012 ] - WARNING: Unsupported Texture width (600)...re
sizing to a width of 256 pixels!
Loading Texture...SunnySky/right.jpg
[ Wed Sep 05 17:12:03 EDT 2012 ] - WARNING: Unsupported Texture width (600)...re
sizing to a width of 256 pixels!
Loading Texture...SunnySky/back.jpg
[ Wed Sep 05 17:12:03 EDT 2012 ] - WARNING: Unsupported Texture width (600)...re
sizing to a width of 256 pixels!
Loading Texture...SunnySky/top.jpg
[ Wed Sep 05 17:12:03 EDT 2012 ] - WARNING: Unsupported Texture width (600)...re
sizing to a width of 256 pixels!
Loading Texture...SunnySky/top.jpg
[ Wed Sep 05 17:12:03 EDT 2012 ] - WARNING: Unsupported Texture width (600)...re
sizing to a width of 256 pixels!
OS Version: Windows 7
Loading Texture...from Image
Loading Texture...playOpening_off.png
Loading Texture...playOpening_on.png
Loading Texture...load_off.png
Loading Texture...load_on.png
Loading Texture...introduction_off.png
Loading Texture...introduction_on.png
Loading Texture...quit_off.png
Loading Texture...quit_on.png
New WorldProcessor created using 1 thread(s) and granularity of 1!
Creating new world processor buffer for thread main
Loading Texture...from Image
Wrapping input stream in a BufferedInputStream
Loading Texture...from Image
Loading Texture...from Image
Loading Texture...from Image
Loading Texture...from Image
Loading Texture...from Image
Loading Texture...import_off.png
Loading Texture...import_on.png
Loading Texture...cancel_off.png
Loading Texture...cancel_on.png
Loading Texture...play_off.png
Loading Texture...play_on.png
Visibility lists disposed!
Software renderer disposed
Title: Re: Transparency Revisited
Post by: EgonOlsen on September 05, 2012, 10:25:12 pm
Looks fine. What are these xxxButton.draw()-methods doing? Does it change something if you remove them and only blit the background? Which version of jPCT are you using? The latest official release?
Title: Re: Transparency Revisited
Post by: AGP on September 05, 2012, 11:12:35 pm
They blit the FrameBuffer individually. Not drawing them doesn't change anything. Using 1.25.
Title: Re: Transparency Revisited
Post by: EgonOlsen on September 06, 2012, 07:06:23 am
I need some test case then. It works fine for me, i can't reproduce this.
Title: Re: Transparency Revisited
Post by: AGP on September 06, 2012, 07:33:43 pm
Since you already have my draw method, I will send you my image.
Title: Re: Transparency Revisited
Post by: EgonOlsen on September 06, 2012, 08:50:30 pm
I made this out of it and it works just fine. I made myself two on/off buttons of 128*128 pixels and added some code to repaint the JFrame on click. To make the buttons appear, i had to add a buffer.clearZBuffer(); between blitting the backdrop and the buttons. That's needed because the software renderer's scaled blit is actually an Overlay and therefor has a depth that will be written into the frame buffer. However, the visuals are fine and look in no way like in your screen shot: http://jpct.de/pix/agp.png (http://jpct.de/pix/agp.png)

Code: [Select]
package agp;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

import com.threed.jpct.*;

public class OpeningScreen extends JFrame implements MouseListener {
private static final long serialVersionUID = 1L;
private Texture background;
protected boolean hasFinished, quitPressed, introPressed;
private FrameBuffer buffer;
private float widthMul, heightMul;
private Button3d playButton, loadButton, introButton, quitButton;

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

public OpeningScreen() {
FrameBuffer buffer = new FrameBuffer(1024, 768, FrameBuffer.SAMPLINGMODE_NORMAL);

this.buffer = buffer;
quitPressed = false;
widthMul = ((float) buffer.getOutputWidth()) / 1024f;
heightMul = ((float) buffer.getOutputHeight()) / 768f;
background = new Texture("OpeningScreen.png", false);
hasFinished = false;
playButton = new Button3d(406f * widthMul, 360 * heightMul, 202f * widthMul, 80f * heightMul, new Texture("off.png", true), new Texture("on.png", true));
loadButton = new Button3d(406f * widthMul, 440 * heightMul, 202f * widthMul, 80f * heightMul, new Texture("off.png", true), new Texture("on.png", true));
introButton = new Button3d(406f * widthMul, 520 * heightMul, 202f * widthMul, 80f * heightMul, new Texture("off.png", true), new Texture("on.png", true));
quitButton = new Button3d(406f * widthMul, 600 * heightMul, 202f * widthMul, 80f * heightMul, new Texture("off.png", true), new Texture("on.png", true));

this.setSize(1024, 768);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.addMouseListener(this);
}

public void processClick(int x, int y) {
if (playButton.contains(x, y))
hasFinished = true;
else if (introButton.contains(x, y))
introPressed = true;
else if (quitButton.contains(x, y))
hasFinished = quitPressed = true;
this.repaint();
}

public void processPress(int x, int y) {
if (playButton.contains(x, y))
playButton.isPressed = true;
else if (loadButton.contains(x, y))
loadButton.isPressed = true;
else if (introButton.contains(x, y))
introButton.isPressed = true;
else if (quitButton.contains(x, y))
quitButton.isPressed = true;
this.repaint();
}

public void processRelease(int x, int y) {
playButton.isPressed = loadButton.isPressed = introButton.isPressed = quitButton.isPressed = false;
this.repaint();
}

@Override
public void paint(Graphics g) {
update(g);
}

@Override
public void update(Graphics g) {
buffer.clear(java.awt.Color.black);
buffer.update();
buffer.blit(background, 0, 0, 0, 0, background.getWidth(), background.getHeight(), buffer.getOutputWidth(), buffer.getOutputHeight(), -1, false);
buffer.clearZBufferOnly();
playButton.draw(buffer);
loadButton.draw(buffer);
introButton.draw(buffer);
quitButton.draw(buffer);
buffer.display(g);
}

@Override
public void mouseClicked(MouseEvent arg0) {
processClick(arg0.getX(), arg0.getY());
}

@Override
public void mouseEntered(MouseEvent arg0) {
//
}

@Override
public void mouseExited(MouseEvent arg0) {
//
}

@Override
public void mousePressed(MouseEvent arg0) {
processPress(arg0.getX(), arg0.getY());
}

@Override
public void mouseReleased(MouseEvent arg0) {
processRelease(arg0.getX(), arg0.getY());
}
}

class Button3d {
private int x, y, width, height;
private Texture unpressed, pressed;
protected boolean isPressed;

public Button3d(float x, float y, float width, float height, Texture unpressed, Texture pressed) {
this.x = (int) (x + .5f);
this.y = (int) (y + .5f);
this.width = (int) (width + .5f);
this.height = (int) (height + .5f);
this.unpressed = unpressed;
this.pressed = pressed;
isPressed = false;
}

public boolean contains(int x, int y) {
if (x > this.x && x <= this.x + this.width && y > this.y && y <= this.y + this.height) {
return true;
}
return false;
}

public void draw(FrameBuffer buffer) {
if (!isPressed) {
buffer.blit(unpressed, 0, 0, x, y, unpressed.getWidth(), unpressed.getHeight(), width, height, 200, false);
} else {
buffer.blit(pressed, 0, 0, x, y, pressed.getWidth(), pressed.getHeight(), width, height, 200, false);
}
if (buffer.usesRenderer(IRenderer.RENDERER_SOFTWARE)) {
java.awt.Graphics g2 = buffer.getGraphics();
g2.setColor(java.awt.Color.blue);
g2.drawRect((int) x, (int) y, (int) width, (int) height);
}
}
}

Title: Re: Transparency Revisited
Post by: AGP on September 06, 2012, 08:59:37 pm
That's very strange. I added the clearZBufferOnly() in between the blits, but I saw no improvement.
Title: Re: Transparency Revisited
Post by: EgonOlsen on September 06, 2012, 09:08:36 pm
That's very strange. I added the clearZBufferOnly() in between the blits, but I saw no improvement.
That's just to make the buttons appear. It has nothing do to with the backdrop. Have you tried my test case for yourself?
Title: Re: Transparency Revisited
Post by: AGP on September 06, 2012, 09:53:45 pm
No, I'll try it, but as far as I can tell the only difference in yours is the lack of a java.awt.Canvas.
Title: Re: Transparency Revisited
Post by: AGP on September 08, 2012, 05:21:51 am
For the record, yours works. From where I'm sitting, this is either a bug on blit (or otherwise, more likely, Overlay) or an awt one related to the use of the canvas. Could you have a look, please?
Title: Re: Transparency Revisited
Post by: EgonOlsen on September 08, 2012, 09:04:55 pm
I don't see how this should be related to using a canvas at all. Displaying the rendered image is a simple drawImage-call and that the only line where the component and the engine interact with each other. You could simply try this by opening an additional JFrame in your application and do the drawing into that one instead.
There might be some problem in Overlay, but i've no idea how to track this down. All my usual test cases and this new one work fine. I've no idea what you are doing different to cause this behaviour. I can only suggest that you try to find the difference between what you are doing and what the test case does. Something has to be different.
I can't help code wise in the next two weeks, because i'll be AFK. I'll browse the forum though if the mobile connection allows it.