April 20, 2024, 04:43:09 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Is there any way to embed media for 3D sprites?

Started by Kale, November 07, 2006, 03:45:13 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Kale

Is there any way to embed media for 3D sprites? In other words can i embed PNG files in my exe to use in a screensaver instead of loading 3dsprites from external sources?

Ionic Wind Support Team

Yes.  Just save it in resources as a scalable image, or a custom data type, and specify the resource ID instead of the filename when using the sprite Load method.   I haven't tried it with PNG images yet but is should work.
Ionic Wind Support Team

Kale

Hmmm... i've tried that and with no success. :-\

I added the resource as an 'Scalable Image' and specified the ID as 'ID_LOGO'.

I then tried to load the sprite using this code:

CurrentSprite->Load(Screen, ID_LOGO, 128, 128, 1, 0);

Outcome: undefined variable - ID_LOGO

Parker

You need to define that the same as you did in the resource file. The compiler doesn't read resource files.

Ionic Wind Support Team

"ID_LOGO"

It's a string.  Unless you're editing the resource file manually to create a resource define.

Ionic Wind Support Team

Kale

Quote from: Paul Turley on November 08, 2006, 04:23:02 PM
"ID_LOGO"
It's a string.

Ok, i tried that but got a program crash and an error: "CreateNewTexture(): Couldn't load texture ID_LOGO". :-\


#AutoDefine "off"
#include "Application.inc"

//Constructor
Application::Application()
{
//Initialise Properties
CurrentDirectory = GetStartPath();

//Setup Screen
Screen.CreateFullScreen(Desktop.GetWidth(), Desktop.GetHeight(), Desktop.GetBitDepth(), True);
DirectInput.Init(Screen);
Camera.Create(Screen);

//Initialise Sprites
Sprites = new(CPointerList, 1);
Sprites->Create();
}

//Destructor
Application::_Application()
{
    for(pointer Position = Sprites->GetFirst(); Position <> 0; Position = Sprites->GetNext(Position))
    {
         C3DSprite *CurrentSprite = Sprites->GetData(Position);
         delete CurrentSprite;
    }
    Sprites->RemoveAll(false);
    delete Sprites;
}

//Initialise all sprite data
Application::InitialiseSprites(int NumberOfSprites)
{
for(int x = 0; x < NumberOfSprites; x++)
{
Sprites->Add(New(C3DSprite, 1));
}

for(pointer Position = Sprites->GetFirst(); Position <> 0; Position = Sprites->GetNext(Position))
{
C3DSprite *CurrentSprite = Sprites->GetData(Position);
CurrentSprite->Load(Screen, "ID_LOGO", 128, 128, 1, 0);
CurrentSprite->SetModulateColor(RGBA(255, 255, 255, 128));
CurrentSprite->SetPosition(Rand(Desktop.GetWidth()) - 64, Rand(Desktop.GetHeight()) - 64);
}
}

//Draw the sprites to the screen
Application::DrawSprites()
{
for(pointer Position = Sprites->GetFirst(); Position <> 0; Position = Sprites->GetNext(Position))
{
C3DSprite *CurrentSprite = Sprites->GetData(Position);
CurrentSprite->Draw();
}
}

//Update the sprite positions on screen
Application::UpdateSpritePositions(float Step)
{
for(pointer Position = Sprites->GetFirst(); Position <> 0; Position = Sprites->GetNext(Position))
{
C3DSprite *CurrentSprite = Sprites->GetData(Position);
VECTOR2 PositionOnScreen = CurrentSprite->GetPosition();
//PositionOnScreen.y = PositionOnScreen.y + Step);
if (PositionOnScreen.y > Desktop.GetHeight())
{
PositionOnScreen.y = -128;
}
CurrentSprite->SetPosition(PositionOnScreen.x, PositionOnScreen.y);
}
}

//Run the app
Application::Run()
{

while (!DirectInput.KeyDown(DIK_ESCAPE))
{
Screen.Clear(RGBA(32, 23, 30, 255));
Screen.BeginScene(Camera);

Screen.Begin2D();
DrawSprites();
UpdateSpritePositions(0.1f);
Screen.End2D();

Screen.RenderScene();
}
}

Ionic Wind Support Team

Like I mentioned I haven't tried it with a png saved as a resource.  Use a bitmap first to see if the code works.
Ionic Wind Support Team

J B Wood (Zumwalt)


C3DSprite GUI;
C3DObject scene;
C3DMesh gunship;
C3DMesh BG1;
C3DLight light;
s.CreateWindowed(0,0,800,600,AWS_CAPTION|AWS_VISIBLE|AWS_SIZE,0,"Gunship Rescue A01 - By Zumwalt",NULL,true);
c.Create(s);
c.Position(0,0,-8);
c.Orient(0,0,1,0,1,0);
c.SetBackPlane(500);
GUI.Load(s,GetStartPath() + "media\\expander.png",650,542);


Snippet to load from file.. going to switch this to a resource in a few to see if I can make it work.

J B Wood (Zumwalt)

To answer your question, yes you can use either bmp or png.
Step 1, click on Resource, then Add
Change type to Custom, type in png for custom type
Browse out to your png file and select it and click on Add
Finally, this is the easiest part,


GUI.Load(s,"expander.png",650,542);


This is the file name that is stored as a resource.