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

Nothing is drawing to the screen [FIXED]

0 posts in this topic

Alright, so I started reading through my tutorial books again and I decided to try one of its implementations, but I tried making a class that handles it. After I got everything set up, no errors were given, not even failed initializations, but the functions called only drew black to the screen. Clear() worked for my Direct3D device when I changed the color, but it still didn't displaying the bitmap. If I changed the file directory, there was surface loading error, so I knew that my program could find my image file, but when it did, it simply didn't draw it. I've checked, and the code after Device->BeginScene was executed, returning true, and the code inside its if statement executed as well, and Device->Present was also called. So why? I tried putting everything in the WinMain.cpp file as well, as the book did it, but it gave me the exact same results. I scoured Google already, so here's my help topic.

 

d3d9.lib and d3dx9.lib are both included. The Include and Lib/x64 directories are added from DirectX's June 2010 folder.

 

Here is my code:

 

WinMain.cpp

[spoiler]

#include <Windows.h>
#include <tchar.h>
#include "Game.hpp"
#include "DXGraphics.hpp"
#include "Definitions.hpp"

LRESULT CALLBACK WinProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
ATOM MyRegisterClass (HINSTANCE hInstance);

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR     cmdLine,
                   int         cmdShow)
{
    MyRegisterClass(hInstance);
    HWND hWnd;       // window handle
    /*RECT wr = {0, 0, 500, 400};
    AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, NULL);*/

    DWORD winStyle;

    if (FULLSCREEN)
        winStyle = WS_EX_TOPMOST | WS_VISIBLE | WS_POPUP;
    else
        winStyle = WS_OVERLAPPED;

    hWnd = CreateWindowEx(0,  
                         _TEXT("GameProject"), // name of the window class
                         _TEXT("GameProject"), // title of the window
                          winStyle, // window style
                          433, // X position
                          184, // Y position
                          SCREEN_WIDTH, // width
                          SCREEN_HEIGHT, // height
                          0, // parent window
                          0, // menus
                          hInstance, // application handle
                          0); // multiple windows

    // display window
    ShowWindow(hWnd, cmdShow);

    DXGraphics GraphicsHandler;
    LPDIRECT3DSURFACE9 background;
    GraphicsHandler.Init(hWnd);
    background = GraphicsHandler.LoadSurface("Graphics/mufntron.bmp", hWnd);
    
    // holds windows event messages
    MSG msg;

    while (true)
    {
        if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
        {
            // translate keystroke messages into the right format
            TranslateMessage(&msg);

            // send the message to the WinProc format
            DispatchMessage(&msg);
            
            GraphicsHandler.Render(background);
            GraphicsHandler.Present();

            // check for the escape key
            if (KEY_DN(VK_ESCAPE))
                PostMessage(hWnd, WM_DESTROY, 0, 0);

            // exit the loop
            if(msg.message == WM_QUIT)
                break;
        }
    }

    background->Release();
    return msg.wParam;
}

LRESULT CALLBACK WinProc(HWND hWnd,
                         UINT message,
                         WPARAM wParam,
                         LPARAM lParam)
{
    // sort through and find what code to run for the message given
    switch (message)
    {
    case WM_DESTROY:
        // close the application entirely
        PostQuitMessage(0);
        return 0;
        break;
    }

    return DefWindowProc(hWnd, message, wParam, lParam);
}

ATOM MyRegisterClass (HINSTANCE hInstance)
{
    WNDCLASSEX wc; // struct that holds information for the window class
    ZeroMemory(&wc, sizeof(WNDCLASSEX)); // clear out window class for use

    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.style         = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc   = WinProc;
    wc.hInstance     = hInstance;
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
    wc.lpszClassName = _TEXT("GameProject");

    return RegisterClassEx(&wc);
}

[/spoiler]

 

DXGraphics.cpp

[spoiler]

// DXGraphics.cpp

#include "DXGraphics.hpp"

DXGraphics::~DXGraphics()
{
    Object->Release();
    Device->Release();
    Backbuffer->Release();
    SpriteHandler->Release();
}

bool DXGraphics::Init(HWND hWnd)
{
    HRESULT result;
    Object = Direct3DCreate9(D3D_SDK_VERSION);
    
    if (Object == 0)
    {
        MessageBox(hWnd, _TEXT("DirectX runtime library not found"), _TEXT("Direct3D Error"), MB_OK);
        return false;
    }

    // initialize all parameters to zero, then fill parameters
    ZeroMemory(&Parameters, sizeof(D3DPRESENT_PARAMETERS));
    Parameters.Windowed                  = (!FULLSCREEN);
    Parameters.SwapEffect              = D3DSWAPEFFECT_COPY;
    Parameters.BackBufferFormat          = D3DFMT_X8R8G8B8;
    Parameters.BackBufferCount          = 1;
    Parameters.BackBufferWidth          = SCREEN_WIDTH;
    Parameters.BackBufferHeight          = SCREEN_HEIGHT;
    Parameters.hDeviceWindow          = hWnd;
    Parameters.EnableAutoDepthStencil = true;
    Parameters.AutoDepthStencilFormat = D3DFMT_D16;
    Parameters.PresentationInterval   = D3DPRESENT_INTERVAL_IMMEDIATE;

    // set the result variable to check for an error
    result = Object->CreateDevice(
                      D3DADAPTER_DEFAULT,
                     D3DDEVTYPE_HAL,
                     hWnd,
                     D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                     &Parameters,
                     &Device);

    if (FAILED(result))
    {
        MessageBox(hWnd, _TEXT("Error creating Direct3D Device"), _TEXT("Direct3D Device Error"), MB_OK);
        return false;
    }

    // clear the backbuffer to black
    Device->Clear(0, 0, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
        
    // get a pointer to the buffer
    Device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &Backbuffer);


    result = D3DXCreateSprite(Device, &SpriteHandler);
    if (result != D3D_OK)
    {
        MessageBox(hWnd, _TEXT("Error initializing the Sprite Handler"), _TEXT("Direct3D Device Error"), MB_OK);
        return false;
    }

    return true;
}

LPDIRECT3DTEXTURE9 DXGraphics::LoadTexture(char* location, D3DCOLOR transparency)
{
    // texture pointer
    LPDIRECT3DTEXTURE9 image = 0;

    // the struct for reading bitmap info
    D3DXIMAGE_INFO imageInfo;

    // standard Windows return value
    HRESULT result;

    // get info from the bitmap file
    result = D3DXGetImageInfoFromFile(location, &imageInfo);
    if (result != D3D_OK)
        return 0;

    // create new texture by loading the image
    D3DXCreateTextureFromFileEx(
        Device,
        location,
        imageInfo.Width,
        imageInfo.Height,
        1,
        D3DPOOL_DEFAULT,
        D3DFMT_UNKNOWN,
        D3DPOOL_DEFAULT,
        D3DX_DEFAULT,
        D3DX_DEFAULT,
        transparency,
        &imageInfo,
        0,
        &image);
    
    if (result != D3D_OK)
        return 0;
    
    return image;
}

LPDIRECT3DSURFACE9 DXGraphics::LoadSurface(char* location, HWND hWnd)
{
    // texture pointer
    LPDIRECT3DSURFACE9 image = 0;

    // the struct for reading bitmap info
    D3DXIMAGE_INFO imageInfo;

    // standard Windows return value
    HRESULT result;

    // get info from the bitmap file
    result = D3DXGetImageInfoFromFile(location, &imageInfo);
    if (FAILED(result))
    {
        MessageBox(hWnd, _TEXT("Error getting surface info"), _TEXT("LPDIRECT3DSURFACE9 Error"), MB_OK);
        return 0;
    }

    // create new surface by loading the image
    result = Device->CreateOffscreenPlainSurface(
                     imageInfo.Width,
                     imageInfo.Height,
                     D3DFMT_X8R8G8B8,
                     D3DPOOL_DEFAULT,
                     &image,
                     0);
    
    if (FAILED(result))
    {
        MessageBox(hWnd, _TEXT("Error creating surface"), _TEXT("LPDIRECT3DSURFACE9 Error"), MB_OK);
        return 0;
    }

    // draw the surface to the backbuffer [DEBUG]
    Device->StretchRect(image, 0, Backbuffer, 0, D3DTEXF_NONE);
    
    return image;
}

void DXGraphics::Render(LPDIRECT3DSURFACE9 SurfaceToDraw)
{
    if (Device->BeginScene())
    {
        Device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &Backbuffer);
        Device->StretchRect(SurfaceToDraw, 0, Backbuffer, 0, D3DTEXF_NONE);
        Device->EndScene();
    }
}

void DXGraphics::Present()
{
    Device->Present(0, 0, 0, 0);
}

[/spoiler]

 

Definitions.hpp

[spoiler]

/* Definitions.hpp
   - important dependencies and definitions and stuff
   */

#ifndef DEFINITIONS_HPP
#define DEFINITIONS_HPP

#include <tchar.h>

#define FULLSCREEN true
#define SCREEN_WIDTH 1280
#define SCREEN_HEIGHT 800
#define KEY_DN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)

#endif

[/spoiler]

 

DXGraphics.hpp

[spoiler]

/* DXGraphics.hpp
   - contains all the dependencies for DirectX graphics
   - contains functions for loading and drawing images
   */

#ifndef DXGRAPHICS_HPP
#define DXGRAPHICS_HPP

#include <d3d9.h>
#include <d3dx9.h>
#include "Definitions.hpp"

class DXGraphics
{

public:
   ~DXGraphics();
    bool Init(HWND hWnd);

    LPDIRECT3DTEXTURE9 LoadTexture(char* location, D3DCOLOR transparency);
    LPDIRECT3DSURFACE9 LoadSurface(char* location, HWND hWnd);

    void Render(LPDIRECT3DSURFACE9 SurfaceToDraw);
    //void Render(LPDIRECT3DTEXTURE9 TextureToDraw);
    void Present();

private:
    LPDIRECT3D9              Object;
    LPDIRECT3DDEVICE9     Device;
    LPDIRECT3DSURFACE9    Backbuffer;
    LPD3DXSPRITE          SpriteHandler;
    D3DPRESENT_PARAMETERS Parameters;
};

#endif

[/spoiler]

 

This is the image I am simply trying to draw; as you can see, it is clearly not just black:

mufntron.bmp

[spoiler]

MgzRT.png

[/spoiler]

 

 

FIXED:

 

Okay, I feel a little dumb. I forgot to add in the D3DXLoadSurfaceFromFile() function. Sorry. I was freaking out for nothing, lol.

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