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

Archived

This topic is now archived and is closed to further replies.

jobu

displaying a bitmap

2 posts in this topic

I'm not very sure but shouldn't use call getDC from the directdraw pointer (lpdd) since you are creating a fullscreen app.

Also try checking return values of window functions.

0

Share this post


Link to post
Share on other sites
the GetDC() function should work just fine. there is no conflict between DD and GDI.

i did notice a few things in your code that are very likely the problem, or likely to cause problems.

first, you are using LoadBitmap, and you are passing the instance handle of your application. since the name of your bitmap is "imagerc.bmp", which is a file name, your bitmap is never getting loaded, since you have to load the bitmap from file, without passing an instance handle.

LoadImage(NULL,bname,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);

should work.

next, ever game loop, you are creating a new Compatible DC, and selecting the main bitmap into it. this is bad. you're leaking GDI resources. create the compatible DC *ONCE* in your init function, select the bitmap into it *ONCE*.

also, you arent putting all of your toys away when you are done. you need to store the return value of the SelectObject in something like hbmOld in your ginit function, and restore it in your cleanup function. when a compatible DC is created, a 1x1 monochrome bitmap is created along with it, selected in that DC. to replace, it, you put it somewhere else for safekeeping, and restore it when you are done with the DC (you dont have to use DeleteObject on it, the call to DeleteDC takes care of it for you).

0

Share this post


Link to post
Share on other sites
alright when i run my program it doesnt display my bitmap for some reason. is it easier for my bitmap to be called from a resource file a just straight from a file?
i also dont know if i called it right.


// INCLUDES ///////////////////////////////////////////////
#define WIN32_LEAN_AND_MEAN

#include (windows.h)
#include (windowsx.h)
#include (stdio.h)
#include (math.h)
#include (ddraw.h)
#include "resource.h"


char bname[]="imagerc.bmp";
HBITMAP hbitmap;
static BITMAP bm;
HDC hdc;
HDC hmdc;
HWND hwnd;


int ginit(void *parms=NULL);
int gshutdown(void *parms=NULL);
int gmain(void *parms=NULL);
// DEFINES ////////////////////////////////////////////////

// defines for windows
#define WINDOW_CLASS_NAME "WINCLASS1"
#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
#define swidth 640
#define sheight 480
#define bpp 16

// GLOBALS ////////////////////////////////////////////////
HWND main_window_handle = NULL; // save the window handle
LPDIRECTDRAW lpdd;
// FUNCTIONS //////////////////////////////////////////////
LRESULT CALLBACK WindowProc(HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam)
{
// this is the main message handler of the system
PAINTSTRUCT ps; // used in WM_PAINT
HDC hdc; // handle to a device context

// what is the message
switch(msg)
{
case WM_CREATE:
{
// do initialization stuff here
return(0);
} break;

case WM_PAINT:
{
// simply validate the window
hdc = BeginPaint(hwnd,&ps);
EndPaint(hwnd,&ps);
return(0);
} break;

case WM_DESTROY:
{
// kill the application
PostQuitMessage(0);
return(0);
} break;

default:break;

} // end switch

// process any messages that we didn't take care of
return (DefWindowProc(hwnd, msg, wparam, lparam));

} // end WinProc

// WINMAIN ////////////////////////////////////////////////
int WINAPI WinMain( HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int ncmdshow)
{

WNDCLASS winclass; // this will hold the class we create
HWND hwnd; // generic window handle
MSG msg; // generic message
hbitmap=LoadBitmap(hinstance,bname);

// first fill in the window class stucture
winclass.style = CS_DBLCLKS | CS_OWNDC |
CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hinstance;
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
winclass.hbrBackground = GetStockObject(WHITE_BRUSH);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = WINDOW_CLASS_NAME;

// register the window class
if (!RegisterClass(&winclass))
return(0);

// create the window
if (!(hwnd = CreateWindow(WINDOW_CLASS_NAME, // class
"Hello", // title
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
0,0, // x,y
640,480, // width, height
NULL, // handle to parent
NULL, // handle to menu
hinstance,// instance
NULL))) // creation parms
return(0);

// save the window handle in a global
main_window_handle = hwnd;
ginit();
// enter main event loop
while(1)
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
// test if this is a quit
if (msg.message == WM_QUIT)
break;

// translate any accelerator keys
TranslateMessage(&msg);

// send the message to the window proc
DispatchMessage(&msg);
} // end if
gmain();
// main game processing goes here

} // end while
gshutdown();
// return to Windows like this
return(msg.wParam);
}


int ginit(void *parms)
{
// this function is where you do all the initialization
// for your game

// create object and test for error
if (DirectDrawCreate(NULL,&lpdd,NULL)!=DD_OK)
return(0);

// set cooperation level to windowed mode normal
if ((lpdd->SetCooperativeLevel(main_window_handle,
DDSCL_ALLOWMODEX | DDSCL_FULLSCREEN |
DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT))!=DD_OK)
return(0);

// set the display mode
if ((lpdd->SetDisplayMode(swidth,sheight,bpp))!=DD_OK)
return(0);

// return success
return(1);
} // end Game_Init

///////////////////////////////////////////////////////////

int gshutdown(void *parms)
{
// this function is where you shutdown your game and
// release all resources that you allocated

// release the directdraw object
if (lpdd!=NULL)
lpdd->Release();
DeleteDC(hmdc);
DeleteObject(hbitmap);
// return success
return(1);
} // end Game_Shutdown

///////////////////////////////////////////////////////////

int gmain(void *parms)
{

hdc=GetDC(hwnd);
hmdc=CreateCompatibleDC(hdc);
SelectObject(hmdc,hbitmap);
GetObject(hbitmap,sizeof(bm),(LPSTR) &bm);
BitBlt(hdc,0,0,bm.bmWidth,bm.bmHeight,hmdc,0,0,SRCCOPY);

if (KEY_DOWN(VK_ESCAPE) | | KEY_DOWN(VK_SPACE))
PostMessage(main_window_handle, WM_DESTROY,0,0);


ReleaseDC(hwnd,hdc);
// return success
return(1);
} // end Game_Main

///////////////////////////////////////////////////////////



0

Share this post


Link to post
Share on other sites