[SOLVED] loading an image?

You know, this is not a bad idea. This sort of question does come up from time to time, and people who are used to pixel-based 2-d engines always seem to miss pixel-based coordinate systems in Panda. It does make a lot of sense to provide such a one for them. I think it would have to be parented to render2d, though, and maintain itself in the corner, so as to avoid the counterscaling that comes with aspect2d.

David

I myself would like this. I implemented it myself by hand (although it is broken in some ways). My issue is that I don’t want my UI to scale with resolution.

All right, I’ve just checked in base.pixel2d, where one unit corresponds to one pixel on screen.

In its coordinate system, the upperleft corner of the window is (0, 0, 0), the lowerright corner is (xsize, 0, -ysize). I had to make the Z negative because Panda uses Z-Up and not Z-down.

Does this mean in 1.7 we will be able to load resolution dependant, pixel perfect images without them getting scaled?

On the contrary. The image loading has not changed. Only the way of ‘scaling’, as you call it.
When you reparent an image to render2d, it is not scaled. In 1.7 (or in the daily snapshot) you’ll be able to reparent it to pixel2d, so that the image is counter-scaled so that the coordinate system is relative to the window, and one unit matches one pixel.
So you’ll be able to call setPos with coordinates in pixels, and setScale with coordinates in pixels. When you resize the window, the image will appear not to resize with it.

Tryed the pixel2d-thing but couldnt get it work, if i reparent an onscreenimage to pixel2d the image is not visible… tryed on windows with newest buildbot-version.

Did you position it, with setPos(x, 0, -y)? And did you scale it to the image size with setScale(width, 1, height) (every dimension in pixels)? By default the image will be 1 pixel big.

nope i dont, but that explaines all ;D
i thought that the pixel2d-thing automatic rescales the image…

so how do i get the dimensions of my image, is there something like onscreenimage.getWidth…or do i have to know the dimensions?

You can use PNMImageHeader to extract the width and height of an image, or call getXSize() / getYSize() on the texture (note that the former method gets the original size, the latter gets the nearest power-of-two size (unless configured differently).

pixel2d image has strange scale behaviour - it’s two times smaller. To display 512x512 texture I have to set scale 256x256. Is it bug or I misunderstood something ?

Hm, perhaps the quad containing your image ranges from -1 to 1, rather than 0 to 1?

Sorry but I’m using Panda since a week, so I have no idea about which quad ? I’m using just plain OnscreenImage :slight_smile:

self.image = OnscreenImage(“textures/title.png”, [400, 0, -300], None, [256, 1, 256], None, pixel2d)

and this is result:
img89.imageshack.us/i/scr02c.jpg/

[/img]

Ah, yes. Apparently OnscreenImage creates a quad of size 2.

Is it bug then ?

No. It just means that you need to use the half image size. :slight_smile:

this topic explained a lot of questions i had, thank you all. I would lock it in the frequently asked section or something so us ilquadterates can find it easier. I wish i found this thread 3 hours ago :slight_smile: