onscreen image

im trying to put an onscreen image into my game. ive basically tried everything and searched the forums and nothing works. can anyone give me a sample of how to load an image from my folder and put it on my screen? if you could include everything needed, including what to import that would be great!

Onscreen image? You mean just display a 2-dimensional picture? I don’t think panda can do that directly. You’ll have to apply it as a texture to something. A card parented to aspect2d would probably work.

http://panda3d.org/manual/index.php/OnscreenImage

my code looks like this

from direct.gui.OnscreenImage import OnscreenImage
imageObject = OnscreenImage(image = ‘loser.jpg’, pos = (-0.5, 0, 0.02))
imageObject.setImage(‘loser.jpg’)

i get an error while loading the game that i need a texture or something.

I haven’t used OnScreenImage, but I see a couple possible problems based on the page drwr linked to.

First, you don’t need to call setImage(). That’s only for changing the image, where the original image to use is set in the OnscreenImage constructor.

Second, are you using the correct path to “loser.jpg”?

Please post the full error message you get, otherwise it’s difficult to help.

hey guys. any idea how i can implement the onscreenimage thing using cxx? i cant seem to find their header file relating to the onscreenimage from python.

playnice, there is no OnscreenImage in C++, However, you can load the image as model and reparent it to aspect2d or render2d.

interesting idea… but i’m really new to panda3d and i’m doing a school’s project. the requirements for this project are that i need to use c++ to code this thing up… so if you dont mind could you help me out with this? i read the python code where you

white = loader.loadTexture('Textures/white.jpg')

to load a texture if i’m not wrong… but how do i load it in c++? and after which how do i apply this texture to a model like u mentioned?
thanks anyway whether you hav time to help or not… really appreciate it. :slight_smile:

This ought to work, though I didnt test it:

PT(Texture) white;
white = new Texture();
white.read(Filename("Textures/white.jpg"));

I am shocked this is not documented, I’ll go write a manual page for it.

EDIT: Done!

oh. thanks alot!

Although that does work to load a texture, a better way is to go through the TexturePool. The TexturePool automatically searches along the model path and also combines multiple load requests to return the same Texture object:

PT(Texture) white;
white = TexturePool::load_texture("Textures/white.jpg");

David

ok thanks :slight_smile:

Hi!
I am creating a simple game in Panda3D. What I want is to show some basic instructions for the game using images(3-4) images and shift the images using the ‘Right Arrow Key’. After the final image is displayed, the game should run.
Can you please help me how to do this?

Use onScreenImage to display the picture:
panda3d.org/manual/index.php/OnscreenImage

And use base.accept to read the keys from the keyboard:
panda3d.org/manual/index.php … rd_Support

Basically you will “bind” a key to a function/method with base.accept, so all you need to do is write a function that changes the picture (using setImage) and then use base.accept to call it when the user presses the key.