Jump to content
  • Advertisement
Sign in to follow this  
Makoy

Loading a texture and loading a sprite using directx9

This topic is 4999 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello! I would like to ask what's the difference between loading a texture and loading a sprite? thank you very much.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Makoy
hello! I would like to ask what's the difference between loading a texture and loading a sprite? thank you very much.


A sprite is an object, a texture is only an image attached to this object. DX can only draw 3d objects. a sprite is a rectangle and you can load a texture on it.

Shortly: You can't render a texture, you can only insert a texture on a sprite and render the sprite.

init()
{
D3DXCreateSprite( m_pd3dDevice, &m_pSprite );
D3DXCreateTextureFromFile(m_pd3dDevice, L"image.jpg", &m_pTexture);
}

render()
{
m_pSprite->Begin();
m_pSprite->Draw(m_pTexture, &r1, NULL, NULL, 0xFFFFFFFF);
m_pSprite->End();
}

Share this post


Link to post
Share on other sites
A sprite is a Direct3D object that provides a set of interfaces to enable you to display 2D images. So it is a mechanism, a set of operations if you like. A texture is pure data that describes a 2D image.

Share this post


Link to post
Share on other sites
That clears my confusion thanks to tiger for the wonderful piece of code and to trip99! :) btw tiger, about the piece of code, should I insert it to winmain or should I call a new function to it?

Share this post


Link to post
Share on other sites
Quote:
Original post by Makoy
about the piece of code, should I insert it to winmain or should I call a new function to it?


How you want :D
You must initialise them only 1 time, if you write a game it is better if you write a class.

Share this post


Link to post
Share on other sites
Tiger54 Can I have an example code. Since I'm new to this whole sprite/texture thing I just need some good code to start with. thanks a lot!

Share this post


Link to post
Share on other sites
Quote:
Original post by Makoy
Tiger54 Can I have an example code. Since I'm new to this whole sprite/texture thing I just need some good code to start with. thanks a lot!


file.h


#pragma once
#ifndef CMAINFRAME_H
#define CMAINFRAME_H

#include "dxstdafx.h"

class CMainFrame
{
protected:
IDirect3DTexture9* m_pTitleTexture;
ID3DXSprite* m_pTitleSprite;

IDirect3DDevice9* m_pd3dDevice;

public:
CMainFrame(IDirect3DDevice9*);
~CMainFrame() {}

void Render( void );
HRESULT RestoreDeviceObjects( void );
HRESULT InvalidateDeviceObjects(void);
HRESULT Release(void);

};



file.cpp

#include "MainFrame.h"

CMainFrame::CMainFrame(IDirect3DDevice9* pDevice)
{
m_pd3dDevice = pDevice;
m_pTitleSprite = NULL;

D3DSURFACE_DESC desc;
desc = *DXUTGetBackBufferSurfaceDesc();

D3DXCreateSprite( m_pd3dDevice, &m_pTitleSprite );
D3DXCreateTextureFromFile(m_pd3dDevice, L"sball.png", &m_pTitleTexture);

}

void CMainFrame::Render( void )
{

const RECT r1 = {0,0,500,200};
m_pTitleSprite->Begin(D3DXSPRITE_ALPHABLEND);
m_pTitleSprite->Draw(m_pTitleTexture, &r1, NULL, NULL, 0xFFFFFFFF);
m_pTitleSprite->End();

}

HRESULT CMainFrame::RestoreDeviceObjects( void )
{
if(m_pTitleSprite)
m_pTitleSprite->OnResetDevice();
return TRUE;
}

HRESULT CMainFrame::InvalidateDeviceObjects(void)
{
if( m_pTitleSprite )
m_pTitleSprite->OnLostDevice();
return TRUE;
}

HRESULT CMainFrame::Release(void)
{
SAFE_RELEASE( m_pTitleSprite);
SAFE_RELEASE( m_pTitleTexture );
return TRUE;
}



Hope this is enough :D

Edited by Coder: Source tags instead of code tags

[Edited by - Coder on November 10, 2004 12:01:33 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!