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

Need help using D3DXCreateTextureFromFileEx

2 posts in this topic

Been beating my head against the wall for the last few day and so I am hoping someone can help. I am relatively new to programming in C++ (been programming in PHP [and other languages] for several years) and in the last few months I started playing around with DirectX.

First, the original code I am trying to modify, and that does work (I think most of it came from a tutorial).
[CODE]
LPDIRECT3DTEXTURE9 Dx_Manager::GetTexture(char* filename)
{
for (int i = 0; i < MAX_TEXTURES; ++i)
{
if (!d3d_texture[i].texture && d3d_texture[i].inuse)
{
continue;
}
d3d_texture[i].inuse = true;
d3d_texture[i].filename = filename;

D3DXCreateTextureFromFileA(d3d_device, d3d_texture[i].filename, &d3d_texture[i].texture);

return d3d_texture[i].texture;
}
return NULL;
}
[/CODE]
Apparently "D3DXCreateTextureFromFileA" insists that graphics be sized to the power of 2 (2, 4, 8, 16, 32, etc), and while it can be dealt with, by making unused parts of the graphic transparent, I can foresee problems with scaling as well as interactive graphics elements overlapping each other. And on top of that there is the wasted memory for the larger than necessary graphic.

So I am thinking that using D3DXCreateTextureFromFileEx would be better. Here is what, I think, I need to replace line 12 (above) with:
[CODE]
D3DXIMAGE_INFO info;
HRESULT result = D3DXGetImageInfoFromFile(filename.c_str(), &info);
if (result != D3D_OK)
{
return NULL;
}

D3DXCreateTextureFromFileEx(
d3d_device,
filename.c_str(),
info.Width,
info.Height,
1,
D3DPOOL_DEFAULT,
D3DFMT_UNKNOWN,
D3DPOOL_DEFAULT,
D3DX_DEFAULT,
D3DX_DEFAULT,
0xFF000000,
&info,
NULL,
&d3d_texture[i].texture
);
[/CODE]
But in both the places that I use "filename.c_str()" I get this error
[CODE]error C2228: left of '.c_str' must have class/struct/union[/CODE]
If take off the ".c_str()" I get errors similar to this
[CODE]error C2664: 'D3DXGetImageInfoFromFileW' : cannot convert parameter 1 from 'char *' to 'LPCWSTR'[/CODE]
I have tried changing the type of "filename" from "char*" to "WCHAR*", "TCHAR", "LPCWSTR", "LPCSTR" as well as looked up ways to convert "char*" to other types and all have failed to work. And really I am not even sure changing the type definition is the solution to the problem.

Any direction on this would be much appreciated.

Also in researching a solution, I read in one place that "D3DXCreateTextureFromFileA" is easier on graphics cards than "D3DXCreateTextureFromFileEx". So if there is a completely different approach I should be looking at let me know. Edited by Krik
0

Share this post


Link to post
Share on other sites
Since filename is a char*, why do you append .c_str()? It's not a std::string.

For the function call, try D3DXCreateTextureFromFileExA to use the ASCII version.
1

Share this post


Link to post
Share on other sites
[quote]Since filename is a char*, why do you append .c_str()? It's not a std::string.[/quote]
I had tried removing it but had ran into other problems, so I wasn't sure it was the answer, just didn't have the other part of the solution. I would have never thought appending an "A" to the function would fix my code. For all the searching I did never once saw that suggested.

I do have some followup questions based on that answer.

In researching a solution for my problem I saw several places that recomended that Unicode (W) be used instead of ANSI (A). Am I understanding that correctly? It does appears that if I use "WCHAR*" instead of "char*" and append a "W" to the functions it works also. So which is the recommended route?

Also I appended the "A" (also tried "W") to both the "D3DXGetImageInfoFromFile" and the "D3DXCreateTextureFromFileEx" functions. Is it safe to assume that "A" (and "W") can be appened to most of the DirectX functions?
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