Jump to content
  • Advertisement

Funso

Member
  • Content Count

    11
  • Joined

  • Last visited

Community Reputation

122 Neutral

About Funso

  • Rank
    Member
  1. I have alot of wanrings in my code. I've got rid of half by getting rid of warnings related to deprecated code. The other half is mostly because of situations where one data type is used in place of another. Now, I know that when I have an int and am passing float data to it, that takes along time due to rounding. So using int a = (int)thatFloat; is slow. Am I right, then, in thinking the other casts are ok? For example I have some RECTs I am making for text, and I am getting warnings about passing floats into longs. I should leave those because of rounding, and just suck it up and handle the warning. Is that the best plan? Other times, I am using vectors and I need to know how many objects are in the vector. Am I ok casting from t_size to int because there isn't a slow down? I've always just gone and programmed and never really worried about casting, but this time I want to clear up that darned box of all the warnings I get, and on this occasion speed does matter. Maybe someone could point me towards an article or two on this? It's an interesting topic but google isn't helping me too much.
  2. Thanks for the input, you're right about using clamp, that helped, I was using wrap in my fx file. If I use point filtering, yes the problem goes away. Now of course if I move the camera nearer the quads, the texture looks very pixelated, but still this might work, zooming in/out is not an intention. And the quads are being drawn at virtually the same resolution as the texture itself, so I am not losing much by using the point filter.
  3. I'm trying to get some basic 2d tiles in D3D. I set the camera back a bit, and draw 4 quads. I make each quad 64 units in length, and start the next quad at lastquadsLeft + 64.0f. I use a tiling texture. However, as I scroll the camera left or right (it doesn't turn) I can see gaps between the quads. Now, I could use the D3Dsprite interfaces, but then I wouldn't be able to use fx files, and I would like to build them in somehow. Is there a way to make these quads appear to be continuous without any gaps, or should I just give up and go with sprites and forget fx?
  4. I think this is most likely a really simple problem, but plenty of googling has found generic but not helpful font discussion. I am using this to create my fonts: //create font D3DXFONT_DESC fontDesc; fontDesc.Height = 24; fontDesc.Width = 0; fontDesc.Weight = 500; fontDesc.MipLevels = 1; fontDesc.Italic = false; fontDesc.CharSet = DEFAULT_CHARSET; fontDesc.OutputPrecision = OUT_DEFAULT_PRECIS; fontDesc.Quality = DEFAULT_QUALITY; fontDesc.PitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; _tcscpy(fontDesc.FaceName, _T("Papyrus")); And it is all working perfectly. But it occurs to me that this font is not on everyone's machines, so I need to supply the fonts I use with my program. How would I package any font I want my users to have displayed? Use the same as above and use: _tcscpy(fontDesc.FaceName, _T("/GameFonts/Papyrus")); Or is there more to it than that. I know I may need to get permission to use non-freeware fonts, I am more worried in implementation at the moment.
  5. My reset and lost functions are merely void FrontPage::onLostDevice() { HR(mFont->OnLostDevice()); HR(mSprite->OnLostDevice()); } void FrontPage::onResetDevice() { HR(mFont->OnResetDevice()); HR(mSprite->OnResetDevice()); } Should they be doing something more than this?
  6. Quote:Original post by pcmattman Firstly, what's better to use: HLSL, or the assembly language (GPU assembly?)? Note I'm not yet looking for exceptional performance, just something that works and I can easily edit and understand. HLSL is used by many of the big studios, so I think it's easy to say that if it's good enough for them then its good enough for us hobbyists. HLSL will be more easy to learn, from my experience. I don't think the use of shaders can be explained in a forum thread, but let me recommend a book. "Introduction to 3d Game Programming with Directx 9.0x A Shader Approach" by Frank Luna is awesome, the best shader book I found after looking at quite a few while at University. It teaches the use of HLSL so that anyone comfortable with C++ can understand them very easily, while I found all the other shader books either didn't go into enough detail, or delved more into the math than the application. Frank's book is both easy to read and runs the gamut from simple shaders to fairly complex ones. This is all assuming you're working in DX9 of course.
  7. I think you're misunderstanding, I probably didn't explain well enough. My image is 1280/1024, just like the new backbuffer size. The Sprite shouldn't need to scale the image, should it? The screen size is 1280/1024, the image size is 1280/1024, therefore the sprite, being called with NULL in those params, should draw the full image. Shouldn't it? Instead it is drawing the top left portion of the image (the portion that would normally fill a 800/600 window) and stretching it to fit in the new 1280/1024 window. As though in fact the window still had a 800/600 resolution but with a size of 1280/1024.
  8. I have taken a demo from a book I bought recently, and have been trying to change the resolution of it from the basic 800/600 to 1280/1024 that my monitor supports. Now, the problem is, the window size increases just fine, but the images I paint to the screen are still being painted as though the screen size hadn't changed. That is, my 1280/1024 sized background which I am drawing with ID3DXSprite interface is only having the 800/600 portion drawn, leaving the right abd bottom portions off the screen. Here's my screen setup code, I think I have changed everything I needed to (the backbuffer sizes and the window size) but the problem remains. (my sprite drawing, in another file, uses: HR(mSprite->Draw(BGTexture, NULL, NULL, NULL, D3DCOLOR_XRGB(255, 255, 255))); //draw Background which means I am drawing from the top left, using the full source image, so if the resolution was working, it should put the entire sourse image in the window - I think). #include "d3dApp.h" D3DApp* gd3dApp = 0; IDirect3DDevice9* gd3dDevice = 0; LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { // Don't start processing messages until the application has been created. if( gd3dApp != 0 ) return gd3dApp->msgProc(msg, wParam, lParam); else return DefWindowProc(hwnd, msg, wParam, lParam); } D3DApp::D3DApp(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP) { mMainWndCaption = winCaption; mDevType = devType; mRequestedVP = requestedVP; mhAppInst = hInstance; mhMainWnd = 0; md3dObject = 0; mAppPaused = false; ZeroMemory(&md3dPP, sizeof(md3dPP)); initMainWindow(); initDirect3D(); } D3DApp::~D3DApp() { ReleaseCOM(md3dObject); ReleaseCOM(gd3dDevice); } HINSTANCE D3DApp::getAppInst() { return mhAppInst; } HWND D3DApp::getMainWnd() { return mhMainWnd; } void D3DApp::initMainWindow() { WNDCLASS wc; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = MainWndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = mhAppInst; wc.hIcon = LoadIcon(0, IDI_APPLICATION); wc.hCursor = LoadCursor(0, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName = 0; wc.lpszClassName = "D3DWndClassName"; if( !RegisterClass(&wc) ) { MessageBox(0, "RegisterClass FAILED", 0, 0); PostQuitMessage(0); } // Default to a window with a client area rectangle of 800x600. RECT R = {0, 0, 1280, 1024}; AdjustWindowRect(&R, WS_OVERLAPPEDWINDOW, false); mhMainWnd = CreateWindow("D3DWndClassName", mMainWndCaption.c_str(), WS_OVERLAPPEDWINDOW, 0, 0, R.right, R.bottom, 0, 0, mhAppInst, 0); if( !mhMainWnd ) { MessageBox(0, "CreateWindow FAILED", 0, 0); PostQuitMessage(0); } ShowWindow(mhMainWnd, SW_SHOW); UpdateWindow(mhMainWnd); } void D3DApp::initDirect3D() { // Step 1: Create the IDirect3D9 object. md3dObject = Direct3DCreate9(D3D_SDK_VERSION); if( !md3dObject ) { MessageBox(0, "Direct3DCreate9 FAILED", 0, 0); PostQuitMessage(0); } // Step 2: Verify hardware support for specified formats in windowed and full screen modes. D3DDISPLAYMODE mode; md3dObject->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &mode); HR(md3dObject->CheckDeviceType(D3DADAPTER_DEFAULT, mDevType, mode.Format, mode.Format, true)); HR(md3dObject->CheckDeviceType(D3DADAPTER_DEFAULT, mDevType, D3DFMT_X8R8G8B8, D3DFMT_X8R8G8B8, false)); // Step 3: Check for requested vertex processing and pure device. D3DCAPS9 caps; HR(md3dObject->GetDeviceCaps(D3DADAPTER_DEFAULT, mDevType, &caps)); DWORD devBehaviorFlags = 0; if( caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT ) devBehaviorFlags |= mRequestedVP; else devBehaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING; // If pure device and HW T&L supported if( caps.DevCaps & D3DDEVCAPS_PUREDEVICE && devBehaviorFlags & D3DCREATE_HARDWARE_VERTEXPROCESSING) devBehaviorFlags |= D3DCREATE_PUREDEVICE; // Step 4: Fill out the D3DPRESENT_PARAMETERS structure. md3dPP.BackBufferWidth = 1280; md3dPP.BackBufferHeight = 1024; md3dPP.BackBufferFormat = D3DFMT_X8R8G8B8; //UNKNOWN; md3dPP.BackBufferCount = 1; md3dPP.MultiSampleType = D3DMULTISAMPLE_NONE; md3dPP.MultiSampleQuality = 0; md3dPP.SwapEffect = D3DSWAPEFFECT_DISCARD; md3dPP.hDeviceWindow = mhMainWnd; md3dPP.Windowed = true; md3dPP.EnableAutoDepthStencil = true; md3dPP.AutoDepthStencilFormat = D3DFMT_D24S8; md3dPP.Flags = 0; md3dPP.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; md3dPP.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; // Step 5: Create the device. HR(md3dObject->CreateDevice( D3DADAPTER_DEFAULT, // primary adapter mDevType, // device type mhMainWnd, // window associated with device devBehaviorFlags, // vertex processing &md3dPP, // present parameters &gd3dDevice)); // return created device } int D3DApp::run() { MSG msg; msg.message = WM_NULL; __int64 cntsPerSec = 0; QueryPerformanceFrequency((LARGE_INTEGER*)&cntsPerSec); float secsPerCnt = 1.0f / (float)cntsPerSec; __int64 prevTimeStamp = 0; QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp); while(msg.message != WM_QUIT) { // If there are Window messages then process them. if(PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) { TranslateMessage( &msg ); DispatchMessage( &msg ); } // Otherwise, do animation/game stuff. else { // If the application is paused then free some CPU cycles to other // applications and then continue on to the next frame. if( mAppPaused ) { Sleep(20); continue; } if( !isDeviceLost() ) { __int64 currTimeStamp = 0; QueryPerformanceCounter((LARGE_INTEGER*)&currTimeStamp); float dt = (currTimeStamp - prevTimeStamp)*secsPerCnt; updateScene(dt); drawScene(); // Prepare for next iteration: The current time stamp becomes // the previous time stamp for the next iteration. prevTimeStamp = currTimeStamp; } } } return (int)msg.wParam; } LRESULT D3DApp::msgProc(UINT msg, WPARAM wParam, LPARAM lParam) { // Is the application in a minimized or maximized state? static bool minOrMaxed = false; RECT clientRect = {0, 0, 0, 0}; switch( msg ) { // WM_ACTIVE is sent when the window is activated or deactivated. // We pause the game when the main window is deactivated and // unpause it when it becomes active. case WM_ACTIVATE: if( LOWORD(wParam) == WA_INACTIVE ) mAppPaused = true; else mAppPaused = false; return 0; // WM_SIZE is sent when the user resizes the window. case WM_SIZE: if( gd3dDevice ) { md3dPP.BackBufferWidth = 1280;//LOWORD(lParam); md3dPP.BackBufferHeight = 1024; //HIWORD(lParam); if( wParam == SIZE_MINIMIZED ) { mAppPaused = true; minOrMaxed = true; } else if( wParam == SIZE_MAXIMIZED ) { mAppPaused = false; minOrMaxed = true; onLostDevice(); HR(gd3dDevice->Reset(&md3dPP)); onResetDevice(); } // Restored is any resize that is not a minimize or maximize. // For example, restoring the window to its default size // after a minimize or maximize, or from dragging the resize // bars. else if( wParam == SIZE_RESTORED ) { mAppPaused = false; // Are we restoring from a mimimized or maximized state, // and are in windowed mode? Do not execute this code if // we are restoring to full screen mode. if( minOrMaxed && md3dPP.Windowed ) { onLostDevice(); HR(gd3dDevice->Reset(&md3dPP)); onResetDevice(); } else { // No, which implies the user is resizing by dragging // the resize bars. However, we do not reset the device // here because as the user continuously drags the resize // bars, a stream of WM_SIZE messages is sent to the window, // and it would be pointless (and slow) to reset for each // WM_SIZE message received from dragging the resize bars. // So instead, we reset after the user is done resizing the // window and releases the resize bars, which sends a // WM_EXITSIZEMOVE message. } minOrMaxed = false; } } return 0; // WM_EXITSIZEMOVE is sent when the user releases the resize bars. // Here we reset everything based on the new window dimensions. case WM_EXITSIZEMOVE: GetClientRect(mhMainWnd, &clientRect); md3dPP.BackBufferWidth = clientRect.right; md3dPP.BackBufferHeight = clientRect.bottom; onLostDevice(); HR(gd3dDevice->Reset(&md3dPP)); onResetDevice(); return 0; // WM_CLOSE is sent when the user presses the 'X' button in the // caption bar menu. case WM_CLOSE: DestroyWindow(mhMainWnd); return 0; // WM_DESTROY is sent when the window is being destroyed. case WM_DESTROY: PostQuitMessage(0); return 0; case WM_KEYDOWN: if( wParam == VK_ESCAPE ) enableFullScreenMode(false); else if( wParam == 'F' ) enableFullScreenMode(true); return 0; } return DefWindowProc(mhMainWnd, msg, wParam, lParam); } void D3DApp::enableFullScreenMode(bool enable) { // Switch to fullscreen mode. if( enable ) { // Are we already in fullscreen mode? if( !md3dPP.Windowed ) return; int width = GetSystemMetrics(SM_CXSCREEN); int height = GetSystemMetrics(SM_CYSCREEN); md3dPP.BackBufferFormat = D3DFMT_X8R8G8B8; md3dPP.BackBufferWidth = 1280; //width; md3dPP.BackBufferHeight = 1024; //height; md3dPP.Windowed = false; // Change the window style to a more fullscreen friendly style. SetWindowLongPtr(mhMainWnd, GWL_style, WS_POPUP); // If we call SetWindowLongPtr, MSDN states that we need to call // SetWindowPos for the change to take effect. In addition, we // need to call this function anyway to update the window dimensions. SetWindowPos(mhMainWnd, HWND_TOP, 0, 0, 1280, 1024, SWP_NOZORDER | SWP_SHOWWINDOW); } // Switch to windowed mode. else { // Are we already in windowed mode? if( md3dPP.Windowed ) return; RECT R = {0, 0, 1280, 1024}; AdjustWindowRect(&R, WS_OVERLAPPEDWINDOW, false); md3dPP.BackBufferFormat = D3DFMT_UNKNOWN; md3dPP.BackBufferWidth = 1280; md3dPP.BackBufferHeight = 1024; md3dPP.Windowed = true; // Change the window style to a more windowed friendly style. SetWindowLongPtr(mhMainWnd, GWL_style, WS_OVERLAPPEDWINDOW); // If we call SetWindowLongPtr, MSDN states that we need to call // SetWindowPos for the change to take effect. In addition, we // need to call this function anyway to update the window dimensions. SetWindowPos(mhMainWnd, HWND_TOP, 0, 0, R.right, R.bottom, SWP_NOZORDER | SWP_SHOWWINDOW); } // Reset the device with the changes. onLostDevice(); HR(gd3dDevice->Reset(&md3dPP)); onResetDevice(); } bool D3DApp::isDeviceLost() { // Get the state of the graphics device. HRESULT hr = gd3dDevice->TestCooperativeLevel(); // If the device is lost and cannot be reset yet then // sleep for a bit and we'll try again on the next // message loop cycle. if( hr == D3DERR_DEVICELOST ) { Sleep(20); return true; } // Driver error, exit. else if( hr == D3DERR_DRIVERINTERNALERROR ) { MessageBox(0, "Internal Driver Error...Exiting", 0, 0); PostQuitMessage(0); return true; } // The device is lost but we can reset and restore it. else if( hr == D3DERR_DEVICENOTRESET ) { onLostDevice(); HR(gd3dDevice->Reset(&md3dPP)); onResetDevice(); return false; } else return false; } Any help is appreciated. It's most likely an obvious mistake and I'm being dumb, but I can't see the problem.
  9. My aim is to have a float value representing a vertex's height oscillate between a minimum and maximum value smoothly over time. It will start at the minimum value at the start of the program. I have two floats MIN and MAX describing the minimum and maximum value of a vertex's y, and the float CHANGEPERSECOND telling us how much the vertex changes in a second. I also have the float AGE which tells us the age of the vertex. 1.0f being one second. 100.0f being 100 hundred seconds old, etc. So, given these details in the shader, what equation would give us the correct y value for our vertex? I appreciate any help. I am not a great mathematician, and I thought you guys would be the perfect ones to ask. I am looking to plug this into my shader (HLSL fx), so a reply which gives a little code snippet I could use would be greatly appreciated. There's a danger I may not understand a reply that uses some of the more complicated math notation. (I know, no genius here). [Edited by - Funso on March 9, 2007 11:48:34 AM]
  10. I have been using the gametutorial.com tutorials for learning directx9, and so far have been doing nicely. The tutorials go into shading, but they all use a cube or sphere to illustrate shading. They create a sphere, use CloneMeshFVF to shange the vert type to one defined earlier, and then draw a D3DPT_TRIANGLELIST using these verts. I tried to break a model built from an x file in the same way, and try as I might, I couldn't get this to work. It compiled, then didn't render as it should. Either no rendering, or the normals are crazy and nothing as they should be. To be precise, it isn't the shaders I am haing trouble with, but the implementation of the shader into my c++ project if using a complex (read not a sphere or cube) model. Are there any shader tutorials which show how to implement a shader using a proper model? I am finding it hard to find relevant tutorials, they all seem to be based around C# and not helping me. Any help or links to help is appreciated.
  • 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!