Skip to main content
gamedev.net
🔒 Locked

Direct Draw declaration problem

Started by GT70sgt Apr 27, 2004 at 8:49 PM 3 replies 1k views
Original Post
GT70sgt
GT70sgt
I use the ddraw tutorials from borland and typed in the code into my own project and its just like the other one, I did this just so I could learn to use it, and when it runs, it says that some of my variables are not declared...can somebody tell me whats wrong..I''ll show you the code and put *** by the basic ones that it says arent declared.
//---------------------------------------------------------------------------


#include <vcl.h>
#include <ddraw.h>
#pragma hdrstop

#include "main.h"
//---------------------------------------------------------------------------

#pragma resource "*.dfm"
#define TIMER_ID          1
#define TIMER_RATE        500
TFormMain *FormMain;
//---------------------------------------------------------------------------

__fastcall TFormMain::TFormMain(TComponent* Owner)
        : TForm(Owner)
{
  lpDD = NULL;   ***
  phase = 0;     ***
  bActive = false;   *** 
  FrontMsg = "Front buffer (F12 or Esc to Quit)";    ***
  BackMsg = "Back buffer (F12 or Esc to Quit)";     ***
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::FormDestroy(TObject *Sender)
{
  if(lpDD != NULL){
      if(lpDDSPrimary != NULL){
          lpDDSPrimary -> Release();
          lpDDSPrimary = NULL;
        }
      lpDD -> Release();
      lpDD = NULL;
    }
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::start()
{
  HRESULT ddrval;
  DDSURFACEDESC ddsd;
  DDSCAPS ddscaps;
  HDC DC;
  char buf[256];
  ddrval = DirectDrawCreate(NULL, &lpDD, NULL);
  if(ddrval == DD_OK){
      ddrval = lpDD -> SetCooperativeLevel(Handle, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
      if(ddrval == DD_OK){
          ddrval = lpDD -> SetDisplayMode(640, 480, 8);
          if(ddrval == DD_OK){
              ddsd.dwSize = sizeof(ddsd);
              ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
              ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
                                    DDSCAPS_FLIP |
                                    DDSCAPS_COMPLEX;
              ddsd.dwBackBufferCount = 1;
              ddrval = lpDD -> CreateSurface(&ddsd, &lpDDSPrimary, NULL);
              if(ddrval == DD_OK){
                  ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
                  ddrval = lpDDSPrimary -> GetAttachedSurface(&dscaps,
                                                              &lpDDSBack);
              if(ddrval == DD_OK){
                  //DRAWING TEXT

                  if(lpDDSPrimary -> GetDC(&DC) == DD_OK){
                      SetBkColor(DC, RGB(0, 0, 255));
                      SetTextColor(DC, RGB(255, 225, 0));
                      TextOut(DC, 0,0, FrontMsg.c_str(), FrontMsg.Length());
                      lpDDSPrimary -> ReleaseDC(DC);
                    }
                  if(lpDDSPrimary -> GetDC(&DC) == DD_OK){
                      SetBkColor(DC, RGB(0, 0, 255));
                      SetTextColor(DC, RGB(255, 225, 0));
                      TextOut(DC, 0,0, BackMsg.c_str(), BackMsg.Length());
                      lpDDSBack -> ReleaseDC(DC);
                    }
                  Timer1 -> Enabled = true;
                  bActive = true;
                  return;
                }
              }
            }
          }
        }
        wsprintf(buf, "Direct Draw Init Failed (%801x)\n", ddrval);
        MessageBox(Handle, buf, "Error", MB_OK);
        Close();
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::FormKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
  switch (Key){
      case VK_F3:
        start();
      break;
      case VK_ESCAPE:
      case VK_F12:
          Close();
      break;
    }
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::FormPaint(TObject *Sender)
{
  RECT rc;
  SIZE size;
  char szMsg[] = "Page Flipping Test: Press F3 to start, F12 or Esc to Exit";
  if(!bActive){
      HDC DC = GetDC(Handle);
      rc = GetClientRect();
      GetTextExtentPoint(DC, szMsg, lstrlen(szMsg), &size);
      SetBkColor(DC, RGB(0, 0, 0));
      SetTextColor(DC, RGB(255, 255, 0));
      TextOut(DC, (rc.right - size.cx)/2, (rc.bottom - size.cy)/2, szMsg, sizeof(szMsg)-1);
      ReleaseDC(Handle, DC);
    }
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::Timer1Timer(TObject *Sender)
{
  HDC DC;
  if(lpDDSBack -> GetDC(&DC) == DD_OK){
      if(phase){
          SetBkColor(DC, RGB(0, 0, 255));
          SetTextColor(DC, RGB(255, 225, 0));
          TextOut(DC, 0,0, FrontMsg.c_str(), FrontMsg.Length());
          phase = 0;
        }
      else{
          SetBkColor(DC, RGB(0, 0, 255));
          SetTextColor(DC, RGB(255, 225, 0));
          TextOut(DC, 0,0, BackMsg.c_str(), BackMsg.Length());
          phase = 1;
        }
      lpDDSBack -> ReleaseDC(DC);
    }
  while(1){
      HRESULT ddrval;
      ddrval = lpDDSPrimary -> Flip(NULL, 0);
      if(ddrval == DD_OK)
        break;
      if(ddrval == DDERR_SURFACELOST){
          ddrval = lpDDSPrimary -> Restore();
          if(ddrval != DD_OK)
            break;
        }
      if(ddrval != DDERR_WASSTILLDRAWING)
        break;
    }
}
//---------------------------------------------------------------------------

thats it, somebody help plz...!!...
C++ ProgrammerAIM - GT70sgtLead Guitar in Distorted Play
GT70sgt
GT70sgt
does anyone know what im trying figure out here...??
C++ ProgrammerAIM - GT70sgtLead Guitar in Distorted Play
Sailorstick
Sailorstick
I would make sure that this main.h you include actually has an include of TFormMain.h in it. If not, stick in a #include "TFormMain.h" at the start of the file you just posted.
Toonkides
Toonkides
What is tFormMain?

Anyway, it seems that you are missing some major declarations for ddraw. You need to declare the surface, device etc.

Go to www.gamedev.net -> Articles Resources -> Directx(directdraw). There are a few tutorials on the basics (outdated?), check them out and see how they declare the surface: LPDIRECTDRAWSURFACE lpPrimary; // etc. etc.

GT70sgt
GT70sgt
this is the exact code that is used in a different borland example that uses direct draw, and it works perfectally fine, but mine doesnt recgonize those variables...I will check out that ddraw stuff....

[edited by - GT70sgt on April 30, 2004 5:46:40 PM]
C++ ProgrammerAIM - GT70sgtLead Guitar in Distorted Play

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.