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

D3DXSPRITE problem - wrongly scaled?

8 posts in this topic

Hi,

I am using D3D9 for rendering some simple things, a movie, as the backmost layer, then on top of that some text messages, and now wanted to add some buttons to that.

Before adding the buttons everything seemed to have worked fine, and I was using a [color=#2A2A2A]D3DXSPRITE [/color]for the text as well (D3DXFONT), now I am loading some graphics for the buttons, but they seem to be scaled to something like 1.2 of its original size (in my test window I centered the graphic, but it being too big it just doesnt fit well, for example the client area is 640x360, the graphic is 440, so i expect 100 pixel on left and right, left side is fine [I took screenshot and "counted" the pixels in photoshop], but on the right there is only about 20 pixels)

My rendering code is very simple (I am omitting error checks etc for brevity)

[color=#0000cd]// initially viewport was set to width/height of client area[/color]

[color=#0000cd]// clear device[/color]
[color=#0000cd]m_d3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_STENCIL|D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0,0,0,0), 1.0f, 0 );[/color]

[color=#0000cd]// begin scene[/color]
[color=#0000cd]m_d3dDevice->BeginScene();[/color]

[color=#0000cd]// render movie surface (just two triangles to which the movie is rendered)[/color]

[color=#0000cd]m_d3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,false);[/color]
[color=#0000cd]m_d3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR ); // bilinear filtering[/color]
[color=#0000cd]m_d3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR ); // bilinear filtering[/color]
[color=#0000cd]m_d3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );[/color]
[color=#0000cd]m_d3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); //Ignored[/color]
[color=#0000cd]m_d3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );[/color]
[color=#0000cd]m_d3dDevice->SetTexture( 0, m_movieTexture );[/color]
[color=#0000cd]m_d3dDevice->SetStreamSource(0, m_displayPlaneVertexBuffer, 0, sizeof(Vertex));[/color]
[color=#0000cd]m_d3dDevice->SetFVF(Vertex::FVF_Flags);[/color]
[color=#0000cd]m_d3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);[/color]

[color=#0000cd]// render sprites[/color]
[color=#0000cd]m_sprite->Begin(D3DXSPRITE_ALPHABLEND | D3DXSPRITE_SORT_TEXTURE | D3DXSPRITE_DO_NOT_ADDREF_TEXTURE);[/color]

[color=#0000cd]// text drop shadow[/color]

[color=#0000cd]m_font->DrawText( m_playerSprite, m_currentMessage.c_str(), m_currentMessage.size(), [/color]
[color=#0000cd]&m_playerFontRectDropShadow, DT_RIGHT|DT_TOP|DT_NOCLIP, m_playerFontColorDropShadow );[/color]
[color=#0000cd]// text[/color]
[color=#0000cd]m_font->DrawText( m_playerSprite, m_currentMessage.c_str(), m_currentMessage.size(), [/color]
[color=#0000cd]&m_playerFontRect, DT_RIGHT|DT_TOP|DT_NOCLIP, m_playerFontColorMessage ) );[/color]

[color=#0000cd]// control object[/color]
[color=#0000cd]m_sprite->Draw( m_texture, 0, 0, &m_vecPos, 0xFFFFFFFF ); // draws a few objects like this [/color]

[color=#0000cd]m_sprite->End()[/color]


[color=#0000cd]// end scene[/color]
[color=#0000cd]m_d3dDevice->EndScene();[/color]


What did I forget to do here? Except for the control objects (play button, pause button etc which are placed on a "panel" which is about 440 pixels wide) everything seems fine, the objects are positioned where I expect them, but just too big. Btw I loaded the images using D3DXCreateTextureFromFileEx (resizing wnidow, and reacting to lost device etc works fine too).

For experimenting, I added some code to take an identity matrix and scale is down on the x/y axis to 0.75f, which then gave me the expected result for the controls (but also made the text smaller and out of position), but I don't know why I would need to scale anything. My rendering code is so simple, I just wanted to draw my 2D objects 1;1 the size they came from the file...

I am really very inexperienced in D3D, so the answer might be very simple...

thanks
Bjoern
0

Share this post


Link to post
Share on other sites
I just wanted to illustrate the size problem with a screenshot where you can see the file displayed in 100% and behind that how it is actually rendered
0

Share this post


Link to post
Share on other sites
How do you load the texture? If you're loading it with D3DXCreateTextureFromFile, then it's getting resized to be a power of two in size. You can either create it as a power of two in width and height, or use D3DXCreateTextureFromFileEx and pass D3DX_DEFAULT_NONPOW2 for the width and height parameters.
1

Share this post


Link to post
Share on other sites
Hi Steve,
thanks for your reply. I was loading already with [color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]D3DXCreateTextureFromFileEx, but I didn't set the [/left][/size][/font][/color][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]D3DX_DEFAULT_NONPOW2 flag. However I just changed my code for testing, and am checking for the size of the texture (which as you said is rounded to the next power of 2), and I am storing the size of the original image in the file - for example the buttons are 29x29 and therefore end up 32x32, which makes sense). So when I am rendering it now, I am using that rectangle (ie 0,0,29,29) as the source rectangle, however I still got the scaling problem.[/left][/size][/font][/color]




[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]The difference compared to before is that now the textures fill the size of the screen as expected, but because they are still scaled they are now also cut off. Please see the screenshot. [/left][/size][/font][/color][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]So somewhere there must still be some scaling happening. But I don't know where, because I am not setting any view matrices or anything.[/left][/size][/font][/color]
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]Hmm, I guess I must still be doing something stupid somewhere...[/left][/size][/font][/color]
0

Share this post


Link to post
Hi Steve,
thanks for your reply. I was loading already with [left]D3DXCreateTextureFromFileEx, but I didn't set the [/left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]D3DX_DEFAULT_NONPOW2 flag. However I just changed my code for testing, and am checking for the size of the texture (which as you said is rounded to the next power of 2), and I am storing the size of the original image in the file - for example the buttons are 29x29 and therefore end up 32x32, which makes sense). So when I am rendering it now, I am using that rectangle (ie 0,0,29,29) as the source rectangle, however I still got the scaling problem.[/left][/size][/font][/color]

[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]The difference compared to before is that now the textures fill the size of the screen as expected, but because they are still scaled they are now also cut off. Please see the screenshot. [/size][/font][/color][/left]
[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]So somewhere there must still be some scaling happening. But I don't know where, because I am not setting any view matrices or anything.[/size][/font][/color][/left]

[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]Hmm, I guess I must still be doing something stupid somewhere...[/size][/font][/color][/left]
0

Share this post


Link to post
Share on other sites
Here is the above mentioned screenshot, now with the source rectangle set to the size of the original image file, it just clips the parts that have been scaled up
0

Share this post


Link to post
Share on other sites
Ok, finally I understand, thanks again Steve!

It seems that D3DXCreateTextureFromFileEx not only loads the texture and fits it into an area the size of the next higher power of two (in my case my 424x69 texture would be 512x128), but it actually [b]stretches[/b] it too. My original expectation was that it puts the 424x69 image into the 512x128 texture, and the excess area would just be either zeroed out or random uninitialized values, and when I draw my sprite and pass in the image size 424x69 it would just copy that section of the original image to the screen. But seeing that it stretches the texture to fill the 512x128 texture, then it also makes sense that it cuts it off. So the D3DX_DEFAULT_NONPOW2 setting actually fixed this.

Is that what it means in the MSDN documentation by "[color=#000000]Mipmapped textures automatically have each level filled with the loaded texture. " [b]?[/b] [/color]Even though I only specified one level...

Sorry if this thread seems kinda silly and newbie-ish... but I am a newbie in this ;-) Anyway, it works now, so I can move on :-)

cheers,
Bjoern
0

Share this post


Link to post
Share on other sites
[quote name='thebjoern' timestamp='1332209045' post='4923494']
Ok, finally I understand, thanks again Steve!

It seems that D3DXCreateTextureFromFileEx not only loads the texture and fits it into an area the size of the next higher power of two (in my case my 424x69 texture would be 512x128), but it actually [b]stretches[/b] it too. My original expectation was that it puts the 424x69 image into the 512x128 texture, and the excess area would just be either zeroed out or random uninitialized values, and when I draw my sprite and pass in the image size 424x69 it would just copy that section of the original image to the screen. But seeing that it stretches the texture to fill the 512x128 texture, then it also makes sense that it cuts it off. So the D3DX_DEFAULT_NONPOW2 setting actually fixed this.

Is that what it means in the MSDN documentation by "[color=#000000]Mipmapped textures automatically have each level filled with the loaded texture. " [b]?[/b] [/color]Even though I only specified one level...[/quote]Ah yes sorry, I should have been clearer. D3DX will resize the texture according to the filter passed in the Filter parameter. You can disable the resizing by using D3DX_FILTER_NONE instead.
That particular line from the docs means that if you load a 400x200 BMP file, and specify 0 for the MipLevels parameter, then D3DX will create all the mip levels (400x200, 200x100, 100x50, 50x25, 25x12, 12x6, 6x3, 3x1, 1x1) and fill them in with resized versions of the BMP file, using the filter specified in the MipFilter patameter.

If you're really picky about compatability, it's worth noting that not all graphics cards support non-power-of-2 textures, although just about every card you'll come across does. Still, it might be worth noting if you're targetting older hardware (GeForce 2 and below for instance). The "CardCaps.pdf" file in the DirectX SDK will list what cards have the D3DPTEXTURECAPS_POW2 and/or D3DPTEXTURECAPS_NONPOW2CONDITIONAL cap bit set.
1

Share this post


Link to post
Share on other sites
Ok, got it, thanks again! Yeah, was really wondering which part made it resize it... that it was the filter wasn't that intuitive for me.... thanks!
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