Thread: Please help with my game

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    50

    Please help with my game

    ok. I am reading books and reading online tutorials and some is sinking in and some isn't. Windows programming is hard.

    Ok. I am trying to write a Falling objects game but don't want to just plagiarize it because where is the learning in that. I have all of my bitmaps drawn. I have the background bitmap and all of my objects drawn with PSP. I need to put them on the screen. Right now, I have my background drawn on a full screen. I want to get some animation going, though. I have a 40 x 40 pixel one block and would like just for learning purposes to animate that down the middle of the screen. Can someone help me do that ? It would greatly improve my learning curve. Right now I am moving like molasses.

    Here is the code that I have so far:

    Code:
    //  My Falling objects game
    
    // INCLUDES ///////////////////////////////////////////////
    #define WIN32_LEAN_AND_MEAN  
    #define INITGUID
    
    #include <windows.h>   // include important windows stuff
    #include <windowsx.h> 
    #include <mmsystem.h>
    #include <iostream.h> // include important C/C++ stuff
    #include <conio.h>
    #include <stdlib.h>
    #include <malloc.h>
    #include <memory.h>
    #include <string.h>
    #include <stdarg.h>
    #include <stdio.h>
    #include <math.h>
    #include <io.h>
    #include <fcntl.h>
    
    #include <ddraw.h>  // directX includes
    
    // DEFINES ////////////////////////////////////////////////
    
    // defines for windows 
    #define WINDOW_CLASS_NAME "WINXCLASS"  // class name
    
    #define WINDOW_WIDTH  640         // size of window
    #define WINDOW_HEIGHT 480
    #define SCREEN_WIDTH  640         // size of screen
    #define SCREEN_HEIGHT 480
    #define SCREEN_BPP    16          // bits per pixel
    
    #define BITMAP_ID     0x4D42      // universal id for a bitmap
    
    // MACROS /////////////////////////////////////////////////
    
    // these read the keyboard asynchronously
    #define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
    #define KEY_UP(vk_code)   ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
    
    // this builds a 16 bit color value in 5.5.5 format (1-bit alpha mode)
    #define _RGB16BIT555(r,g,b) ((b & 31) + ((g & 31) << 5) + ((r & 31) << 10))
    
    // this builds a 16 bit color value in 5.6.5 format (green dominate mode)
    #define _RGB16BIT565(r,g,b) ((b & 31) + ((g & 63) << 5) + ((r & 31) << 11))
    
    
    // TYPES //////////////////////////////////////////////////
    
    typedef unsigned short USHORT;
    typedef unsigned short WORD;
    typedef unsigned char  UCHAR;
    typedef unsigned char  BYTE;
    
    // container structure for bitmaps .BMP file
    typedef struct BITMAP_FILE_TAG
            {
            BITMAPFILEHEADER bitmapfileheader;  // this contains the bitmapfile header
            BITMAPINFOHEADER bitmapinfoheader;  // this is all the info including the palette
            PALETTEENTRY     palette[256];      // we will store the palette here
            UCHAR            *buffer;           // this is a pointer to the data
    
            } BITMAP_FILE, *BITMAP_FILE_PTR;
    
    // PROTOTYPES /////////////////////////////////////////////
    
    int Game_Init(void *parms=NULL);
    int Game_Shutdown(void *parms=NULL);
    int Game_Main(void *parms=NULL);
    
    int Load_Bitmap_File(BITMAP_FILE_PTR bitmap, char *filename);
    int Unload_Bitmap_File(BITMAP_FILE_PTR bitmap);
    int Flip_Bitmap(UCHAR *image, int bytes_per_line, int height);
    
    // GLOBALS ////////////////////////////////////////////////
    
    HWND main_window_handle = NULL; // save the window handle
    HINSTANCE main_instance = NULL; // save the instance
    char buffer[80];                // used to print text
    
    LPDIRECTDRAW7        lpdd         = NULL;  // dd object
    LPDIRECTDRAWSURFACE7 lpddsprimary = NULL;  // dd primary surface
    LPDIRECTDRAWSURFACE7 lpddsback    = NULL;  // dd back surface
    LPDIRECTDRAWPALETTE  lpddpal      = NULL;  // a pointer to the created dd palette
    DDSURFACEDESC2       ddsd;                 // a direct draw surface description struct
    DDSCAPS2             ddscaps;              // a direct draw surface capabilities struct
    HRESULT              ddrval;               // result back from dd calls
    UCHAR                *primary_buffer = NULL; // primary video buffer
    BITMAP_FILE          bitmap16bit;            // a 16 bit bitmap file
    
    // 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:
             {
             // start painting
             hdc = BeginPaint(hwnd,&ps);
    
             // end painting
             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
    HDC      hdc;       // generic dc
    PAINTSTRUCT ps;     // generic paintstruct
    
    // 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	= (HBRUSH)GetStockObject(BLACK_BRUSH);
    winclass.lpszMenuName	= NULL; 
    winclass.lpszClassName	= WINDOW_CLASS_NAME;
    
    // register the window class
    if (!RegisterClass(&winclass))
    	return(0);
    
    // create the window, note the use of WS_POPUP
    if (!(hwnd = CreateWindow(WINDOW_CLASS_NAME, // class
    						  "WinX Game Console",	 // title
    						  WS_POPUP | WS_VISIBLE,
    					 	  0,0,	   // x,y
    						  WINDOW_WIDTH,  // width
                              WINDOW_HEIGHT, // height
    						  NULL,	   // handle to parent 
    						  NULL,	   // handle to menu
    						  hinstance,// instance
    						  NULL)))	// creation parms
    return(0);
    
    // hide the mouse
    ShowCursor(FALSE);
    
    // save the window handle and instance in a global
    main_window_handle = hwnd;
    main_instance      = hinstance;
    
    // perform all game console specific initialization
    Game_Init();
    
    // 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
        
        // main game processing goes here
        Game_Main();
    
    	} // end while
    
    // shutdown game and release all resources
    Game_Shutdown();
    
    // return to Windows like this
    return(msg.wParam);
    
    } // end WinMain
    
    // WINX GAME PROGRAMMING CONSOLE FUNCTIONS ////////////////
    
    int Game_Init(void *parms)
    {
    // this function is where you do all the initialization 
    // for your game
    
    // create object and test for error
    if (DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, 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(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP,0,0)!=DD_OK)
       return(0);
    
    // Create the primary surface
    memset(&ddsd,0,sizeof(ddsd));
    ddsd.dwSize         = sizeof(ddsd);
    ddsd.dwFlags        = DDSD_CAPS;
    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
    
    if (lpdd->CreateSurface(&ddsd,&lpddsprimary,NULL)!=DD_OK)
       return(0);
    
    // now load the 16 bit color bitmap
    Load_Bitmap_File(&bitmap16bit, "tetrisgood640x480.BMP");
    Load_Bitmap_File(&bitmap16bit, "tetrisblockred.bmp");
    
    
    
    
    // return success
    return(1);
    
    } // end Game_Init
    
    ///////////////////////////////////////////////////////////
    
    int Game_Shutdown(void *parms)
    {
    // this function is where you shutdown your game and
    // release all resources that you allocated
    
    // first release the primary surface
    if (lpddsprimary!=NULL)
       lpddsprimary->Release();
           
    // release the directdraw object
    if (lpdd!=NULL)
       lpdd->Release();
    
    // delete the bitmap 
    Unload_Bitmap_File(&bitmap16bit);
    
    // return success
    return(1);
    } // end Game_Shutdown
    
    ///////////////////////////////////////////////////////////
    
    
    int Game_Main(void *parms)
    {
    // this is the workhorse of your game it will be called
    // continuously in real-time this is like main() in C
    // all the calls for you game go here!
    
    // check of user is trying to exit
    if (KEY_DOWN(VK_ESCAPE) || KEY_DOWN(VK_SPACE))
        PostMessage(main_window_handle, WM_DESTROY,0,0);
    
    // set up the surface description to lock the surface
    memset(&ddsd,0,sizeof(ddsd)); 
    ddsd.dwSize = sizeof(ddsd);
    
    // lock the primary surface, note in a real game you would
    lpddsprimary->Lock(NULL,&ddsd, 
                       DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL);
    
    // get video pointer
    primary_buffer = (UCHAR *)ddsd.lpSurface;
    
    // copy each bitmap line into primary buffer 
    // taking into consideration non-linear video 
    // cards and the memory pitch lPitch
    for (int y=0; y < SCREEN_HEIGHT; y++)
        {
        // copy the line
        memcpy(&primary_buffer[y*ddsd.lPitch], // dest address
               &bitmap16bit.buffer[y*SCREEN_WIDTH*2],   // src address
               SCREEN_WIDTH*2);                         // bytes to copy
        } // end for y
    
    // unlock the surface
    lpddsprimary->Unlock(NULL);
    
    // return success
    return(1);
    
    } // end Game_Main
    
    ///////////////////////////////////////////////////////////
    
    int Load_Bitmap_File(BITMAP_FILE_PTR bitmap, char *filename)
    {
    // this function opens a bitmap file and loads the data into bitmap
    
    int file_handle,  // the file handle
        index;        // looping index
    
    UCHAR *temp_buffer = NULL; // used to convert 24 bit images to 16 bit
    OFSTRUCT file_data;        // the file data information
    
    // open the file if it exists
    if ((file_handle = OpenFile(filename,&file_data,OF_READ))==-1)
       return(0);
    
    // now load the bitmap file header
    _lread(file_handle, &bitmap->bitmapfileheader,sizeof(BITMAPFILEHEADER));
    
    // test if this is a bitmap file
    if (bitmap->bitmapfileheader.bfType!=BITMAP_ID)
       {
       // close the file
       _lclose(file_handle);
    
       // return error
       return(0);
       } // end if
    
    // now we know this is a bitmap, so read in all the sections
    
    // first the bitmap infoheader
    
    // now load the bitmap file header
    _lread(file_handle, &bitmap->bitmapinfoheader,sizeof(BITMAPINFOHEADER));
    
    // now load the color palette if there is one
    if (bitmap->bitmapinfoheader.biBitCount == 8)
       {
       _lread(file_handle, &bitmap->palette,256*sizeof(PALETTEENTRY));
    
       // now set all the flags in the palette correctly and fix the reversed 
       // BGR RGBQUAD data format
       for (index=0; index < 256; index++)
           {
           // reverse the red and green fields
           int temp_color = bitmap->palette[index].peRed;
           bitmap->palette[index].peRed  = bitmap->palette[index].peBlue;
           bitmap->palette[index].peBlue = temp_color;
           
           // always set the flags word to this
           bitmap->palette[index].peFlags = PC_NOCOLLAPSE;
           } // end for index
    
        } // end if
    
    // finally the image data itself
    _lseek(file_handle,-(int)(bitmap->bitmapinfoheader.biSizeImage),SEEK_END);
    
    // now read in the image, if the image is 8 or 16 bit then simply read it
    // but if its 24 bit then read it into a temporary area and then convert
    // it to a 16 bit image
    
    if (bitmap->bitmapinfoheader.biBitCount==8 || bitmap->bitmapinfoheader.biBitCount==16)
       {
       // allocate the memory for the image
       if (!(bitmap->buffer = (UCHAR *)malloc(bitmap->bitmapinfoheader.biSizeImage)))
          {
          // close the file
          _lclose(file_handle);
    
          // return error
          return(0);
          } // end if
    
       // now read it in
       _lread(file_handle,bitmap->buffer,bitmap->bitmapinfoheader.biSizeImage);
    
       } // end if
    else
       {
       // this must be a 24 bit image, load it in and convert it to 16 bit
    //   printf("\nconverting 24 bit image...");
    
       // allocate temporary buffer
       if (!(temp_buffer = (UCHAR *)malloc(bitmap->bitmapinfoheader.biSizeImage)))
          {
          // close the file
          _lclose(file_handle);
    
          // return error
          return(0);
          } // end if
       
       // allocate final 16 bit storage buffer
       if (!(bitmap->buffer=(UCHAR *)malloc(2*bitmap->bitmapinfoheader.biWidth*bitmap->bitmapinfoheader.biHeight)))
          {
          // close the file
          _lclose(file_handle);
    
          // release working buffer
          free(temp_buffer);
    
          // return error
          return(0);
          } // end if
    
       // now read it in
       _lread(file_handle,temp_buffer,bitmap->bitmapinfoheader.biSizeImage);
    
       // now convert each 24 bit RGB value into a 16 bit value
       for (index=0; index<bitmap->bitmapinfoheader.biWidth*bitmap->bitmapinfoheader.biHeight; index++)
           {
           // extract RGB components (note they are in memory BGR)
           // also, assume 5.6.5 format, so scale appropriately
           UCHAR red    = (temp_buffer[index*3 + 2] >> 3), // 5 bits
                 green  = (temp_buffer[index*3 + 1] >> 2), // 6 bits, change to 3 for 5 bits
                 blue   = (temp_buffer[index*3 + 0] >> 3); // 5 bits
    
           // build up 16 bit color word assume 5.6.5 format
           USHORT color = _RGB16BIT565(red,green,blue);
    
           // write color to buffer
           ((USHORT *)bitmap->buffer)[index] = color;
    
           } // end for index
    
       // finally write out the correct number of bits
       bitmap->bitmapinfoheader.biBitCount=16;
    
       } // end if
    
    #if 0
    // write the file info out 
    printf("\nfilename:%s \nsize=%d \nwidth=%d \nheight=%d \nbitsperpixel=%d \ncolors=%d \nimpcolors=%d",
            filename,
            bitmap->bitmapinfoheader.biSizeImage,
            bitmap->bitmapinfoheader.biWidth,
            bitmap->bitmapinfoheader.biHeight,
    		bitmap->bitmapinfoheader.biBitCount,
            bitmap->bitmapinfoheader.biClrUsed,
            bitmap->bitmapinfoheader.biClrImportant);
    #endif
    
    // close the file
    _lclose(file_handle);
    
    // flip the bitmap
    Flip_Bitmap(bitmap->buffer, 
                bitmap->bitmapinfoheader.biWidth*(bitmap->bitmapinfoheader.biBitCount/8), 
                bitmap->bitmapinfoheader.biHeight);
    
    // return success
    return(1);
    
    } // end Load_Bitmap_File
    
    ///////////////////////////////////////////////////////////
    
    int Unload_Bitmap_File(BITMAP_FILE_PTR bitmap)
    {
    // this function releases all memory associated with "bitmap"
    if (bitmap->buffer)
       {
       // release memory
       free(bitmap->buffer);
    
       // reset pointer
       bitmap->buffer = NULL;
    
       } // end if
    
    // return success
    return(1);
    
    } // end Unload_Bitmap_File
    
    ///////////////////////////////////////////////////////////
    
    
    int Flip_Bitmap(UCHAR *image, int bytes_per_line, int height)
    {
    // this function is used to flip upside down .BMP images
    
    UCHAR *buffer; // used to perform the image processing
    int index;     // looping index
    
    // allocate the temporary buffer
    if (!(buffer = (UCHAR *)malloc(bytes_per_line*height)))
       return(0);
    
    // copy image to work area
    memcpy(buffer,image,bytes_per_line*height);
    
    // flip vertically
    for (index=0; index < height; index++)
        memcpy(&image[((height-1) - index)*bytes_per_line],
               &buffer[index*bytes_per_line], bytes_per_line);
    
    
    // release the memory
    free(buffer);
    
    // return success
    return(1);
    
    
    
    
    } // end Flip_Bitmap
    My small bitmap is called oneblocktetris.bmp

    Thank you for any replies.

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    Do you know C++? What you want to do is abstract out some of the window's code. But you should first read further in your books, since directx has hardware video blits which means you don't have to use memcpy.

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    50
    Not as well as I should. The whole purpose of doing this for me is to learn C++ and learn direct X . I have about 5 books - some on direct x and some on C++ . I have done some of their sample programs on accounting and crap like that. It is so boring to me. I know about loops. I know a little about classes. Don't really know about Inheritance or Encapsulation, though.


    Question # 2

    Why would I get a linking error when compiling a program ? Not this program but another one. It says:


    Linking...
    bitmapanim.obj : error LNK2001: unresolved external symbol _DirectDrawCreateEx@16
    Debug/bitmap animation.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.

    bitmap animation.exe - 2 error(s), 0 warning(s)


    I've added the bitmap to the project. I hate these stupid linking errors.

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Quote Originally Posted by jjj93421
    Question # 2

    Why would I get a linking error when compiling a program ? Not this program but another one. It says:


    Linking...
    bitmapanim.obj : error LNK2001: unresolved external symbol _DirectDrawCreateEx@16
    Debug/bitmap animation.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.

    bitmap animation.exe - 2 error(s), 0 warning(s)


    I've added the bitmap to the project. I hate these stupid linking errors.
    That means you aren't linking to the appropriate directx libs. I don't know what compiler you are using but you should be able to read your docs and find out how to link to libraries very easily.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  5. #5
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    Not as well as I should. The whole purpose of doing this for me is to learn C++ and learn direct X . I have about 5 books - some on direct x and some on C++ . I have done some of their sample programs on accounting and crap like that. It is so boring to me. I know about loops. I know a little about classes. Don't really know about Inheritance or Encapsulation, though.
    I would go with the C++ books first, athough you can probably learn both. Just continue reading Lamoth's book since it teaches you how to blit surfaces further in it. Anyways, what I did was write a directX wrapper like this in surface.h

    Code:
    class Surface {
            friend class Video;
    
            LPDIRECTDRAWSURFACE7 m_lpSurface;
            int m_width;
            int m_height;
            bool m_colorKey;
        public:
            /** Create an empty surface
             *  @param w width of the surface
             *  @param h height of the surface
             */
            Surface(int w, int h);
    
            /** Create a surface from a file
             *  @param filename filename the surface will be loaded from
             */
            Surface(const char* filename);
    
            /** Create a surface that has not been allocated */
            Surface() : m_lpSurface(0), m_width(0), m_height(0)
            { }
            ~Surface();
    
            /** Draw dstsurface onto this surface
             *  @param dstSurface  surface drawn onto this surface
             *  @param dstx        destination x-coordinate
             *  @param dsty        destination y-coordinate
             *  @return 0 on success, -1 on failure
             */
            int draw(Surface& dstSurface, int dstx, int dsty) const {
                  return draw(dstSurface, 0, 0, dstx, dsty,
                                      getWidth(), getHeight());
            }
            
            /** Draw dstSurface onto this surface
             *  @param srcx        source x-coordinate
             *  @param srcy        source y-coordinate
             *  @param dstx        destination x-coordinate
             *  @param dsty        destination y-coordinate
             *  @param w           width
             *  @param h           height
             *  @return 0 on success, -1 on failure
             */
            int draw(Surface& surface, int srcx, int srcy,
                int dstx, int dsty, int w, int h) const
            {
                RECT dstrect;
                dstrect.left   = dstx;
                dstrect.top    = dsty;
                dstrect.right  = dstx + w;
                dstrect.bottom = dsty + h;
    
                RECT srcrect;
                srcrect.left   = srcx;
                srcrect.top    = srcy;
                srcrect.right  = srcx + w;
                srcrect.bottom = srcy + h;
                DWORD flags = 0;
    
                if (m_colorKey) {
                    flags = DDBLT_KEYSRC;
                }
    
                DDBLTFX fx;
                ZeroMemory(&fx, sizeof fx);
                fx.dwSize = sizeof fx;
    
                surface.m_lpSurface->Blt(&dstrect, m_lpSurface,
                    &srcrect,
                    flags,
                    &fx);
    
                return 0;
            }
    
    
            /** Fill a surface with a given color represented by RGB 
             *  @param  r red color that must be between 0 and 255
             *  @param  g green color that must be between 0 and 255
             *  @param  b blue color that must be between 0 and 255
             */
            void fill(uint8 r, uint8 g, uint8 b);
    
            /** @return width of the surface */
            int getWidth() const;
    
            /** @return height of the surface */
            int getHeight() const;
    
            /** Set the color key of the surface, allowing transparent
             *  blits 
             *  @param r red color that must be between 0 and 255
             *  @param g green color that must be between 0 and 255
             *  @param b blue color that must be between 0 and 255
             */
            void setColorKey(uint8 r, uint8 g, uint8 b);
    
            void textout(const char* str) {
                HDC hdc;
                m_lpSurface->GetDC(&hdc);
                TextOut(hdc, 0, 0, str, 12);
                m_lpSurface->ReleaseDC(hdc);
            }
        };
    
    
        class Video {
            static Surface* m_primary;
            static Surface* m_secondary;
        public:
            /** Set the display mode
             *  @param xres x resolution
             *  @param yres y resoulution
             *  @param bpp  bits per pixel */
            static void setDisplayMode(int xres, int yres, int bpp);
    
            /** Destroy the video context, relinquishing control over DirectX
             */
            static void destroy();
    
            /** Flip the surface, allowing the previously unshown back buffer to become
             *  the front buffer */
            static void flip();
    
            /** @return primary surface */
            static Surface* getPrimary()   { return m_primary; }
    
            /** @return secondary surface which will be used for drawing */
            static Surface* getSecondary() { return m_secondary; }
    
            /** @return width of the graphical context */
            static int getWidth() {
                return m_secondary->getWidth();
            }
    
            /** @return height of the graphical context */
            static int getHeight() {
                return m_secondary->getHeight();
            }
        };
    Although in surface.cpp it depends on the global g_hwnd and you still have to register and create the window using the winapi and it's not too flexible yet, it's much easier to use compared to the just using the directx api.

    For most functions such as setting the window mode it's not necessary they be fast. However, I inlined the draw method function, hoping the compile will be able to optimize biltting a large number of tiles in a loop.

    Linking shouldn't be too hard. Most likely you want to link winmm.lib ddraw.lib dinput.lib dxguid.lib
    Last edited by okinrus; 04-12-2004 at 04:15 AM.

  6. #6
    Registered User
    Join Date
    Mar 2004
    Posts
    50
    thanks Okinrus and MrWizard

    You were right. I forgot to add winmm.lib ddraw.lib dinput.lib dxguid.lib to the project settings Link tab.

    I've done that before just didn't think I needed to do it everytime. Is there a way to permanently include those libraries in the settings ?

    I have skipped around in the "C++ : A beginner's Guide" book but for going page after page, I am on page 90 of about 500 pages. I skipped to classes and loops. It just gets boring making program after program with interest rate formulas.

    These are the books I have:

    C++: A beginners guide
    Windows Game Programming for Dummies by Andre LaMothe
    3D Programming with C++ by Andre LaMothe
    The Complete Reference C++ by Herbert Schildt
    C++ for Dummies

    (like the dummies books.....)

    Is Andre LaMothe some kind of programming God ?

    Anyway, got the program to compile. It animates a bitmap so tomorrow I am going to look at that. I need a printer to print these programs out to look at them better. I have a Bachelor's in Mathematics but I only took one CS class and that was pascal. I figure once I get the coding down, I can rig some neat games maybe. Fake it you know. Fake physics or something

  7. #7
    Registered User
    Join Date
    Mar 2004
    Posts
    50

    Can I use direct X with console apps instead?

    thanks for the wrapper Okinrus

    Do you care if I use that?

    I copied it for later use if you don't mind.

    In my opinion, there is too much going on in direct x.

    Also, can I use direct X with a console App? Console Apps make so much more sense to me. In this instructional cd, there was a console app game and it was easy for me to understand. In windows apps, there are so many headers and huge variables like lsppdprimary or something.

    There is so much emphasis on drawing to the buffer . I think a book needs to be written about drawing directly to the screen so a newbie can get that down first then do buffering.

  8. #8
    Registered User heat511's Avatar
    Join Date
    Dec 2001
    Posts
    169
    Quote Originally Posted by jjj93421
    Is there a way to permanently include those libraries in the settings?
    hmmmmm... not that i know of, altho ultimately it depends on your compiler so maybe you can find one with that option. of course it would add those libs to all your projects which would be kinda bad. i use the below code to link libs in the declarations of opengl code. of course you'll need to change the libs to the directx ones, but it should work.

    Code:
    #pragma comment(lib, "OpenGL32.lib") 
    #pragma comment(lib, "GLu32.lib") 
    #pragma comment(lib, "GLaux.lib")
    "uh uh uh, you didn't say the magic word"
    -Jurassic Park

  9. #9
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    No, it's ok. I'll probably release the entire sourcecode of my project using the GNU license, but some parts such as the wrapper are pretty much public domain(most of the code is from the window's help file). I didn't post the surface.cpp since its dependent on exception classes. The code I posted is pretty much project specific, so you will have to make some changes.

    Also, can I use direct X with a console App? Console Apps make so much more sense to me. In this instructional cd, there was a console app game and it was easy for me to understand. In windows apps, there are so many headers and huge variables like lsppdprimary or something.
    I don't think so.


    Is Andre LaMothe some kind of programming God ?
    I think so. I have some complaints about his code, mainly the lack of C++ abstractions(he explains the audience is for both C and C++ programmers), but he's a professional I suppose.

    I have a Bachelor's in Mathematics but I only took one CS class and that was pascal. I figure once I get the coding down, I can rig some neat games maybe. Fake it you know. Fake physics or something
    I know Pascal, or at least I used to. You must have been in college quite a few years ago. My college doesn't even teach Pascal anymore.

  10. #10
    Registered User
    Join Date
    Mar 2004
    Posts
    50
    yeah, I was in college in 1995 while learning Pascal. I was at a technology school and decided Electrical Engineering wasn't for me and changed my major to math and changed schools, as well. They were teaching C, too but I had an option. Things were just starting to move and change at that time. We had what they called Next computers and the next year, all of the computers were moved out and the students had to buy laptops for $500 a piece. The school likes to stay on the cutting edge.

    I'm 27 but I'm still a kid.

  11. #11
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Lamothe's book will get into the hardware blitter later...but be forewarned it is NOT always faster than memcpy or the assembly language equivalent.


    The fastest blit I've found is actually to not use the hardware blitter. It seems with all the focus on 3D, the 2D portion of video cards has suffered or perhaps it is a direct result of being unable to do both extremely well.

    If you are blitting a large number of rects to the screen do not use the hardware blitter...if you are blitting a small number or 1 blit as in to clear the surface then use it.

    I know this does not sound right but trust me it is. The fastest way to use DirectX in 2D is to not use the hardware at all. Simply create the device, buffer, and back buffer - retrieve a pointer to the back buffer via Lock() and then use it just like you would in any DOS graphics code. This is not true with 3D as Direct3D is far faster than any software function you could code, but 2D is not so cut and dried as this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-08-2010, 12:08 AM
  2. Open Source / Semi Open source game idea. Help needed
    By CaptainPatent in forum Projects and Job Recruitment
    Replies: 10
    Last Post: 05-16-2007, 10:44 AM
  3. game engine advice?
    By stien in forum Game Programming
    Replies: 0
    Last Post: 01-23-2007, 03:46 PM
  4. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM