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

falcon93

Members
  • Content count

    124
  • Joined

  • Last visited

Community Reputation

121 Neutral

About falcon93

  • Rank
    Member

Personal Information

  • Location
    Sweden
  1. Yes, I've compiled it a couple of times and it builds successfully, the window appears and there's something drawn, but it draws realy strange (see image in previous post). I'll move on to DirectX11 instead. Exciting [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]
  2. Thanks very much for your help ATC [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] I've heard of different wrappers of DirectX for C#. The reason that I chose C++ and DirectX anyway, is becouse many companies in the game industry uses it. As I'm a student, having knowledge in these areas can be a very good qualification when it's time to search for a job. I'll take a look at the link and try a little bit by my own again. However I recently tried to get it work with DirectX11, but problems accured and I guess that they will this time too. If so, I'll send you a pm so you can help me. Thanks again so much for your help [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
  3. Thanks for your reply ATC. I actually wanted to learn DirectX11, but I havn't managed to find any good tutorials about textured quads. The only tutorial I found was really overkill, using shaders etc. I would really like to learn DirectX11, but could you help me to find any totorial that just picks the absolutely neccessary to draw a textured quad? I'm already familiar with encapsulization and separating into classes as I have 5 years experience of C# and XNA. I just felt that I wanted to move on with something more advanced than XNA, and therefore decided to learn C++ and DirectX. I know that the code should be splitted into classes, but before I do that, I just want everything in one place so I can overveiw it easy. The only purpose of the current project is so I learn the simpliest basics. When I've learn these, I'll move along with a new project where I'll split the code into classes and learn more complicated things. Could you please help me find a good tutorial with [i]only the absolutely neccessary steps[/i] to render a textured quad in DirectX11? Or, if you want to be very kind, would you like to spend like 10-15 minutes and write a short tutorial with the absolutely neccessary steps?
  4. Thanks for your reply Waaayoff. I've added the file extension, ".png". I'll look deeper into error checking, while I do that; I've done some minor chages to the code again, and there's actually something appearing on the screen now, however, the texture just looks strange. It's supposed to be a small cloud: [url=http://postimage.org/][img]http://s16.postimage.org/lalw86mfl/Image.png[/img][/url] But instead this is showing up: [url=http://postimage.org/image/xqim1xfrl/][img]http://s16.postimage.org/xqim1xfrl/Window.jpg[/img][/url] Current code below (error checking coming soon): [CODE] #include <windows.h> #include <windowsx.h> #include <d3d9.h> #include <d3dx9.h> #define FULLSCREEN FALSE #define SCREEN_WIDTH 1280 #define SCREEN_HEIGHT 800 #pragma comment (lib, "d3d9.lib") #pragma comment (lib, "d3dx9.lib") #define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_TEX1) LPDIRECT3D9 d3d; LPDIRECT3DDEVICE9 d3ddev; LPDIRECT3DVERTEXBUFFER9 v_buffer; LPDIRECT3DTEXTURE9 d3dtex; D3DPRESENT_PARAMETERS d3dpp; struct CUSTOMVERTEX { float X, Y, Z, RHW, U, V; }; LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HWND hWnd; WNDCLASSEX wc; MSG msg; ZeroMemory(&wc, sizeof(WNDCLASSEX)); wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WindowProc; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.lpszClassName = L"WindowClass"; RegisterClassEx(&wc); if (FULLSCREEN) { hWnd = CreateWindowEx(NULL, L"WindowClass", L"Window 1", WS_EX_TOPMOST | WS_POPUP, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL); } else { hWnd = CreateWindowEx(NULL, L"WindowClass", L"Window 1", WS_OVERLAPPEDWINDOW, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL); } ShowWindow(hWnd, nCmdShow); d3d = Direct3DCreate9(D3D_SDK_VERSION); ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.Windowed = !FULLSCREEN; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.hDeviceWindow = hWnd; d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; d3dpp.BackBufferWidth = SCREEN_WIDTH; d3dpp.BackBufferHeight = SCREEN_HEIGHT; d3d -> CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev); D3DXCreateTextureFromFile(d3ddev, L"ParticleSmokeCloud64x64.png", &d3dtex); struct CUSTOMVERTEX vertices[] = { { 10.0f, 10.0f, 0.0f, 1.0f, 0.0f, 0.0f, }, { 110.0f, 10.0f, 0.0f, 1.0f, 1.0f, 0.0f, }, { 10.0f, 110.0f, 0.0f, 1.0f, 0.0f, 1.0f, }, { 110.0f, 110.0f, 0.0f, 1.0f, 1.0f, 1.0f, }, }; d3ddev -> CreateVertexBuffer(4 * sizeof(CUSTOMVERTEX), NULL, CUSTOMFVF, D3DPOOL_MANAGED, &v_buffer, NULL); VOID* pVoid; v_buffer -> Lock(0, 0, (void**)&pVoid, 0); memcpy(pVoid, vertices, sizeof(vertices)); v_buffer -> Unlock(); while (TRUE) { while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage (&msg); } if (msg.message == WM_QUIT) break; d3ddev -> Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255, 255, 255), 1.0f, 0); d3ddev -> BeginScene(); d3ddev -> SetRenderState( D3DRS_LIGHTING, TRUE); d3ddev -> SetTexture(0, d3dtex); d3ddev -> SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX)); d3ddev -> SetFVF(CUSTOMFVF); d3ddev -> DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); d3ddev -> EndScene(); d3ddev -> Present(NULL, NULL, NULL, NULL); } v_buffer -> Release(); d3ddev -> Release(); d3d -> Release(); return msg.wParam; } LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_DESTROY: PostQuitMessage(0); return 0; break; } return DefWindowProc(hWnd, message, wParam, lParam); } [/CODE]
  5. I've tried to rewrite everything, so now it atleast appears a quad. However, the quad isn't textured but instead some sort of a gradient with black and red. I guess that I don't have to set up any veiwport, otherways the quad itself wouldn't appear, right? Any other ideas? I've pasted the new code below [CODE] #include <windows.h> #include <windowsx.h> #include <d3d9.h> #include <d3dx9.h> #define FULLSCREEN FALSE #define SCREEN_WIDTH 1280 #define SCREEN_HEIGHT 800 #pragma comment (lib, "d3d9.lib") #pragma comment (lib, "d3dx9.lib") #define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1) LPDIRECT3D9 d3d; LPDIRECT3DDEVICE9 d3ddev; LPDIRECT3DVERTEXBUFFER9 v_buffer; LPDIRECT3DTEXTURE9 d3dtex; D3DPRESENT_PARAMETERS d3dpp; struct CUSTOMVERTEX { float X, Y, Z, RHW, U, V; DWORD COLOR; }; LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HWND hWnd; WNDCLASSEX wc; MSG msg; ZeroMemory(&wc, sizeof(WNDCLASSEX)); wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WindowProc; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.lpszClassName = L"WindowClass"; RegisterClassEx(&wc); if (FULLSCREEN) { hWnd = CreateWindowEx(NULL, L"WindowClass", L"Window 1", WS_EX_TOPMOST | WS_POPUP, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL); } else { hWnd = CreateWindowEx(NULL, L"WindowClass", L"Window 1", WS_OVERLAPPEDWINDOW, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL); } ShowWindow(hWnd, nCmdShow); d3d = Direct3DCreate9(D3D_SDK_VERSION); ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.Windowed = !FULLSCREEN; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.hDeviceWindow = hWnd; d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; d3dpp.BackBufferWidth = SCREEN_WIDTH; d3dpp.BackBufferHeight = SCREEN_HEIGHT; d3d -> CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev); D3DXCreateTextureFromFile(d3ddev, L"ParticleSmokeCloud64x64", &d3dtex); struct CUSTOMVERTEX vertices[] = { { 10.0f, 10.0f, 0.0f, 1.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(0, 255, 0), }, { 110.0f, 10.0f, 0.0f, 1.0f, 1.0f, 0.0f, D3DCOLOR_XRGB(0, 0, 255), }, { 10.0f, 110.0f, 0.0f, 1.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), }, { 110.0f, 110.0f, 0.0f, 1.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(0, 255, 255), }, }; d3ddev -> CreateVertexBuffer(4 * sizeof(CUSTOMVERTEX), NULL, CUSTOMFVF, D3DPOOL_MANAGED, &v_buffer, NULL); VOID* pVoid; v_buffer -> Lock(0, 0, (void**)&pVoid, 0); memcpy(pVoid, vertices, sizeof(vertices)); v_buffer -> Unlock(); while (TRUE) { while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage (&msg); } if (msg.message == WM_QUIT) break; d3ddev -> Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255, 255, 255), 1.0f, 0); d3ddev -> BeginScene(); d3ddev -> SetFVF(CUSTOMFVF); d3ddev -> SetTexture(0, d3dtex); d3ddev -> SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX)); d3ddev -> DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); d3ddev -> EndScene(); d3ddev -> Present(NULL, NULL, NULL, NULL); } v_buffer -> Release(); d3ddev -> Release(); d3d -> Release(); return msg.wParam; } LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_DESTROY: PostQuitMessage(0); return 0; break; } return DefWindowProc(hWnd, message, wParam, lParam); } [/CODE]
  6. Hello everyone! I'm trying to draw a textured quad made from 4 vertices using DirectX9. I've followed some tutorials but it simply wont work. I've pasted the code below and I would appreciate it very much if someone could look through it and help me. I know that the code should be splitted up into methods and classes, but before i do that I want to keep it as simple as possible and be able to see and learn the entire process. What i want this code to do is to simply draw my quad with a texture on it. Could anyone please help me? My current code (I've also attached the project): [CODE] #include <windows.h> #include <d3d9.h> #include <d3dx9.h> #define FULLSCREEN FALSE #define SCREEN_WIDTH 1280 #define SCREEN_HEIGHT 800 #pragma comment (lib, "d3d9.lib") #pragma comment (lib, "d3dx9.lib") const DWORD D3DFVF_TLVERTEX = D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1; struct TLVERTEX { float x, y, z; float rhw; D3DCOLOR color; float u, v; }; LPDIRECT3D9 d3d; LPDIRECT3DDEVICE9 d3ddev; LPDIRECT3DVERTEXBUFFER9 vertexBuffer; D3DPRESENT_PARAMETERS d3dpp; LPDIRECT3DTEXTURE9 d3dTexture; TLVERTEX* vertices; LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); HRESULT WINAPI D3DXCreateTextureFromFile(LPDIRECT3DDEVICE9 pDevice, LPCTSTR pSrcFile, LPDIRECT3DTEXTURE9 *ppTexture); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HWND hWnd; WNDCLASSEX wc; MSG msg; ZeroMemory(&wc, sizeof(WNDCLASSEX)); wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WindowProc; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.lpszClassName = L"WindowClass"; RegisterClassEx(&wc); if (FULLSCREEN) { hWnd = CreateWindowEx(NULL, L"WindowClass", L"Window 1", WS_EX_TOPMOST | WS_POPUP, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL); } else { hWnd = CreateWindowEx(NULL, L"WindowClass", L"Window 1", WS_OVERLAPPEDWINDOW, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL); } ShowWindow(hWnd, nCmdShow); d3d = Direct3DCreate9(D3D_SDK_VERSION); ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.Windowed = !FULLSCREEN; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.hDeviceWindow = hWnd; d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; d3dpp.BackBufferWidth = SCREEN_WIDTH; d3dpp.BackBufferHeight = SCREEN_HEIGHT; d3d -> CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev); d3ddev -> CreateVertexBuffer(sizeof(TLVERTEX) * 4, NULL, D3DFVF_TLVERTEX, D3DPOOL_MANAGED, &vertexBuffer, NULL); vertexBuffer->Lock(0, 0, (void**)&vertices, NULL); vertices[0].x = 0.0F; vertices[0].y = 0.0F; vertices[0].z = 0.0F; vertices[0].u = 0.0F; vertices[0].v = 0.0F; vertices[0].rhw = 1.0F; vertices[0].color = D3DCOLOR_ARGB(255, 255, 255, 255); vertices[0].x = 64.0F; vertices[0].y = 0.0F; vertices[0].z = 0.0F; vertices[0].u = 1.0F; vertices[0].v = 0.0F; vertices[0].rhw = 1.0F; vertices[0].color = D3DCOLOR_ARGB(255, 255, 255, 255); vertices[0].x = 0.0F; vertices[0].y = 64.0F; vertices[0].z = 0.0F; vertices[0].u = 0.0F; vertices[0].v = 1.0F; vertices[0].rhw = 1.0F; vertices[0].color = D3DCOLOR_ARGB(255, 255, 255, 255); vertices[0].x = 64.0F; vertices[0].y = 64.0F; vertices[0].z = 0.0F; vertices[0].u = 1.0F; vertices[0].v = 1.0F; vertices[0].rhw = 1.0F; vertices[0].color = D3DCOLOR_ARGB(255, 255, 255, 255); vertexBuffer->Unlock(); VOID* pVoid; vertexBuffer -> Lock(0, 0, (void**)&pVoid, 0); memcpy(pVoid, vertices, sizeof(vertices)); vertexBuffer -> Unlock(); D3DXCreateTextureFromFile(d3ddev, L"ParticleSmokeCloud64x64.png", &d3dTexture); while (TRUE) { while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage (&msg); } if (msg.message == WM_QUIT) break; d3ddev -> Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255, 255, 255), 1.0f, 0); d3ddev -> BeginScene(); d3ddev -> SetRenderState(D3DRS_LIGHTING, FALSE); d3ddev -> SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); d3ddev -> SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); d3ddev -> SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); d3ddev -> SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); d3ddev -> SetTexture (0, d3dTexture); d3ddev -> SetVertexShader(NULL); d3ddev -> SetFVF(D3DFVF_TLVERTEX); d3ddev -> SetStreamSource(0, vertexBuffer, 0, sizeof(TLVERTEX)); d3ddev -> DrawPrimitive (D3DPT_TRIANGLEFAN, 0, 2); d3ddev -> EndScene(); d3ddev -> Present(NULL, NULL, NULL, NULL); } d3ddev -> Release(); d3d -> Release(); return msg.wParam; } LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_DESTROY: PostQuitMessage(0); return 0; break; } return DefWindowProc(hWnd, message, wParam, lParam); } [/CODE]
  7. Anyone please?
  8. Hi! The method below is from my project that uses pixel collision. The collision "works", but I'm encountering a bug during the test. When the collision is detected on the right and bottom side of Texture1, the pixel collision works perfectly. However when the collision is detected on the left and top side of Texture1, Texture2 has to intersect with half it's size before collision is detected. I've added the entire project if you would like to take a look and below is the collision method. Please help! Project: [color=#CC0000][font=Verdana, Helvetica, Tahoma, Arial][url="http://s000.tinyupload.com/index.php?file_id=54830964798969346127"]http://s000.tinyupload.com/?file_id=54830964798969346127[/url][/font][/color] [source lang="cs"] public bool IntersectPixels( Matrix transformA, Rectangle rectangleA, int widthA, int heightA, Color[] dataA, Matrix transformB, Rectangle rectangleB, int widthB, int heightB, Color[] dataB) { int top = Math.Max(rectangleA.Top, rectangleB.Top); int bottom = Math.Min(rectangleA.Bottom, rectangleB.Bottom); int left = Math.Max(rectangleA.Left, rectangleB.Left); int right = Math.Min(rectangleA.Right, rectangleB.Right); rectangle = new Rectangle(left, top, right - left, bottom - top); // Calculate a matrix which transforms from A's local space into // world space and then into B's local space Matrix transformAToB = transformA * Matrix.Invert(transformB); // When a point moves in A's local space, it moves in B's local space with a // fixed direction and distance proportional to the movement in A. // This algorithm steps through A one pixel at a time along A's X and Y axes // Calculate the analogous steps in B: Vector2 stepX = Vector2.TransformNormal(Vector2.UnitX, transformAToB); Vector2 stepY = Vector2.TransformNormal(Vector2.UnitY, transformAToB); // Calculate the top left corner of A in B's local space // This variable will be reused to keep track of the start of each row Vector2 yPosInB = Vector2.Transform(Vector2.Zero, transformAToB); // For each row of pixels in A for (int yA = 0; yA < rectangle.Height; yA++) { // Start at the beginning of the row Vector2 posInB = yPosInB; // For each pixel in this row for (int xA = 0; xA < rectangle.Height; xA++) { // Round to the nearest pixel int xB = (int)Math.Round(posInB.X); int yB = (int)Math.Round(posInB.Y); // If the pixel lies within the bounds of B if (0 <= xB && xB < widthB && 0 <= yB && yB < heightB) { if (0 <= xA && xA < widthA && 0 <= yA && yA < heightA) { // Get the colors of the overlapping pixels Color colorA = dataA[xA + yA * widthA]; Color colorB = dataB[xB + yB * widthB]; // If both pixels are not completely transparent, if (colorA.A != 0 && colorB.A != 0) { // then an intersection has been found return true; } } } // Move to the next pixel in the row posInB += stepX; } // Move to the next row yPosInB += stepY; } // No intersection found return false; } [/source]
  9. PM sent Thanks for helping
  10. It's the SQL Server Compact Edition Database File (33.6mb) and a folder called ipch(50.6mb). I havn't added them, they was put there automaticly when I created my project in Visual Studio. Do you have Skype?
  11. I'm using Visual Studio 2010 [quote]as Aero said you should use D3DXCreateTextureFromFileEx. its the only way to get it to work [/quote] I tried using it, and specifying width and height manually, but it did no difference?
  12. Not sure if you meant DirectX version or SDK version... DirectX DirectX SDK June 2010 C++ version? My stationary computer supports D3DX_DEFAULT_NONPOW2, but my laptop does not. But there has to be another way? What did you mean with surface? Here's the code from Graphics.cpp: [source lang="cpp"] #include "Graphics.h" Graphics::Graphics(HWND hWnd) { d3d = Direct3DCreate9(D3D_SDK_VERSION); ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS)); d3dpp.Windowed = true; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.hDeviceWindow = hWnd; d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; d3dpp.BackBufferWidth = 1280; d3dpp.BackBufferHeight = 800; d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev); D3DXCreateSprite(d3ddev, &sprite); } Graphics::~Graphics(void) { } // -------------------------------------------------------------------------------- // Name: Begin // Desc: Prepares a device for drawing // Rtrn: None // -------------------------------------------------------------------------------- void Graphics::Begin(void) { d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255, 255, 255), 1, 0); d3ddev->BeginScene(); sprite->Begin(D3DXSPRITE_ALPHABLEND); } // -------------------------------------------------------------------------------- // Name: Draw // Desc: Draws a texture to the screen // Rtrn: None // -------------------------------------------------------------------------------- void Graphics::Draw(LPDIRECT3DTEXTURE9 texture, D3DXVECTOR3 position, int alpha) { color = D3DCOLOR_COLORVALUE(0, 0, 0, alpha); sprite->Draw(texture, NULL, NULL, &position, 0xFFFFFFFF); } // -------------------------------------------------------------------------------- // Name: DrawSpriteSheet // Desc: Draws a texture to the screen with enabled source rectangle // Rtrn: None // -------------------------------------------------------------------------------- void Graphics::DrawSpriteSheet(LPDIRECT3DTEXTURE9 texture, D3DXVECTOR3 position, RECT source_rectangle, int alpha) { color = D3DCOLOR_COLORVALUE(255, 255, 255, alpha); sprite->Draw(texture, &source_rectangle, NULL, &position, 0xFFFFFFFF); } // -------------------------------------------------------------------------------- // Name: DrawEx // Desc: Draws a texture to the screen with enabled rotation // Rtrn: None // -------------------------------------------------------------------------------- void Graphics::DrawEx(LPDIRECT3DTEXTURE9 texture, D3DXVECTOR3 position, RECT source_rectangle, int alpha, D3DXVECTOR3 rotation_orgin, float rotation) { } // -------------------------------------------------------------------------------- // Name: End // Desc: Restores the device state to how it was before Begin was called // Rtrn: None // -------------------------------------------------------------------------------- void Graphics::End(void) { sprite->End(); d3ddev->EndScene(); d3ddev->Present(NULL, NULL, NULL, NULL); } // -------------------------------------------------------------------------------- // Name: LoadTexture // Desc: Creates a texture from a file // Rtrn: Returns the created texture // -------------------------------------------------------------------------------- LPDIRECT3DTEXTURE9 Graphics::LoadTexture(LPCWSTR path) { D3DXCreateTextureFromFile(d3ddev, path, &texture); return texture; } [/source] And if you want the entire project: [color=#CC0000][font=Verdana, Helvetica, Tahoma, Arial][url="http://s000.tinyupload.com/index.php?file_id=06177933712431710737"]http://s000.tinyupload.com/?file_id=06177933712431710737[/url][/font][/color]
  13. I'll take a look at the code, thank you Meanwhile, what about keeping the images original proportions? I tried to set the width and height manually in my code, but it still rounds?
  14. My stationary computer supports D3DX_DEFAULT_NONPOW2, but my laptop does not [img]http://public.gamedev.net/public/style_emoticons/default/sad.gif[/img] Is there any way (that is supported on all computers) to draw an image with it's original proportions? I'm trying to find a solid solution that will support three things: 1. png images with transparent parts 2. sprite sheet animation 3. rotation (and of course original proportions) Based on this, which way should I choose? There has to be something that support this 3 things, or? Thanks everyone for helping
  15. Ok, I solved it by simply add the BeginScene, EndScene and Present methods. Everything works well now, my current code is below (some of the code in main.cpp is just temporary) Main.cpp [source lang="cpp"] #include <Windows.h> #include "Main.h" #include "Graphics.h" #include "Input.h" Graphics* graphics; Input* input; LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hWnd, message, wParam, lParam); } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wc; ZeroMemory(&wc, sizeof(WNDCLASSEX)); wc.cbSize = sizeof(WNDCLASSEX); wc.hInstance = hInstance; wc.lpfnWndProc = WindowProc; wc.lpszClassName = L"AvoidBallClass"; wc.style = CS_VREDRAW | CS_HREDRAW; RegisterClassEx(&wc); HWND hWnd; hWnd = CreateWindowEx(NULL, L"AvoidBallClass", L"AvoidBall", WS_OVERLAPPED, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL); ShowWindow(hWnd, nCmdShow); MSG msg; graphics = new Graphics(hWnd); input = new Input(); // Temporary LPDIRECT3DTEXTURE9 texture; texture = graphics->LoadTexture(L"spitfire.png"); D3DXVECTOR3 pos; pos.x = 0; pos.y = 0; pos.z = 0; RECT rectangle; rectangle.bottom = 400; rectangle.top = 0; rectangle.right = 100; rectangle.left = 0; while (true) { while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } graphics->Begin(); graphics->Draw(texture, pos, 0); graphics->End(); if (input->ButtonDownOnce(VK_ESCAPE)) { PostQuitMessage(0); return 0; } } // TODO: Clean up resources. return msg.wParam; } [/source] Graphics.cpp [source lang="cpp"] #include "Graphics.h" Graphics::Graphics(HWND hWnd) { d3d = Direct3DCreate9(D3D_SDK_VERSION); ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS)); d3dpp.Windowed = true; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.hDeviceWindow = hWnd; d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; d3dpp.BackBufferWidth = 1280; d3dpp.BackBufferHeight = 800; d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev); D3DXCreateSprite(d3ddev, &sprite); } Graphics::~Graphics(void) { } // -------------------------------------------------------------------------------- // Name: Begin // Desc: Prepares a device for drawing // Rtrn: None // -------------------------------------------------------------------------------- void Graphics::Begin(void) { d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255, 255, 255), 1, 0); d3ddev->BeginScene(); sprite->Begin(D3DXSPRITE_ALPHABLEND); } // -------------------------------------------------------------------------------- // Name: Draw // Desc: Draws a texture to the screen // Rtrn: None // -------------------------------------------------------------------------------- void Graphics::Draw(LPDIRECT3DTEXTURE9 texture, D3DXVECTOR3 position, int alpha) { color = D3DCOLOR_COLORVALUE(0, 0, 0, alpha); sprite->Draw(texture, NULL, NULL, &position, 0xFFFFFFFF); } // -------------------------------------------------------------------------------- // Name: DrawSpriteSheet // Desc: Draws a texture to the screen with enabled source rectangle // Rtrn: None // -------------------------------------------------------------------------------- void Graphics::DrawSpriteSheet(LPDIRECT3DTEXTURE9 texture, D3DXVECTOR3 position, RECT source_rectangle, int alpha) { color = D3DCOLOR_COLORVALUE(255, 255, 255, alpha); sprite->Draw(texture, &source_rectangle, NULL, &position, 0xFFFFFFFF); } // -------------------------------------------------------------------------------- // Name: DrawEx // Desc: Draws a texture to the screen with enabled rotation // Rtrn: None // -------------------------------------------------------------------------------- void Graphics::DrawEx(LPDIRECT3DTEXTURE9 texture, D3DXVECTOR3 position, RECT source_rectangle, int alpha, D3DXVECTOR3 rotation_orgin, float rotation) { } // -------------------------------------------------------------------------------- // Name: End // Desc: Restores the device state to how it was before Begin was called // Rtrn: None // -------------------------------------------------------------------------------- void Graphics::End(void) { sprite->End(); d3ddev->EndScene(); d3ddev->Present(NULL, NULL, NULL, NULL); } // -------------------------------------------------------------------------------- // Name: LoadTexture // Desc: Creates a texture from a file // Rtrn: Returns the created texture // -------------------------------------------------------------------------------- LPDIRECT3DTEXTURE9 Graphics::LoadTexture(LPCWSTR path) { D3DXCreateTextureFromFile(d3ddev, path, &texture); return texture; } [/source] Graphics.h [source lang="cpp"] #pragma once #include <d3d9.h> #include <d3dx9.h> #pragma comment (lib, "d3d9.lib") #pragma comment (lib, "d3dx9.lib") class Graphics { public: Graphics(HWND hWnd); ~Graphics(void); // -------------------------------------------------------------------------------- // Name: Begin // Desc: Prepares a device for drawing // Rtrn: None // -------------------------------------------------------------------------------- void Begin(void); // -------------------------------------------------------------------------------- // Name: Draw // Desc: Draws a texture to the screen // Rtrn: None // -------------------------------------------------------------------------------- void Draw(LPDIRECT3DTEXTURE9 texture, D3DXVECTOR3 position, int alpha); // -------------------------------------------------------------------------------- // Name: DrawSpriteSheet // Desc: Draws a texture to the screen with enabled source rectangle // Rtrn: None // -------------------------------------------------------------------------------- void DrawSpriteSheet(LPDIRECT3DTEXTURE9 texture, D3DXVECTOR3 position, RECT source_rectangle, int alpha); // -------------------------------------------------------------------------------- // Name: DrawEx // Desc: Draws a texture to the screen with enabled rotation // Rtrn: None // -------------------------------------------------------------------------------- void DrawEx(LPDIRECT3DTEXTURE9 texture, D3DXVECTOR3 position, RECT source_rectangle, int alpha, D3DXVECTOR3 rotation_orgin, float rotation); // -------------------------------------------------------------------------------- // Name: End // Desc: Restores the device state to how it was before Begin was called // Rtrn: None // -------------------------------------------------------------------------------- void End(void); // -------------------------------------------------------------------------------- // Name: LoadTexture // Desc: Creates a texture from a file // Rtrn: Returns the created texture // -------------------------------------------------------------------------------- LPDIRECT3DTEXTURE9 LoadTexture(LPCWSTR path); private: LPDIRECT3D9 d3d; D3DPRESENT_PARAMETERS d3dpp; LPDIRECT3DDEVICE9 d3ddev; LPD3DXSPRITE sprite; LPDIRECT3DTEXTURE9 texture; D3DCOLOR color; }; [/source] Does this seem correct, or should you have changed anything? (I'll also add the error checking) Then I also have 2 more questions: 1. I've noticed that the texture is scaling to the closest 64x64, 128x128, 256x256, 512x512, 1024x1024 etc. If my texture is 300 in height, it's going to be scaled to 512 in height. Can I disable this somehow? 2. What do [i]you[/i] think is better? Using Sprites or setting up vertices? @ryan20fun: Ok, I've checked the Debug Runtime Version. Should I do anything with the Debug Output Level? Where will I find this debug help in Visual Studio when I work? Thanks for helping!