IonicWind Software

Aurora Compiler => 3D Graphics => Topic started by: Kale on November 07, 2006, 03:45:13 PM

Title: Is there any way to embed media for 3D sprites?
Post by: Kale on November 07, 2006, 03:45:13 PM
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?
Title: Re: Is there any way to embed media for 3D sprites?
Post by: Ionic Wind Support Team on November 07, 2006, 05:15:46 PM
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.
Title: Re: Is there any way to embed media for 3D sprites?
Post by: Kale on November 08, 2006, 04:05:18 PM
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
Title: Re: Is there any way to embed media for 3D sprites?
Post by: Parker on November 08, 2006, 04:18:26 PM
You need to define that the same as you did in the resource file. The compiler doesn't read resource files.
Title: Re: Is there any way to embed media for 3D sprites?
Post by: Ionic Wind Support Team on November 08, 2006, 04:23:02 PM
"ID_LOGO"

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

Title: Re: Is there any way to embed media for 3D sprites?
Post by: Kale on November 16, 2006, 04:49:07 PM
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();
}
}
Title: Re: Is there any way to embed media for 3D sprites?
Post by: Ionic Wind Support Team on November 16, 2006, 05:25:05 PM
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.
Title: Re: Is there any way to embed media for 3D sprites?
Post by: J B Wood (Zumwalt) on November 16, 2006, 06:42:21 PM

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.
Title: Re: Is there any way to embed media for 3D sprites?
Post by: J B Wood (Zumwalt) on November 16, 2006, 06:55:19 PM
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.