SC4 Devotion Forum Archives

Other City-Building Games => [Archived] CityMania - Open Source Sim City => Other games => CityMania Programming => Topic started by: Nique on January 23, 2010, 07:33:58 AM

Title: Panda3D Specific Help (learning)
Post by: Nique on January 23, 2010, 07:33:58 AM
Hello, i opened this thread (for my self and others) to solve problems we might have with the engine.

I kick off with a very noob question..

I try to render a image to the window, but this image is being scaled up to the window. I dont want the images to be scaled up conforming the window width. Why is everything 'relative' to the panda window?


(https://www.sc4devotion.com/forums/proxy.php?request=http%3A%2F%2Fi5.photobucket.com%2Falbums%2Fy199%2FNe0que%2FCityMania%2FLogoRenders%2FCITYMANIA_TRANSPARANT.png&hash=2ad352db2c145f4d1e079ef361af4d81f9726c65)
+

# Function to draw the splash
def addSplashImage(image):
    return OnscreenImage(image = image, pos = (0,0,0), scale = 1)

class Game(DirectObject):
    def __init__(self):
        base.setBackgroundColor(0.22,0.22,0.22)
        self.accept("escape",sys.exit)
        self.title = addTitle("CityMania TestWindow")
        self.splashImg = addSplashImage("logo.png")
        self.splashImg.setTransparency(TransparencyAttrib.MAlpha)

=



(https://www.sc4devotion.com/forums/proxy.php?request=http%3A%2F%2Fi47.tinypic.com%2F23sw3sx.jpg&hash=f6e8f8f625e4570418cd5dc617643c9a09cf2e81)

What the hell?
This is insane. Please dont tell me the app need to recalculate the actual image size ? by getting window width's etc etc etc etc..? For each image?! Who ever invented this , this is insane  ()what()
Title: Re: Panda3D Specific Help
Post by: croxis on January 23, 2010, 09:16:26 AM
There are two major branches in the panda render tree, render, and render2d. render2d is fairly dumb and will stretch images like you see. However there is a child node, aspect2d, that will maintain the aspect ratio. You will need the Node.reparentTo(aspect2d) command.



# Function to draw the splash
def addSplashImage(image):
    image = OnscreenImage(image = image, pos = (0,0,0), scale = 1)
    image.reparentTo(apect2d)
    return

class Game(DirectObject):
    def __init__(self):
        base.setBackgroundColor(0.22,0.22,0.22)
        self.accept("escape",sys.exit)
        self.title = addTitle("CityMania TestWindow")
        self.splashImg = addSplashImage("logo.png")
        self.splashImg.setTransparency(TransparencyAttrib.MAlpha)


There is also a pixel2d layer which coordinate system is based on pixels instead.
Title: Re: Panda3D Specific Help
Post by: Nique on January 23, 2010, 09:45:39 AM
Thanks,

This tells me some more, i did read a lot of the manual but i guess i accidentally skipped it. Anyway, i still get the same result..


# Function to draw the splash
def addSplashImage(image):
    img=OnscreenImage(image = image, pos = (0,0,0), scale = 1)
    img.reparentTo(aspect2d)
    img.setTransparency(TransparencyAttrib.MAlpha)   
    return img

class Game(DirectObject):
    def __init__(self):
        base.setBackgroundColor(0.22,0.22,0.22)
        self.accept("escape",sys.exit)
        self.title = addTitle("CityMania TestWindow")
        self.splashImg = addSplashImage("logo.png")
Title: Re: Panda3D Specific Help (learning)
Post by: croxis on January 23, 2010, 10:09:28 AM
This is curious. OnScreenImage should be parented to aspect2d by default. Try removing the scale parameter.
Title: Re: Panda3D Specific Help (learning)
Post by: croxis on January 23, 2010, 10:38:05 AM
Also, My irc client auto signs in to #citymania and #panda3d (both on freenode), so you can catch me in either location. There is also my wave account too :)
Title: Re: Panda3D Specific Help (learning)
Post by: Nique on January 24, 2010, 03:36:01 AM
Roger that,

I have problems to get 1.7.0 working on windows as the buildbot provides a 'not working' version. So i decided to build panda3d my self, but that also is impossible....

because... you can't download the thirdparty dir anywhere... (this is bad and frustrating me bigtime)
So none of these 2 options seems to work. I want 1.7.0 (seems to be released this week.. but pages on home page arent updated) because of it's pixel2d function.

Is there somehow, another way to get this working? Do you have the thirdparty dir of 1.7.0 croxis?


Nevermind, they released 1.7.0 (http://www.panda3d.org/download/panda3d-1.7.0/Panda3D-1.7.0.exe) now
Title: Re: Panda3D Specific Help (learning)
Post by: Nique on January 24, 2010, 06:59:02 AM
<?php



from pandac
.PandaModules import loadPrcFileData
loadPrcFileData
("""""    
    window-title CityMania
    fullscreen 0
    win-size 1024 768
    cursor-hidden 1
    sync-video 0
    frame-rate-meter-update-interval 0.5
    show-frame-rate-meter 1
"""
)

import direct.directbase.DirectStart
from pandac
.PandaModules import TextNode,Vec3,PNMImageHeader,Filename
from pandac
.PandaModules import TransparencyAttrib
from direct
.showbase.DirectObject import DirectObject
from direct
.gui.OnscreenText import OnscreenText
from direct
.gui.OnscreenImage import OnscreenImage

import sys
font 
loader.loadFont("cmss12")

# Function to put title on the screen.
def addTitle(text):
    return 
OnscreenText(text=textstyle=1fg=(1,1,1,1), font font
                
pos=(1,-0.8), align=TextNode.ARightscale .07)

# Function to draw the splash
def addSplashImage(image):
    
iH=PNMImageHeader()
    
iH.readHeader(Filename(image))
    
img=OnscreenImage(image image)
    
img.reparentTo(pixel2d)
    
img.setPos(base.win.getXSize()/2,0,0-base.win.getYSize()/2)
    
img.setScale(iH.getXSize(),1,iH.getYSize())
    
img.setTransparency(TransparencyAttrib.MAlpha)    
    return 
img

class Game(DirectObject):
    
def __init__(self):
        
base.setBackgroundColor(0.22,0.22,0.22)
        
self.accept("escape",sys.exit)
        
self.title addTitle("CityMania TestWindow")
        
self.splashImg addSplashImage("logo.png")

t=Game()

#Run app
run()


?>



Gave me:
(https://www.sc4devotion.com/forums/proxy.php?request=http%3A%2F%2Fi48.tinypic.com%2F2mg2m82.jpg&hash=ca5cb218ed7a08ac6b684b7d4c8c3547b8f4d91d)

Now, when power of 2 is turned off (textures-power-2 none):
(https://www.sc4devotion.com/forums/proxy.php?request=http%3A%2F%2Fi45.tinypic.com%2F2wpt6vn.jpg&hash=71443bb1a979f159ed9fd2ef4c77a90615240022)
It looks more like it, but still blurry...

I devided the scale.. (god may know why it is still scaled up)
img.setScale(iH.getXSize() / 2,1,iH.getYSize() / 2)
and got this
(https://www.sc4devotion.com/forums/proxy.php?request=http%3A%2F%2Fi45.tinypic.com%2F14ax9mo.jpg&hash=2ea0a077a6d03ea8e58c56653b73dd45e27e02de)
Now this is 'allmost' there, but notice, its STILL FREAKING BLURRY.. and WHY do i have to devide the original width/height of the image that i got from PNMImageHeader()

its a battlefield here, why is it SO DAMN HARD to just render a normal 2d picture to the screen in panda, in all other engines i did this in just 2 minutes... here i am.. : DAY 2

the original image looks like this sharp:
(https://www.sc4devotion.com/forums/proxy.php?request=http%3A%2F%2Fi49.tinypic.com%2F2vuaeyh.jpg&hash=54f57a85bc7a054118c738e9c3738b4721bdb229)


Croxis, do you have an example of a 'well' rendered pic.. i mean.. this is rubbish
Title: Re: Panda3D Specific Help (learning)
Post by: croxis on January 24, 2010, 09:33:50 AM
It would help if I actually had the pic to work with. Could you attach it?
Title: Re: Panda3D Specific Help (learning)
Post by: Nique on January 24, 2010, 09:52:20 AM
http://dl.dropbox.com/u/552137/CityMania/Temp/logo.png
Title: Re: Panda3D Specific Help (learning)
Post by: croxis on January 24, 2010, 10:03:10 AM
from pandac.PandaModules import loadPrcFileData
loadPrcFileData("", """   
    window-title CityMania
    fullscreen 0
    win-size 1024 768
    cursor-hidden 1
    sync-video 0
    frame-rate-meter-update-interval 0.5
    show-frame-rate-meter 1
""")

import direct.directbase.DirectStart
from pandac.PandaModules import TextNode,PNMImageHeader,Filename
from pandac.PandaModules import TransparencyAttrib
from direct.showbase.DirectObject import DirectObject
from direct.gui.OnscreenText import OnscreenText
from direct.gui.OnscreenImage import OnscreenImage

import sys
font = loader.loadFont("cmss12")

# Function to put title on the screen.
def addTitle(text):
    return OnscreenText(text=text, style=1, fg=(1,1,1,1), font = font,
                pos=(1,-0.8), align=TextNode.ARight, scale = .07)

# Function to draw the splash
def addSplashImage(image):
    iH=PNMImageHeader()
    iH.readHeader(Filename(image))
    img=OnscreenImage(image = image, parent = pixel2d)
    img.setPos(base.win.getXSize()/2,0,0-base.win.getYSize()/2)
    img.setScale(iH.getXSize()/2,1,iH.getYSize()/2)
    img.setTransparency(TransparencyAttrib.MAlpha)   
    return img

class Game(DirectObject):
    def __init__(self):
        base.setBackgroundColor(0.22,0.22,0.22)
        self.accept("escape",sys.exit)
        self.title = addTitle("CityMania TestWindow")
        self.splashImg = addSplashImage("logo.png")

t=Game()

#Run app
run()