• 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
viper110110

Loading PNG files

11 posts in this topic

I have searched google and I can't seem to find anything relevant. I am trying to load simple PNG images into my directx program. I have DDS images working and they become ID3D11ShaderResourceView when loaded. How can I load PNGs?

 

I am targeting the windows app store and D3D 11.1, but I would also prefer something more backwards compatible with windows 7.

0

Share this post


Link to post
Share on other sites

Excuse my ignorance (I never had the opportunity to use D3D11 since I'm stuck with XP for the time being), but wouldn't there be a D3DX function that loads various texture formats including .png files?  I know it's good not to rely on D3DX when possible either way.

 

Shogun.

0

Share this post


Link to post
Share on other sites

Excuse my ignorance (I never had the opportunity to use D3D11 since I'm stuck with XP for the time being), but wouldn't there be a D3DX function that loads various texture formats including .png files?  I know it's good not to rely on D3DX when possible either way.

 

Shogun.

D3DX11CreateTextureFromFile  

 

However it has been depreciated in windows 8 and therefore the future.  Might as well learn the 6 or 7 lines it takes to load image data using FreeImage, and the few more to send it into directx.  This allows you future proof and you could switch to openGL as well if you wanted.

 

Also rolling your own .bmp and/or .tga loader is a piece of cake if you can find the right header info for your image exporter.  This will be a great learning experience, and as long as you are just learning and/or using small projects the extra size of the image files won't really matter.

Edited by EddieV223
0

Share this post


Link to post
Share on other sites

Excuse my ignorance (I never had the opportunity to use D3D11 since I'm stuck with XP for the time being), but wouldn't there be a D3DX function that loads various texture formats including .png files?  I know it's good not to rely on D3DX when possible either way.

 

Shogun.

D3DX11CreateTextureFromFile  

 

However it has been depreciated in windows 8 and therefore the future.  Might as well learn the 6 or 7 lines it takes to load image data using FreeImage, and the few more to send it into directx.  This allows you future proof and you could switch to openGL as well if you wanted.

 

Ah, that makes sense.  Writing your own image loader or using an open source one has always been my choice for portability and such, especially when working with consoles (those of us who get that far).

 

Shogun.

0

Share this post


Link to post
Share on other sites



Excuse my ignorance (I never had the opportunity to use D3D11 since I'm stuck with XP for the time being), but wouldn't there be a D3DX function that loads various texture formats including .png files?  I know it's good not to rely on D3DX when possible either way.
 
Shogun.

D3DX11CreateTextureFromFile  
 
However it has been depreciated in windows 8 and therefore the future.  Might as well learn the 6 or 7 lines it takes to load image data using FreeImage, and the few more to send it into directx.  This allows you future proof and you could switch to openGL as well if you wanted.


 
Ah, that makes sense.  Writing your own image loader or using an open source one has always been my choice for portability and such, especially when working with consoles (those of us who get that far).
 
Shogun.


yep, agreed.

though funny is I have usually written my own loaders (and other code as well), but admitting to this is one of those things which often causes people to start making accusations of "reinventing the wheel" and "making a standard of non-standard" and so on.

but, I am not really afraid of writing my own code, and consider it a reasonable tradeoff to avoid the annoyance of having lots of external dependencies (more so when targeting multiple OS's is involved).

granted, not all file-formats are equally simple, like it is a bit simpler to write a loader for something like TGA or BMP than for something like PNG, or JPEG (*1).

ultimately, there is little really "special" about file-formats, mostly just specific ways of representing various kinds of data, and code generally doesn't really care whose code generates or processes the data, so long as it basically matches the expected format.


*1: for example, TGA and BMP are basically a header followed by a glob of raw pixel data (may be RLE compressed for TGA though).
in contrast, PNG is a TLV format (sort of like a WAV or an AVI), with data-lumps for headers and image data, and with the image data stored using Deflate compression and with per-scanline filtering and similar. and, JPEG is a beast not easily explained in a short summary (basically, it is a stream of escape-coded markers representing headers and image-data, which consists mostly of Huffman-compressed DCT blocks representing typically 3 planes in the YCbCr colorspace, ...). (worse yet is video codecs...).

but, usually, most of this complexity has its reasons (such as smaller file-sizes, ...), and by playing around with things, one may discover why things are the way they are.

as far as complexity goes, PNG isn't really all that bad though. the most complicated bit is probably the Deflate compression, but this part is (usually) handled by Zlib, unless of course one also goes and writes their own Deflate code (...).

as in everything, there are pros and cons involved...
1

Share this post


Link to post
Share on other sites

If you're feeling like doing it yourself, you can have a look at the PNG format specification.It'll probably take some time to familiarize yourself with it, but the documentation appears exhaustive.

0

Share this post


Link to post
Share on other sites

I have now loaded the png file using stb_image.c but the image is not showing.

 

int x, y, n;
	unsigned char *data = stbi_load(charFilename, &x, &y, &n, 0);

	D3D11_TEXTURE2D_DESC desc;
	desc.Width = x;
	desc.Height = y;
	desc.MipLevels = 1;
	desc.ArraySize = 1;
	desc.Format = DXGI_FORMAT_R8G8B8A8_UINT;
	desc.SampleDesc.Count = 1;
	desc.SampleDesc.Quality = 0;
	desc.Usage = D3D11_USAGE_DEFAULT;
	desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
	desc.CPUAccessFlags = 0;
	desc.MiscFlags = 0;

	D3D11_SUBRESOURCE_DATA subres;
	subres.pSysMem = data;
	subres.SysMemPitch = x * n;
	subres.SysMemSlicePitch = 0;

	ID3D11Texture2D *texture2D = 0;

	HRESULT result = device->CreateTexture2D(&desc, &subres, &texture2D);
	if (FAILED(result))
	{
		DebugConsole::writeLine("Failed to create Texture2D");
	}

	result = device->CreateShaderResourceView(texture2D, NULL, &m_texture);
	if (FAILED(result))
	{
		DebugConsole::writeLine("Failed to create resource view");
	}

I have checked the HRESULT of both calls and they are both S_OK. I have also checked the filename and it is correct. If I change the extension to .dds (I have both files in the directory) then it works using the dds loading code (it checks for the .dds extension). Have I made a small mistake or am I going at it all wrong?


 

0

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