• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
SkyRaign

Using bitmap resources (*.rc) in Visual Studio 2010

8 posts in this topic

Hi, I am trying to find a way to use bitmaps in my game without having to load files from the hard disk at runtime.  I can include bitmap files into a *.rc, but I have searched on the web for hours and cannot find a way to access the images from code.  Nothing I have tried has worked.

 

This is the "name" that my file "TryRes.rc" has given my bitmap:

 

IDB_BITMAP1

 

This identified throws a compiler error, saying it is "undeclared". 

 

I am using DirectX10 for graphics; my intention is to use "CreateTextureFromResource" once I am able to access the images...unless someone knows a better way to do this.  The idea is to be able to port the executable over to another computer and still be able to run it without all the extra graphics files.

0

Share this post


Link to post
Share on other sites

I think it would help the reader if you provided some specific code or compling errors ;) It's quite hard right now to see the problem.

0

Share this post


Link to post
Share on other sites
Hi, I am trying to find a way to use bitmaps in my game without having to load files from the hard disk at runtime.  I can include bitmap files into a *.rc, but I have searched on the web for hours and cannot find a way to access the images from code.  Nothing I have tried has worked.

 

This is the "name" that my file "TryRes.rc" has given my bitmap:

 

IDB_BITMAP1

 

This identified throws a compiler error, saying it is "undeclared". 

 

I am using DirectX10 for graphics; my intention is to use "CreateTextureFromResource" once I am able to access the images...unless someone knows a better way to do this.  The idea is to be able to port the executable over to another computer and still be able to run it without all the extra graphics files.

 

Maybe this could be useful

 

http://www.winprog.org/tutorial/resources.html

http://msdn.microsoft.com/en-us/library/cc194804.aspx

 

But using bitmaps instead of compressed formats are going to increase the game size, right?

0

Share this post


Link to post
Share on other sites
Ravnock:

You are undoubtedly right about the game size but right now I am just trying to learn how to use the resources. This is SOOOOOOO frustrating. I looked at the links you posted and followed http://www.winprog.o.../resources.html the best I could (using "BITMAP" as a resource type instead of "ICON") but it did not work.

Nick C.:

Noting the above, this is the result of what I get:

In my resource file, "resource3.h"
#define IDB_BITMAP1 101

In my main file:

#include "resource3.h"
~
~
~
~
IDB_BITMAP1 BITMAP "Image.bmp";

^^^these are the compiler errors that I get
1>DirectX10 Exp Part 2.cpp(214): error C2146: syntax error : missing ';' before identifier 'BITMAP'
1>DirectX10 Exp Part 2.cpp(214): error C2143: syntax error : missing ';' before 'string'1>DirectX10 Exp Part 2.cpp(214): error C2275: 'BITMAP' : illegal use of this type as an expression

I haven't even gotten to creating textures yet. Bottom line is I want to be able to use these bitmap resources to create textures through Direct3D10 functionality. This seems like such a simple issue but I cannot find ANY helpful documentation on this! Edited by SkyRaign
0

Share this post


Link to post
Share on other sites

Ok so I have seemingly made some progress.  Here is what the code looks like now:

 

In my resource file, "resource3.h":

 

#define IDB_BITMAP1 101

 

In my main file:

 

#include "resource3.h"

 

hResult = D3DX10CreateTextureFromResource(pD3DDevice,0,MAKEINTRESOURCE(IDB_BITMAP1),0,0,&pD3D10Resource,0);

 

This example compiles, but the hResult always returns as "E_FAIL".  Conveniently enough, this is the "unspecified" code.  Some of the

tutorials I have read have indicated coding things this way but it just isn't working.  Any thoughts?

0

Share this post


Link to post
Share on other sites
Ok so I have seemingly made some progress.  Here is what the code looks like now:

 

In my resource file, "resource3.h":

 

#define IDB_BITMAP1 101

 

In my main file:

 

#include "resource3.h"

 

Ok so I have seemingly made some progress.  Here is what the code looks like now:

 

In my resource file, "resource3.h":

 

#define IDB_BITMAP1 101

 

In my main file:

 

#include "resource3.h"

 

hResult = D3DX10CreateTextureFromResource(pD3DDevice,0,MAKEINTRESOURCE(IDB_BITMAP1),0,0,&pD3D10Resource,0);

 

This example compiles, but the hResult always returns as "E_FAIL".  Conveniently enough, this is the "unspecified" code.  Some of the

tutorials I have read have indicated coding things this way but it just isn't working.  Any thoughts?

 

 

hResult = D3DX10CreateTextureFromResource(pD3DDevice,0,MAKEINTRESOURCE(IDB_BITMAP1),0,0,&pD3D10Resource,0);

 

This example compiles, but the hResult always returns as "E_FAIL".  Conveniently enough, this is the "unspecified" code.  Some of the

tutorials I have read have indicated coding things this way but it just isn't working.  Any thoughts?

 

But D3DX10CreateTextureFromResource is expecting a pointer to the path string, I think you need D3DX10CreateTextureFromMemory. The question is: how to get the bitmap defined in the resource file as a pointer to the memory?

 

I think this thread could be useful for you:

 

http://social.msdn.microsoft.com/forums/en-US/vcgeneral/thread/07318565-7733-4c3d-b885-85dfeaa9b73b

 

Some msdn doc:

http://msdn.microsoft.com/en-us/library/windows/desktop/dd145033(v=vs.85).aspx

http://msdn.microsoft.com/en-us/library/windows/desktop/aa380680(v=vs.85).aspx

0

Share this post


Link to post
Share on other sites

Well Ravnock I looked into the links you provided.  Having investigated further I still cannot see why D3DX10CreateTextureFromResource is not working.  The second parameter should be a handle to the instance creating it, which in my case should be the .exe.  Having made that change it still does not work.

 

hResult=D3DX10CreateTextureFromResource(pD3DDevice,GetModuleHandle(0), MAKEINTRESOURCE(IDB_BITMAP1), 0 , 0 ,  &pD3D10Resource , 0 );

 

 

I tried using D3DX10CreateTextureFromMemory as follows:

 

HBITMAP hBit = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP1));

hResult=D3DX10CreateTextureFromMemory(pD3DDevice,hBit, 0 , 0 , 0 , &pD3D10Resource , 0 );

 

It did not work, even if I cast hBit to "HMODULE".  LoadBitmap() -->DOES<-- return a valid pointer to a bitmap, but now I am left with how to access it through Direct3D10.  The second paramter to the function call is an LPCVOID pointer but I can't seem to make it work for me.  Still, all I am getting here is E_FAIL in the hResult return value.

 

Bout ready to pull the hair out of my head here.  What on earth could I be missing?  Is it maybe a linker issue?

0

Share this post


Link to post
Share on other sites
Well Ravnock I looked into the links you provided.  Having investigated further I still cannot see why D3DX10CreateTextureFromResource is not working.  The second parameter should be a handle to the instance creating it, which in my case should be the .exe.  Having made that change it still does not work.

 

hResult=D3DX10CreateTextureFromResource(pD3DDevice,GetModuleHandle(0), MAKEINTRESOURCE(IDB_BITMAP1), 0 , 0 ,  &pD3D10Resource , 0 );

 

 

I tried using D3DX10CreateTextureFromMemory as follows:

 

HBITMAP hBit = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP1));

hResult=D3DX10CreateTextureFromMemory(pD3DDevice,hBit, 0 , 0 , 0 , &pD3D10Resource , 0 );

 

It did not work, even if I cast hBit to "HMODULE".  LoadBitmap() -->DOES<-- return a valid pointer to a bitmap, but now I am left with how to access it through Direct3D10.  The second paramter to the function call is an LPCVOID pointer but I can't seem to make it work for me.  Still, all I am getting here is E_FAIL in the hResult return value.

 

Bout ready to pull the hair out of my head here.  What on earth could I be missing?  Is it maybe a linker issue?

 

Sorry :( I only have a few experience with these resource files, I have only used them to load icons and things like that.

 

I guess some guy from the msdn forum must know this. Maybe not (LOL)

0

Share this post


Link to post
Share on other sites

These functions don't like BITMAP type resource data, only RCDATA type resource data.

 

Change the

IDB_BITMAP1 BITMAP "Image.bmp";

 

bit in the rc file to

IDB_BITMAP1 RCDATA "Image.bmp";
 

The second stores a copy of the file as is; the first one strips off the BITMAPFILEHEADER from the start of the file. The WIC functions the D3DX functions use (specifically CreateDecoderFromStream) seem to require that header be present or they fail. It ain't there, so they fail which make the D3DX function fail.

1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0