// These are all the includes we need. One for the basic Windows stuff
// (which we will use as rarely as possible, I'm not a fan of the Windows
// API) and one for Direct3D 8.
define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
include <windows.h>
include <D3DX8.h>
// This is causes the d3d8.lib to be linked in, the same thing can be accomplished by
// adding it to your compiler's link list (Project->Settings->Link in VC++),
// but I prefer this method.
pragma comment(lib,"d3d8.lib")
pragma comment(lib,"d3dx8.lib")
// Forward declarations for all of our functions, see their definitions for more detail
void FatalError(const char p_error_msg);
void FatalError(HRESULT p_hr,const char p_error_msg);
bool ask_fullscreen(void);
LRESULT CALLBACK default_window_proc(HWND p_hwnd,UINT p_msg,WPARAM p_wparam,LPARAM p_lparam);
void init_window(bool p_fullscreen);
void kill_window(void);
void init_d3d(bool p_fullscreen);
void kill_d3d(void);
void init_scene(void);
void kill_scene(void);
void message_pump(void);
D3DFORMAT find_16bit_mode(void);
void render(void);
void NOP(HINSTANCE p_prev_instance,LPSTR p_cmd_line,int p_show);
// The name of our application. Used for window titles, MessageBox titles and
// error reporting
const char g_app_name[]="DirectX 8 Lesson 2a";
// Our screen/window sizes. A better app would allow the user to choose the
// sizes. I'll do that in a later tutorial, for now this is good enough.
const int g_width=640;
const int g_height=480;
// A global handle to our main window, initializing pointers to NULL can save you
// a lot of hassle in the future.
HWND g_main_window=NULL;
// A global handle to our 'instance'. This is needed in various places by the Windows API.
HINSTANCE g_instance;
// Our global flag to track whether we should quit or not. When it becomes true, we clean
// up and exit.
bool g_app_done=false;
// Our main Direct3D interface, it doesn't do much on its own, but all the more commonly
// used interfaces are created by it. It's the first D3D object you create, and the last
// one you release.
IDirect3D8 *g_D3D=NULL;
// The D3DDevice is your main rendering interface. It represents the display and all of its
// capabilities. When you create, modify, or render any type of resource, you will likely
// do it through this interface.
IDirect3DDevice8 *g_d3d_device=NULL;
//Declare a structure to hold a vertex with all the information that we need
struct my_vertex{
FLOAT x, y, z, rhw; // The transformed position for the vertex.
DWORD colour; // The vertex colour.
};
//A handy little 'macro' for our definition of the vertex. When we use the vertex data
//we have to tell D3D what data we're passing it. D3DFVF_DIFFUSE specifies that the
//vertex will have a colour, the D3DFVF_XYZRHW specifies that the vertex will have
//coordinate given in screen space.
//The x & y values here are given in 'screen space'. Vertices in screen space
//are referred to as Transformed vertices. What this means is that the x and y
//coordinates are given as offsets from the top left of the screen. If you change
//these coordinates by adding 50 to each x value, you will move everything to the
//right by 50 pixels.
//With Transformed vertices, the z coordinate doesn't do much. If you have a Z Buffer
//it determines which objects block other objects, but changing the z coordinate will
//have no other effect. The visible size (given by the x,y coordinates) is static, so
//even though you can effectively move the object deeper into the screen, it will remain
//the same size.
//The colour for each vertex is given in Hex notation. Each pair of hex digits is another
//component of the colour. The components are Alpha, Red, Green and Blue, and they are
//organized like this: 0xAARRGGBB
my_vertex g_triangle_vertices[] ={
{ 125.0f, 50.0f, 0.5f, 1.0f, 0xFFFFFFFF }, // x, y, z, rhw, colour
{ 200.0f, 200.0f, 0.5f, 1.0f, 0xFFFFFFFF },
{ 50.0f, 200.0f, 0.5f, 1.0f, 0xFFFFFFFF }
};
//Direct3D does not support a Quad rendering primitive like OpenGL does. It does have
//Triangle Strips. In a Triangle Strip, the first 3 vertices form a triangle, and
//then each additional vertex adds a triangle formed by itself and the previous 2
//vertices. Thus to draw a square we need only 4 vertices.
my_vertex g_square_vertices[] ={
{ 250.0f, 200.0f, 0.5f, 1.0f, 0xFFFFFFFF }, // x, y, z, rhw, colour
{ 250.0f, 50.0f, 0.5f, 1.0f, 0xFFFFFFFF },
{ 400.0f, 200.0f, 0.5f, 1.0f, 0xFFFFFFFF },
{ 400.0f, 50.0f, 0.5f, 1.0f, 0xFFFFFFFF }
};
//Vertex buffers are a method of storing vertices to be rendered in an optimized manner.
IDirect3DVertexBuffer8 g_triangle=NULL;
IDirect3DVertexBuffer8 g_square=NULL;
// WinMain is the first function called by Windows when our app is run. It's the entry
// point of our application.
int APIENTRY WinMain(HINSTANCE p_instance,HINSTANCE p_prev_instance,LPSTR p_cmd_line,int p_show){
bool full_screen;
// Set our global instance handle so we don't have to pass it around
g_instance=p_instance;
//This function exists to quiet compiler warnings, see its definition for more detail
NOP(p_prev_instance,p_cmd_line,p_show);
// Prompt the user, Full Screen? Windowed? Cancel?
full_screen=ask_fullscreen();
// Build our window. Cover the screen if full-screen, otherwise make a standard window
init_window(full_screen);
//Build the D3D objects we'll require
init_d3d(full_screen);
//One-time preparation of objects and other stuff required for rendering
init_scene();
//Loop until the user aborts (closes the window or hits a key)
while(!g_app_done){
//Check for window messages
message_pump();
//Draw our incredibly cool graphics
render();
}
//Clean up all of our scene objects/resources
kill_scene();
//Clean up all of our Direct3D objects
kill_d3d();
//Close down our window
kill_window();
//Exit happily
return 0;
}
// Procedure: NOP
// Whazzit:This procedure does nothing. If set to a high warning level
// (which I like to do) the compiler will complain because the
// parameters passed into WinMain are never used. The purpose
// of this procedure is to make it think that they are used, so
// it doesn't complain.
void NOP(HINSTANCE p_prev_instance,LPSTR p_cmd_line,int p_show){
// Procedure: message_pump
// Whazzit:Checks the message queue to see if any windows messages
// (window is closing, window needs repainting, etc)
// are waiting and if there are, the messages are dispatched
// to our message handler.
void message_pump(void){
MSG msg;
// Function: init_window
// Whazzit:Registers a window class and then creates our window.
void init_window(bool p_fullscreen){
ULONG window_width, window_height;
WNDCLASS window_class;
DWORD style;
//Fill in all the fields for the WNDCLASS structure. Window classes
//are a sort of template for window creation. You could create many
//windows using the same window class.
window_class.style = CS_OWNDC;
window_class.cbClsExtra = 0;
window_class.cbWndExtra = 0;
window_class.hInstance = g_instance;
window_class.hIcon = LoadIcon(NULL,IDI_APPLICATION);
window_class.hCursor = LoadCursor(NULL,IDC_ARROW);
window_class.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
window_class.lpszMenuName = NULL;
window_class.lpszClassName = "DH Class";
//Here we provide our default window handler, all windows messages
//will be sent to this function.
window_class.lpfnWndProc = default_window_proc;
//Register the class with windows
if(!RegisterClass(&window_class)){
FatalError("Error registering window class");
}
//If we're running full screen, we cover the desktop with our window.
//This isn't necessary, but it provides a smoother transition for the
//user, especially when we're going to change screen modes.
if(p_fullscreen){
window_width=GetSystemMetrics(SM_CXSCREEN);
window_height=GetSystemMetrics(SM_CYSCREEN);
style=WS_POPUP;
}else{
//In windowed mode, we just make the window whatever size we need.
window_width=g_width;
window_height=g_height;
style=WS_OVERLAPPED|WS_SYSMENU;
}
//Here we actually create the window. For more detail on the various
//parameters please refer to the Win32 documentation.
g_main_window=CreateWindow("DH Class", //name of our registered class
g_app_name, //Window name/title
style, //Style flags
0, //X position
0, //Y position
window_width,//width of window
window_height,//height of window
NULL, //Parent window
NULL, //Menu
g_instance, //application instance handle
NULL); //pointer to window-creation data
//The next 3 lines just make sure that our window is visible and has the
//input focus. It's not strictly necessary, but it doesn't hurt to be
//thorough.
ShowWindow(g_main_window,SW_SHOW);
UpdateWindow(g_main_window);
SetFocus(g_main_window);
}
// Function: kill_window
// Whazzit:Closes the window, clean up any waiting messages, and then unregister
// our window class. Note - This is not the standard Win32 way of cleaning
// up your window. The standard way involves putting the clean-up code in
// your window handler. With this method, we destroy what we create.
void kill_window(void){
//Test if our window is valid
if(g_main_window){
if(!DestroyWindow(g_main_window)){
//We failed to destroy our window, this shouldn't ever happen
OutputDebugString(" Failed to DestroyWindow\n");
MessageBox(NULL,"Destroy Window Failed",g_app_name,MB_OK|MB_ICONERROR|MB_TOPMOST);
}else{
MSG msg;
//Clean up any pending messages
while(PeekMessage(&msg, NULL, 0, 0,PM_REMOVE)){
DispatchMessage(&msg);
}
}
//Set our window handle to NULL just to be safe
g_main_window=NULL;
}
//Unregister our window, if we had opened multiple windows using this
//class, we would have to close all of them before we unregistered the class.
if(!UnregisterClass("DH Class",g_instance)){
OutputDebugString(" Failed to Unregister Window\n");
MessageBox(NULL,"Unregister Failed",g_app_name,MB_OK|MB_ICONERROR|MB_TOPMOST);
}
}
// Function:init_d3d
// Whazzit:Sets up Direct3D and creates the device. The device is created differently
// if we're full-screen as opposed to running in a desktop window.
void init_d3d(bool p_fullscreen){
HRESULT hr;
D3DPRESENT_PARAMETERS d3dpp;
D3DDISPLAYMODE display_mode;
//Create Direct3D8, this is the first thing you have to do in any D3D8 program
g_D3D = Direct3DCreate8( D3D_SDK_VERSION );
if(!g_D3D ){
FatalError("Error getting Direct3D");
}
//Get the current(desktop) display mode. This is only needed if
//we're running in a window.
hr=g_D3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&display_mode);
if(FAILED(hr)){
FatalError(hr,"Error getting display mode");
}
//Clear out our D3DPRESENT_PARAMETERS structure. Even though we're going
//to set virtually all of its members, it's good practice to zero it out first.
ZeroMemory(&d3dpp,sizeof(d3dpp));
//Whether we're full-screen or windowed these are the same.
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; // Throw away previous frames, we don't need them
d3dpp.hDeviceWindow = g_main_window; //This is our main (and only) window
d3dpp.BackBufferCount= 1; //We only need a single back buffer
// BackBufferWidth/Height have to be set for full-screen apps, these values are
//used (along with BackBufferFormat) to determine the display mode.
//They aren't needed in windowed mode since the size of the window will be used.
// BackBufferFormat is the pixel format we want.
if(p_fullscreen){
d3dpp.Windowed = FALSE;
d3dpp.BackBufferWidth = g_width;
d3dpp.BackBufferHeight = g_height;
//In full-screen we need to find a pixel format we like, see find_16bit_mode()
//below for more details.
d3dpp.BackBufferFormat = find_16bit_mode();
}else{
d3dpp.Windowed = TRUE;
//In windowed mode we use the same format as the desktop, which we found
//by using GetAdapterDisplayMode() above.
d3dpp.BackBufferFormat = display_mode.Format;
}
hr=g_D3D->CreateDevice(D3DADAPTER_DEFAULT, //The default adapter, on a multimonitor system
//there can be more than one.
//Use hardware acceleration rather than the software renderer
D3DDEVTYPE_HAL,
//Our Window
g_main_window,
//Process vertices in software. This is slower than in hardware,
//But will work on all graphics cards.
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
//Our D3DPRESENT_PARAMETERS structure, so it knows what we want to build
&d3dpp,
//This will be set to point to the new device
&g_d3d_device);
if(FAILED(hr)){
FatalError(hr,"Error creating device");
}
}
// Function:kill_d3d
// Whazzit:Releases all of our D3D resources in the opposite order from their creation.
// Note-Since we initially set the pointers to be NULL, we can safely test them
// for a non-NULL state and we know if they've been created. Thus we never Release
// something we didn't create (which causes bad things to happen).
void kill_d3d(void){
}
// Function:init_scene
// Whazzit:One-time preparation of objects required for rendering. In this tutorial we prepare
// 2 objects:a triangle & a square.
void init_scene(void){
HRESULT hr;
unsigned char *vb_vertices;
//As mentioned above, a Vertex Buffer is an optimized storage medium for vertices.
//Here we create a vertex buffer large enough to hold 3 vertices. We specify that
//it can only be written to and we allow Direct3D to determine where in memory
//it should be placed.
hr=g_d3d_device->CreateVertexBuffer(3*sizeof(my_vertex), //Size of memory to be allocated
// Number of vertices * size of a vertex
D3DUSAGE_WRITEONLY, // We never need to read from it so
// we specify write only, it's faster
D3D8T_CUSTOMVERTEX, //Our custom vertex specifier (coordinates & a colour)
D3DPOOL_MANAGED, //Tell DirectX to manage the memory of this resource
&g_triangle); //Pointer to our triangle, after this call
//It will point to a valid vertex buffer
if(FAILED(hr)){
FatalError(hr,"Error creating triangle vertex buffer");
}
//The only difference between this and the above call is that we're allocating
//enough space for 4 vertices instead of 3.
hr=g_d3d_device->CreateVertexBuffer(4*sizeof(my_vertex), //Size of memory to be allocated
// Number of vertices * size of a vertex
D3DUSAGE_WRITEONLY, // We never need to read from it so
// we specify write only, it's faster
D3D8T_CUSTOMVERTEX, //Our custom vertex specifier (coordinates & a colour)
D3DPOOL_MANAGED, //Tell DirectX to manage the memory of this resource
&g_square); //Pointer to our triangle, after this call
//It will point to a valid vertex buffer
if(FAILED(hr)){
FatalError(hr,"Error creating square vertex buffer");
}
//Now we have our Vertex Buffers, but they're empty. To put our data into them
//we Lock the Vertex Buffer so Direct3D knows we're modifying it, then we copy
//our data in and Unlock it so Direct3D knows we're done.
hr=g_triangle->Lock(0, //Offset, we want to start at the beginning
0, //SizeToLock, 0 means lock the whole thing
&vb_vertices, //If successful, this will point to the data in the VB
0); //Flags, nothing special
if(FAILED(hr)){
FatalError(hr,"Error Locking triangle buffer");
}
//vb_vertices now points to our vertices inside the Vertex buffer, so
//to fill in our VB, we copy to vb_vertices.
memcpy(vb_vertices, g_triangle_vertices, sizeof(g_triangle_vertices) );
//Unlock so Direct3D knows we're done and can do any behind-the-scenes magic required
g_triangle->Unlock();
//Now we go through the same process to fill in our VB for the square.
hr=g_square->Lock(0, //Offset, we want to start at the beginning
0, //SizeToLock, 0 means lock the whole thing
&vb_vertices, //If successful, this will point to the data in the VB
0); //Flags, nothing special
if(FAILED(hr)){
FatalError(hr,"Error Locking square buffer");
}
// Function:find_16bit_mode
// Whazzit:Tests a couple of 16-bit modes to see if they are supported. Virtually every graphics
// card in existance will support one of these 2 formats.
D3DFORMAT find_16bit_mode(void){
HRESULT hr;
//First we test for R5G6B5. All 16-bits are used in this format giving us a full 64K worth
//worth of colours
hr=g_D3D->CheckDeviceType(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,D3DFMT_R5G6B5,D3DFMT_R5G6B5,FALSE);
if(SUCCEEDED(hr)){
OutputDebugString("D3DFMT_R5G6B5\n");
return D3DFMT_R5G6B5;
}
//Next try X1R5G5B5. Since 1 bit is wasted it's technically a 15-bit mode and only
//provides 32K colours, though you'd be hard pressed to tell the difference between
//15- & 16-bit modes.
hr=g_D3D->CheckDeviceType(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,D3DFMT_X1R5G5B5,D3DFMT_X1R5G5B5,FALSE);
if(SUCCEEDED(hr)){
OutputDebugString("D3DFMT_X1R5G5B5\n");
return D3DFMT_X1R5G5B5;
}
//This is a freaky card. Complain and bail out.
FatalError(hr,"Couldn't find a decent mode");
//Won't actually hit this line since FatalError() kills us, but it makes the compiler happy.
return (D3DFORMAT)NULL;
}
// Function:ask_fullscreen
// Whazzit:Ask the user if they would like to run in full-screen or windowed mode or if they
// would like to Cancel (abort).
bool ask_fullscreen(void){
int full_result;
bool full_screen=true;
full_result=MessageBox(NULL,"Would you like to run in fullscreen mode?",g_app_name,
MB_YESNOCANCEL|MB_ICONQUESTION);
switch(full_result){
case IDCANCEL: //User hit 'Cancel' button, so we quit
MessageBox(NULL,"User Abort",g_app_name,MB_OK);
exit(5);
break;
case IDNO: //User hit 'No' button, run in a window
full_screen=false;
break;
case IDYES: //User hit 'Yes' button, run full-screen
full_screen=true;
break;
case 0: //Error! Couldn't open dialog box
OutputDebugString("Couldn't open MessageBox, dying");
exit(10);
break;
}
return full_screen;
}
// Function: render
// Whazzit:Clears the screen, draws a triangle and a square
// and then presents the results.
void render(void){
//Clear the buffer to black. We set our vertex colours using Hex notation (0xAARRGGBB)
//above. Here we use the D3DCOLOR_XRGB macro to specify our colour. This is just
//another way to accomplish the same thing.
g_d3d_device->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );
//Notify the device that we're ready to render
if(SUCCEEDED(g_d3d_device->BeginScene())){
//Vertex shaders are a complex topic, but you can do some amazing things with them
//For this example we're not creating one, so we tell Direct3D that we're just
//using a plain vertex format.
g_d3d_device->SetVertexShader(D3D8T_CUSTOMVERTEX);
//D3D's rendering functions read from streams. Here we tell D3D that the
//VB we created for our triangle is the stream it should read from.
g_d3d_device->SetStreamSource(0,g_triangle,sizeof(my_vertex));
//After all that setup, actually drawing the triangle is pretty easy.
//We tell it what we're giving it (a Triangle List), where it should
//start reading (0, the beginning), and how many triangles we're drawing(1)
g_d3d_device->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);
//Set the active stream to be our square.
//NOTE: Because of the offsets that DrawPrimitive takes, we could
//have built the triangle & square into a single VB and still
//drawn them seperately.
g_d3d_device->SetStreamSource(0,g_square,sizeof(my_vertex));
//Now we're drawing a Triangle Strip, 4 vertices to draw 2 triangles.
g_d3d_device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
//Notify the device that we're finished rendering for this frame
g_d3d_device->EndScene();
}
//Show the results
g_d3d_device->Present( NULL, NULL, NULL, NULL );
}
// Function:FatalError
// Whazzit:Close down all resources, alert the user and quit
void FatalError(const char *p_error_msg){
}
// Function:FatalError
// Whazzit:Close down all resources, alert the user and quit
void FatalError(HRESULT p_hr,const char *p_error_msg){
char buffer[255];
D3DXGetErrorStringA(p_hr,buffer,250);
strcat(buffer,"\n");
strcat(buffer,p_error_msg);
kill_scene();
kill_d3d();
kill_window();
//Write our error message out to the debugger (if it's active)
OutputDebugString( buffer );
OutputDebugString("\n");
MessageBox(NULL, buffer,g_app_name, MB_OK );
exit(5);
}
// Function:default_window_proc
// Whazzit:All Windows messages get passed through this function. We only handle
// a tiny subset of the available messages, all unhandled messages get
// passed through to DefWindowProc() which is part of the Win32 API.
LRESULT CALLBACK default_window_proc(HWND p_hwnd,UINT p_msg,WPARAM p_wparam,LPARAM p_lparam){
switch(p_msg){
case WM_KEYDOWN: // A key has been pressed, end the app
case WM_LBUTTONDOWN: //user hit the left mouse button
case WM_CLOSE: //User hit the Close Window button, end the app
g_app_done=true;
return 0;
case WM_DESTROY: //This window is being destroyed, tell Windows we're quitting
PostQuitMessage(0);
return 0;
}
This looks like code that is set to compile under Visual C++, there is stuff in there, like the Pragma statements that will probably never compile under GCC.
This is hardly code to get started with.
Wayne
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Instead of attempting to excerpt the error message, copy and past your compile log
from the tab labeled "Compile Log" - note that you have to use the right mouse
button to get the correct copy menu. If you have a ton of errors, post the log
from the beginning through the first 5 or so errors.
Wayne
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
> Pragma statements that will probably never compile under GCC.
The ISO standard requires that any unrecognised #pragma directives (which in GCC is pretty much any #pragma directives) are ignored. #pragma directives are always compiler specific.
Because these lines will be ignored, you will have to explicitly link the DirectX libraries by specifying them in the linker options rather than using this nasty non-standard kludge. You will get linker "undefined reference' errors otherwise.
Of course, you will struggle to find DirextX libraries and headers to work with Dev-C++. You cannot use Microsoft's SDK out of the box. There is a DirectX 9 DevPak which I reckon is legally dubious since it distributes MS code. http://www.g-productions.net/page.php?id=23&a=dl
I suggest that you make life easier for yourself, and keep on the right side of the EULA and use a Microsoft tool for this code.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
"Because these lines will be ignored, you will have to explicitly link the DirectX libraries by specifying them in the linker options rather than using this nasty non-standard kludge. You will get linker "undefined reference' errors otherwise."
I am quoting Clifford, but talking to the original poster
It is possible that the you did this, and the compile log portion of the Basic 3 would show us that. Each element in the Basic 3 has a purpose (none of which is to annoy or inconvenience you)
Wayne
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Look at this it is code i just pasted and tried to compile
I am new to this so it must be me but i am not sure what i am doing wrong. As far as SDK i installed the dx9 devpak
Here is the complie log you wanted maybe you can solve my problem This code is differnt from above, also i am having trouble when i try to compile open gl code so who knows
Compiler: Default GCC compiler
Executing g++.exe...
g++.exe "C:\3Dfish\set\D3DSetup\D3DWindow.cpp" -o "C:\3Dfish\set\D3DSetup\D3DWindow.exe" -I"C:\Program Files\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Program Files\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Program Files\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Program Files\Dev-Cpp\include\c++\3.4.2" -I"C:\Program Files\Dev-Cpp\include" -I"C:\Program Files\Dev-Cpp\" -I"C:\Program Files\Dev-Cpp\include\common\wx\msw" -I"C:\Program Files\Dev-Cpp\include\common\wx\generic" -I"C:\Program Files\Dev-Cpp\include\common\wx\fl" -I"C:\Program Files\Dev-Cpp\include\common\wx\gizmos" -I"C:\Program Files\Dev-Cpp\include\common\wx\html" -I"C:\Program Files\Dev-Cpp\include\common\wx\mmedia" -I"C:\Program Files\Dev-Cpp\include\common\wx\net" -I"C:\Program Files\Dev-Cpp\include\common\wx\ogl" -I"C:\Program Files\Dev-Cpp\include\common\wx\plot" -I"C:\Program Files\Dev-Cpp\include\common\wx\protocol" -I"C:\Program Files\Dev-Cpp\include\common\wx\stc" -I"C:\Program Files\Dev-Cpp\include\common\wx\svg" -I"C:\Program Files\Dev-Cpp\include\common\wx\xml" -I"C:\Program Files\Dev-Cpp\include\common\wx\xrc" -I"C:\Program Files\Dev-Cpp\include\common\wx" -I"C:\Program Files\Dev-Cpp\include\common" -L"C:\Program Files\Dev-Cpp\Lib"
C:\3Dfish\set\D3DSetup\D3DWindow.cpp:5:19: dxerr.h: No such file or directory
C:\3Dfish\set\D3DSetup\D3DWindow.cpp: In member function `bool D3DWindow::Create(HINSTANCE__*, unsigned int, unsigned int, bool)':
C:\3Dfish\set\D3DSetup\D3DWindow.cpp:55: warning: cast from pointer to integer of different size
C:\3Dfish\set\D3DSetup\D3DWindow.cpp:56: warning: cast from pointer to integer of different size
C:\3Dfish\set\D3DSetup\D3DWindow.cpp: In member function bool D3DWindow::InitD3DDevice(unsigned int, unsigned int, bool)':
C:\3Dfish\set\D3DSetup\D3DWindow.cpp:304: error:DXGetErrorString' undeclared (first use this function)
C:\3Dfish\set\D3DSetup\D3DWindow.cpp:304: error: (Each undeclared identifier is reported only once for each function it appears in.)
C:\3Dfish\set\D3DSetup\D3DWindow.cpp: In member function bool D3DWindow::HandlePresentRetVal(HRESULT)':
C:\3Dfish\set\D3DSetup\D3DWindow.cpp:540: error:DXGetErrorString' undeclared (first use this function)
C:\3Dfish\set\D3DSetup\D3DWindow.cpp: In member function bool D3DWindow::ResetDevice()':
C:\3Dfish\set\D3DSetup\D3DWindow.cpp:561: error:DXGetErrorString' undeclared (first use this function)
Well, one problem (probably not your only one) is that you installed Dev in "Program Files", this is a VERY VERY bad idea, and it is confusing your paths due to the space in the name. (The "Please Read" thread mentions this)
You need to do a clean install (directions can be found in the "Please Read" thread), DO NOT assume you know how to do it yourself and don't need to read them. Then install Dev where it wants to go. (C:\dev-cpp). Please CAREFULLY note the directions in there about noting in detail what you did, and reporting it if you have issues. (probably 90%, even when reminded forcefully to do so, stupidly do not. You don't want to look like a complete idiot, who is too stupid to program, like they did, do you?)
There is a getting started with GLUT section in the "Please Read" thread - it tells you what to get where, and how to link things (I note in your log there are no link commands). Give that a try and report back.
Wayne
p.s. A general tip. Do NOT override a program's default directory during install unless you are REALLR sure that it is OK. If it is not defaulting to program files, there is probably a very good reason.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Feel free to get as mad as you want for using terms like stupid.
If it gets you to provide needed information that helps you - and gets you going in the right direction, I will be happy tohave your hate me.
I suggested the GLUT example by the way since you mentioned issues with getting OpenGL to compile.
Finally, there is a section in the "Please Read" thread on the compile log,including headers and linking libraries that also goes into the mechanics and understanding of that process...tells you what commands like
-lglut32
are meant to do.
Wayne
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This command "-I" is attmpting to set the path to your include directories - but the directory
"Program Files"
is being split at the space - so c:\program files becomes c:\program
Spaces in paths - to Dev, or to your code, cause issues like this. The evil part, is that the problems are erratic. You may get away with this for a while, and then, things stop working.
Wayne
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am using wxdev C++ and it wants to go to program files. When i installed i did not choose that folder the first time, but i installed it to c:\Devccp like you said I also reinstalled the dx9 devpack. The devpak comes with samples, I tried to compile the teapot sample below is the compile log Of course it did not work I am running xp pro
d3dapp.cpp: In member function HRESULT CD3DApplication::Initialize3DEnvironment()':
d3dapp.cpp:871: error:ULongToHandle' undeclared (first use this function)
d3dapp.cpp:871: error: (Each undeclared identifier is reported only once for each function it appears in.)
d3dapp.cpp: In member function `HRESULT CD3DApplication::Reset3DEnvironment()':
d3dapp.cpp:1048: error: `ULongToHandle' undeclared (first use this function)
mingw32-make.exe: *** [MingW/d3dapp.o] Error 1
Execution terminated
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You did Google "ULongToHandle" to find out what it was and where it is defined before posting didn't you? http://cboard.cprogramming.com/showthread.php?t=59466 You might also try updating the Win32API package from www.mingw.org, or through the web update tool (Tools menu). There maybe a a newer version than that installed with Dev-C++, and it may contain the necessary function.
When wxDevCpp started installing to "Program Files", I thought perhaps they had implemented some fix to make this work; but it seems not.
There is another problem with not using c:\dev-cpp as the installation folder. Many if not all DevPak project templates assume that, and have the path hard-coded in their project paths. This is why a large number of the other errors disappeared when you reinstalled.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
i asked questions here because the widgets forum NEVER answers, not just me but it seems many people never get an answer, so because wxdev c++ is just an extension of Dev c++ i thought it would be okay to ask here, ( here is where i learned about the DX9 devpak)I did not mention it sooner because i did not think it mattered, sorry. I did google some of those problems i had but do not have enough knowledge to really understand what to do, not clearly anyway. That is why i needed wxdev C++ to work so i can start to learn DX9 by compiling. I will fool around with it a bit more but i think at this point i will just have to bite the bullet and buy a complier that has gui design tools. Wxdev C++ is great and i had fun with making frames. Thanks to you guys for answering so quickly and patiently with me. As a beginner i ask stupid questions If you know where i can get a CHEAP compiler with gui design tools please let me know, preferably one that has no problems with DX9. i will look around for one on the net but i think you will know better than me
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
> but i think at this point i will just have to bite the
> bullet and buy a complier that has gui design tools.
MSVC++ 2008 Express Edition is free. It has Windows Forms support for visual GUI development. That entails learning a little about the C++/CLI extensions and .NET framework, but frankly it is worth it. That said, I decided to learn C# for .NET development instead. The Free Visual C# Express has a better IDE than the cut down Visual Studio with VC++ EE.
The best thing about the Express Editions are the excellent debug tools.
Take a look at the VC++ EE webste (and C# is you are interested). There are lots of project ideas and free third part tools you can download. If you are interested in DirectX for game development, there is in fact a Game Development Toolkit that will probably save you a lot of work.
You can use VC++ EE for vanilla Win32 code too (but no GUI designer or MFC), and ISO C++.
Yeah, i knew about express, I was told express does not have gui design tools but the problem of it is you have to be online to install, for me 98 Megs would be about 6 hours online. leave it to Microsoft to make everything difficult. I asked for a cd on their forum and of course no answer. I will try to get it though. thanks again
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
> I was told express does not have gui design tools.
Never believe what you are told until you have confirmed it yourself from a reliable source... like the source itself.
> but the problem of it is you have to be online to install,
You can download a DVD ISO image. You'll need a DVD writer, or use "ISO buster" to emulate the DVD from the image. That is an even bigger download, but you can download it unattended. However it is still going to take days at your rate fo 4.6kbps. The Internet has left you behind it seems. Perhaps an Internet cafe, your local library, or a friend, employer or whoever you know with a fast link could help.
There is another option: Borland Turbo Explorer. http://www.turboexplorer.com/ This is the same principle as Microsoft's Express Editions, however you can build Win32 native GUI apps visually using Borland's Visual Component Library rather than .NET/Windows Forms. with the necessary C++/CLI extensions. Some of the limitations on the product are more severe that Microsoft's however. Like you can only install one Turbo product on a single machine (although I reckon you could wok around that with a virtual machine if necessary. Not sure if you can use DirectX with it though. Of course it probably does not help you, it is a 390Mb download.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I installed DX9 devpak but get error messages no matter how many times with different source codes below is an example that may make it clearer
This is the error message for the code below
hCursor = (HCURSOR)ULongToHandle( GetClassLong( m_hWnd, GCL_HCURSOR )
// These are all the includes we need. One for the basic Windows stuff
// (which we will use as rarely as possible, I'm not a fan of the Windows
// API) and one for Direct3D 8.
define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
include <windows.h>
include <D3DX8.h>
// This is causes the d3d8.lib to be linked in, the same thing can be accomplished by
// adding it to your compiler's link list (Project->Settings->Link in VC++),
// but I prefer this method.
pragma comment(lib,"d3d8.lib")
pragma comment(lib,"d3dx8.lib")
// Forward declarations for all of our functions, see their definitions for more detail
void FatalError(const char p_error_msg);
void FatalError(HRESULT p_hr,const char p_error_msg);
bool ask_fullscreen(void);
LRESULT CALLBACK default_window_proc(HWND p_hwnd,UINT p_msg,WPARAM p_wparam,LPARAM p_lparam);
void init_window(bool p_fullscreen);
void kill_window(void);
void init_d3d(bool p_fullscreen);
void kill_d3d(void);
void init_scene(void);
void kill_scene(void);
void message_pump(void);
D3DFORMAT find_16bit_mode(void);
void render(void);
void NOP(HINSTANCE p_prev_instance,LPSTR p_cmd_line,int p_show);
// The name of our application. Used for window titles, MessageBox titles and
// error reporting
const char g_app_name[]="DirectX 8 Lesson 2a";
// Our screen/window sizes. A better app would allow the user to choose the
// sizes. I'll do that in a later tutorial, for now this is good enough.
const int g_width=640;
const int g_height=480;
// A global handle to our main window, initializing pointers to NULL can save you
// a lot of hassle in the future.
HWND g_main_window=NULL;
// A global handle to our 'instance'. This is needed in various places by the Windows API.
HINSTANCE g_instance;
// Our global flag to track whether we should quit or not. When it becomes true, we clean
// up and exit.
bool g_app_done=false;
// Our main Direct3D interface, it doesn't do much on its own, but all the more commonly
// used interfaces are created by it. It's the first D3D object you create, and the last
// one you release.
IDirect3D8 *g_D3D=NULL;
// The D3DDevice is your main rendering interface. It represents the display and all of its
// capabilities. When you create, modify, or render any type of resource, you will likely
// do it through this interface.
IDirect3DDevice8 *g_d3d_device=NULL;
//Declare a structure to hold a vertex with all the information that we need
struct my_vertex{
FLOAT x, y, z, rhw; // The transformed position for the vertex.
DWORD colour; // The vertex colour.
};
//A handy little 'macro' for our definition of the vertex. When we use the vertex data
//we have to tell D3D what data we're passing it. D3DFVF_DIFFUSE specifies that the
//vertex will have a colour, the D3DFVF_XYZRHW specifies that the vertex will have
//coordinate given in screen space.
define D3D8T_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE)
//The x & y values here are given in 'screen space'. Vertices in screen space
//are referred to as Transformed vertices. What this means is that the x and y
//coordinates are given as offsets from the top left of the screen. If you change
//these coordinates by adding 50 to each x value, you will move everything to the
//right by 50 pixels.
//With Transformed vertices, the z coordinate doesn't do much. If you have a Z Buffer
//it determines which objects block other objects, but changing the z coordinate will
//have no other effect. The visible size (given by the x,y coordinates) is static, so
//even though you can effectively move the object deeper into the screen, it will remain
//the same size.
//The colour for each vertex is given in Hex notation. Each pair of hex digits is another
//component of the colour. The components are Alpha, Red, Green and Blue, and they are
//organized like this: 0xAARRGGBB
my_vertex g_triangle_vertices[] ={
{ 125.0f, 50.0f, 0.5f, 1.0f, 0xFFFFFFFF }, // x, y, z, rhw, colour
{ 200.0f, 200.0f, 0.5f, 1.0f, 0xFFFFFFFF },
{ 50.0f, 200.0f, 0.5f, 1.0f, 0xFFFFFFFF }
};
//Direct3D does not support a Quad rendering primitive like OpenGL does. It does have
//Triangle Strips. In a Triangle Strip, the first 3 vertices form a triangle, and
//then each additional vertex adds a triangle formed by itself and the previous 2
//vertices. Thus to draw a square we need only 4 vertices.
my_vertex g_square_vertices[] ={
{ 250.0f, 200.0f, 0.5f, 1.0f, 0xFFFFFFFF }, // x, y, z, rhw, colour
{ 250.0f, 50.0f, 0.5f, 1.0f, 0xFFFFFFFF },
{ 400.0f, 200.0f, 0.5f, 1.0f, 0xFFFFFFFF },
{ 400.0f, 50.0f, 0.5f, 1.0f, 0xFFFFFFFF }
};
//Vertex buffers are a method of storing vertices to be rendered in an optimized manner.
IDirect3DVertexBuffer8 g_triangle=NULL;
IDirect3DVertexBuffer8 g_square=NULL;
// WinMain is the first function called by Windows when our app is run. It's the entry
// point of our application.
int APIENTRY WinMain(HINSTANCE p_instance,HINSTANCE p_prev_instance,LPSTR p_cmd_line,int p_show){
bool full_screen;
// Set our global instance handle so we don't have to pass it around
g_instance=p_instance;
//This function exists to quiet compiler warnings, see its definition for more detail
NOP(p_prev_instance,p_cmd_line,p_show);
// Prompt the user, Full Screen? Windowed? Cancel?
full_screen=ask_fullscreen();
// Build our window. Cover the screen if full-screen, otherwise make a standard window
init_window(full_screen);
//Build the D3D objects we'll require
init_d3d(full_screen);
//One-time preparation of objects and other stuff required for rendering
init_scene();
//Loop until the user aborts (closes the window or hits a key)
while(!g_app_done){
//Check for window messages
message_pump();
//Draw our incredibly cool graphics
render();
}
//Clean up all of our scene objects/resources
kill_scene();
//Clean up all of our Direct3D objects
kill_d3d();
//Close down our window
kill_window();
//Exit happily
return 0;
}
// Procedure: NOP
// Whazzit:This procedure does nothing. If set to a high warning level
// (which I like to do) the compiler will complain because the
// parameters passed into WinMain are never used. The purpose
// of this procedure is to make it think that they are used, so
// it doesn't complain.
void NOP(HINSTANCE p_prev_instance,LPSTR p_cmd_line,int p_show){
p_prev_instance=p_prev_instance;
p_cmd_line=p_cmd_line;
p_show=p_show;
}
// Procedure: message_pump
// Whazzit:Checks the message queue to see if any windows messages
// (window is closing, window needs repainting, etc)
// are waiting and if there are, the messages are dispatched
// to our message handler.
void message_pump(void){
MSG msg;
if(PeekMessage(&msg, NULL, 0, 0,PM_REMOVE)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
// Function: init_window
// Whazzit:Registers a window class and then creates our window.
void init_window(bool p_fullscreen){
ULONG window_width, window_height;
WNDCLASS window_class;
DWORD style;
//Fill in all the fields for the WNDCLASS structure. Window classes
//are a sort of template for window creation. You could create many
//windows using the same window class.
window_class.style = CS_OWNDC;
window_class.cbClsExtra = 0;
window_class.cbWndExtra = 0;
window_class.hInstance = g_instance;
window_class.hIcon = LoadIcon(NULL,IDI_APPLICATION);
window_class.hCursor = LoadCursor(NULL,IDC_ARROW);
window_class.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
window_class.lpszMenuName = NULL;
window_class.lpszClassName = "DH Class";
//Here we provide our default window handler, all windows messages
//will be sent to this function.
window_class.lpfnWndProc = default_window_proc;
//Register the class with windows
if(!RegisterClass(&window_class)){
FatalError("Error registering window class");
}
//If we're running full screen, we cover the desktop with our window.
//This isn't necessary, but it provides a smoother transition for the
//user, especially when we're going to change screen modes.
if(p_fullscreen){
window_width=GetSystemMetrics(SM_CXSCREEN);
window_height=GetSystemMetrics(SM_CYSCREEN);
style=WS_POPUP;
}else{
//In windowed mode, we just make the window whatever size we need.
window_width=g_width;
window_height=g_height;
style=WS_OVERLAPPED|WS_SYSMENU;
}
//Here we actually create the window. For more detail on the various
//parameters please refer to the Win32 documentation.
g_main_window=CreateWindow("DH Class", //name of our registered class
g_app_name, //Window name/title
style, //Style flags
0, //X position
0, //Y position
window_width,//width of window
window_height,//height of window
NULL, //Parent window
NULL, //Menu
g_instance, //application instance handle
NULL); //pointer to window-creation data
if(!g_main_window){
FatalError("Error opening window");
}
//The next 3 lines just make sure that our window is visible and has the
//input focus. It's not strictly necessary, but it doesn't hurt to be
//thorough.
ShowWindow(g_main_window,SW_SHOW);
UpdateWindow(g_main_window);
SetFocus(g_main_window);
}
// Function: kill_window
// Whazzit:Closes the window, clean up any waiting messages, and then unregister
// our window class. Note - This is not the standard Win32 way of cleaning
// up your window. The standard way involves putting the clean-up code in
// your window handler. With this method, we destroy what we create.
void kill_window(void){
//Test if our window is valid
if(g_main_window){
if(!DestroyWindow(g_main_window)){
//We failed to destroy our window, this shouldn't ever happen
OutputDebugString(" Failed to DestroyWindow\n");
MessageBox(NULL,"Destroy Window Failed",g_app_name,MB_OK|MB_ICONERROR|MB_TOPMOST);
}else{
MSG msg;
//Clean up any pending messages
while(PeekMessage(&msg, NULL, 0, 0,PM_REMOVE)){
DispatchMessage(&msg);
}
}
//Set our window handle to NULL just to be safe
g_main_window=NULL;
}
//Unregister our window, if we had opened multiple windows using this
//class, we would have to close all of them before we unregistered the class.
if(!UnregisterClass("DH Class",g_instance)){
OutputDebugString(" Failed to Unregister Window\n");
MessageBox(NULL,"Unregister Failed",g_app_name,MB_OK|MB_ICONERROR|MB_TOPMOST);
}
}
// Function:init_d3d
// Whazzit:Sets up Direct3D and creates the device. The device is created differently
// if we're full-screen as opposed to running in a desktop window.
void init_d3d(bool p_fullscreen){
HRESULT hr;
D3DPRESENT_PARAMETERS d3dpp;
D3DDISPLAYMODE display_mode;
//Create Direct3D8, this is the first thing you have to do in any D3D8 program
g_D3D = Direct3DCreate8( D3D_SDK_VERSION );
if(!g_D3D ){
FatalError("Error getting Direct3D");
}
//Get the current(desktop) display mode. This is only needed if
//we're running in a window.
hr=g_D3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&display_mode);
if(FAILED(hr)){
FatalError(hr,"Error getting display mode");
}
//Clear out our D3DPRESENT_PARAMETERS structure. Even though we're going
//to set virtually all of its members, it's good practice to zero it out first.
ZeroMemory(&d3dpp,sizeof(d3dpp));
//Whether we're full-screen or windowed these are the same.
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; // Throw away previous frames, we don't need them
d3dpp.hDeviceWindow = g_main_window; //This is our main (and only) window
d3dpp.BackBufferCount= 1; //We only need a single back buffer
// BackBufferWidth/Height have to be set for full-screen apps, these values are
//used (along with BackBufferFormat) to determine the display mode.
//They aren't needed in windowed mode since the size of the window will be used.
// BackBufferFormat is the pixel format we want.
if(p_fullscreen){
d3dpp.Windowed = FALSE;
d3dpp.BackBufferWidth = g_width;
d3dpp.BackBufferHeight = g_height;
//In full-screen we need to find a pixel format we like, see find_16bit_mode()
//below for more details.
d3dpp.BackBufferFormat = find_16bit_mode();
}else{
d3dpp.Windowed = TRUE;
//In windowed mode we use the same format as the desktop, which we found
//by using GetAdapterDisplayMode() above.
d3dpp.BackBufferFormat = display_mode.Format;
}
hr=g_D3D->CreateDevice(D3DADAPTER_DEFAULT, //The default adapter, on a multimonitor system
//there can be more than one.
//Use hardware acceleration rather than the software renderer
D3DDEVTYPE_HAL,
//Our Window
g_main_window,
//Process vertices in software. This is slower than in hardware,
//But will work on all graphics cards.
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
//Our D3DPRESENT_PARAMETERS structure, so it knows what we want to build
&d3dpp,
//This will be set to point to the new device
&g_d3d_device);
if(FAILED(hr)){
FatalError(hr,"Error creating device");
}
}
// Function:kill_d3d
// Whazzit:Releases all of our D3D resources in the opposite order from their creation.
// Note-Since we initially set the pointers to be NULL, we can safely test them
// for a non-NULL state and we know if they've been created. Thus we never Release
// something we didn't create (which causes bad things to happen).
void kill_d3d(void){
if(g_d3d_device){
g_d3d_device->Release();
g_d3d_device=NULL;
}
if(g_D3D){
g_D3D->Release();
g_D3D=NULL;
}
}
// Function:init_scene
// Whazzit:One-time preparation of objects required for rendering. In this tutorial we prepare
// 2 objects:a triangle & a square.
void init_scene(void){
HRESULT hr;
unsigned char *vb_vertices;
//As mentioned above, a Vertex Buffer is an optimized storage medium for vertices.
//Here we create a vertex buffer large enough to hold 3 vertices. We specify that
//it can only be written to and we allow Direct3D to determine where in memory
//it should be placed.
hr=g_d3d_device->CreateVertexBuffer(3*sizeof(my_vertex), //Size of memory to be allocated
// Number of vertices * size of a vertex
D3DUSAGE_WRITEONLY, // We never need to read from it so
// we specify write only, it's faster
D3D8T_CUSTOMVERTEX, //Our custom vertex specifier (coordinates & a colour)
D3DPOOL_MANAGED, //Tell DirectX to manage the memory of this resource
&g_triangle); //Pointer to our triangle, after this call
//It will point to a valid vertex buffer
if(FAILED(hr)){
FatalError(hr,"Error creating triangle vertex buffer");
}
//The only difference between this and the above call is that we're allocating
//enough space for 4 vertices instead of 3.
hr=g_d3d_device->CreateVertexBuffer(4*sizeof(my_vertex), //Size of memory to be allocated
// Number of vertices * size of a vertex
D3DUSAGE_WRITEONLY, // We never need to read from it so
// we specify write only, it's faster
D3D8T_CUSTOMVERTEX, //Our custom vertex specifier (coordinates & a colour)
D3DPOOL_MANAGED, //Tell DirectX to manage the memory of this resource
&g_square); //Pointer to our triangle, after this call
//It will point to a valid vertex buffer
if(FAILED(hr)){
FatalError(hr,"Error creating square vertex buffer");
}
//Now we have our Vertex Buffers, but they're empty. To put our data into them
//we Lock the Vertex Buffer so Direct3D knows we're modifying it, then we copy
//our data in and Unlock it so Direct3D knows we're done.
hr=g_triangle->Lock(0, //Offset, we want to start at the beginning
0, //SizeToLock, 0 means lock the whole thing
&vb_vertices, //If successful, this will point to the data in the VB
0); //Flags, nothing special
if(FAILED(hr)){
FatalError(hr,"Error Locking triangle buffer");
}
//vb_vertices now points to our vertices inside the Vertex buffer, so
//to fill in our VB, we copy to vb_vertices.
memcpy(vb_vertices, g_triangle_vertices, sizeof(g_triangle_vertices) );
//Unlock so Direct3D knows we're done and can do any behind-the-scenes magic required
g_triangle->Unlock();
//Now we go through the same process to fill in our VB for the square.
hr=g_square->Lock(0, //Offset, we want to start at the beginning
0, //SizeToLock, 0 means lock the whole thing
&vb_vertices, //If successful, this will point to the data in the VB
0); //Flags, nothing special
if(FAILED(hr)){
FatalError(hr,"Error Locking square buffer");
}
memcpy(vb_vertices, g_square_vertices, sizeof(g_square_vertices) );
g_square->Unlock();
}
// Function:kill_scene
// Whazzit:Clean up any objects we required for rendering.
void kill_scene(void){
if(g_triangle){
g_triangle->Release();
g_triangle=NULL;
}
if(g_square){
g_square->Release();
g_square=NULL;
}
}
// Function:find_16bit_mode
// Whazzit:Tests a couple of 16-bit modes to see if they are supported. Virtually every graphics
// card in existance will support one of these 2 formats.
D3DFORMAT find_16bit_mode(void){
HRESULT hr;
//First we test for R5G6B5. All 16-bits are used in this format giving us a full 64K worth
//worth of colours
hr=g_D3D->CheckDeviceType(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,D3DFMT_R5G6B5,D3DFMT_R5G6B5,FALSE);
if(SUCCEEDED(hr)){
OutputDebugString("D3DFMT_R5G6B5\n");
return D3DFMT_R5G6B5;
}
//Next try X1R5G5B5. Since 1 bit is wasted it's technically a 15-bit mode and only
//provides 32K colours, though you'd be hard pressed to tell the difference between
//15- & 16-bit modes.
hr=g_D3D->CheckDeviceType(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,D3DFMT_X1R5G5B5,D3DFMT_X1R5G5B5,FALSE);
if(SUCCEEDED(hr)){
OutputDebugString("D3DFMT_X1R5G5B5\n");
return D3DFMT_X1R5G5B5;
}
//This is a freaky card. Complain and bail out.
FatalError(hr,"Couldn't find a decent mode");
//Won't actually hit this line since FatalError() kills us, but it makes the compiler happy.
return (D3DFORMAT)NULL;
}
// Function:ask_fullscreen
// Whazzit:Ask the user if they would like to run in full-screen or windowed mode or if they
// would like to Cancel (abort).
bool ask_fullscreen(void){
int full_result;
bool full_screen=true;
full_result=MessageBox(NULL,"Would you like to run in fullscreen mode?",g_app_name,
MB_YESNOCANCEL|MB_ICONQUESTION);
switch(full_result){
case IDCANCEL: //User hit 'Cancel' button, so we quit
MessageBox(NULL,"User Abort",g_app_name,MB_OK);
exit(5);
break;
case IDNO: //User hit 'No' button, run in a window
full_screen=false;
break;
case IDYES: //User hit 'Yes' button, run full-screen
full_screen=true;
break;
case 0: //Error! Couldn't open dialog box
OutputDebugString("Couldn't open MessageBox, dying");
exit(10);
break;
}
return full_screen;
}
// Function: render
// Whazzit:Clears the screen, draws a triangle and a square
// and then presents the results.
void render(void){
//Clear the buffer to black. We set our vertex colours using Hex notation (0xAARRGGBB)
//above. Here we use the D3DCOLOR_XRGB macro to specify our colour. This is just
//another way to accomplish the same thing.
g_d3d_device->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );
//Notify the device that we're ready to render
if(SUCCEEDED(g_d3d_device->BeginScene())){
//Vertex shaders are a complex topic, but you can do some amazing things with them
//For this example we're not creating one, so we tell Direct3D that we're just
//using a plain vertex format.
g_d3d_device->SetVertexShader(D3D8T_CUSTOMVERTEX);
//D3D's rendering functions read from streams. Here we tell D3D that the
//VB we created for our triangle is the stream it should read from.
g_d3d_device->SetStreamSource(0,g_triangle,sizeof(my_vertex));
//After all that setup, actually drawing the triangle is pretty easy.
//We tell it what we're giving it (a Triangle List), where it should
//start reading (0, the beginning), and how many triangles we're drawing(1)
g_d3d_device->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);
//Set the active stream to be our square.
//NOTE: Because of the offsets that DrawPrimitive takes, we could
//have built the triangle & square into a single VB and still
//drawn them seperately.
g_d3d_device->SetStreamSource(0,g_square,sizeof(my_vertex));
//Now we're drawing a Triangle Strip, 4 vertices to draw 2 triangles.
g_d3d_device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
//Notify the device that we're finished rendering for this frame
g_d3d_device->EndScene();
}
//Show the results
g_d3d_device->Present( NULL, NULL, NULL, NULL );
}
// Function:FatalError
// Whazzit:Close down all resources, alert the user and quit
void FatalError(const char *p_error_msg){
kill_scene();
kill_d3d();
kill_window();
OutputDebugString( p_error_msg );
OutputDebugString("\n");
MessageBox(NULL, p_error_msg,g_app_name, MB_OK );
exit(5);
}
// Function:FatalError
// Whazzit:Close down all resources, alert the user and quit
void FatalError(HRESULT p_hr,const char *p_error_msg){
char buffer[255];
D3DXGetErrorStringA(p_hr,buffer,250);
strcat(buffer,"\n");
strcat(buffer,p_error_msg);
kill_scene();
kill_d3d();
kill_window();
//Write our error message out to the debugger (if it's active)
OutputDebugString( buffer );
OutputDebugString("\n");
MessageBox(NULL, buffer,g_app_name, MB_OK );
exit(5);
}
// Function:default_window_proc
// Whazzit:All Windows messages get passed through this function. We only handle
// a tiny subset of the available messages, all unhandled messages get
// passed through to DefWindowProc() which is part of the Win32 API.
LRESULT CALLBACK default_window_proc(HWND p_hwnd,UINT p_msg,WPARAM p_wparam,LPARAM p_lparam){
switch(p_msg){
case WM_KEYDOWN: // A key has been pressed, end the app
case WM_LBUTTONDOWN: //user hit the left mouse button
case WM_CLOSE: //User hit the Close Window button, end the app
g_app_done=true;
return 0;
case WM_DESTROY: //This window is being destroyed, tell Windows we're quitting
PostQuitMessage(0);
return 0;
}
return (DefWindowProc(p_hwnd,p_msg,p_wparam,p_lparam));
}
Hopefully someone will know As a beginner it is hard to get started.
Rocco
"This is the error message for the code below"
There is only code below, no error messages.
This looks like code that is set to compile under Visual C++, there is stuff in there, like the Pragma statements that will probably never compile under GCC.
This is hardly code to get started with.
Wayne
Instead of attempting to excerpt the error message, copy and past your compile log
from the tab labeled "Compile Log" - note that you have to use the right mouse
button to get the correct copy menu. If you have a ton of errors, post the log
from the beginning through the first 5 or so errors.
Wayne
> Pragma statements that will probably never compile under GCC.
The ISO standard requires that any unrecognised #pragma directives (which in GCC is pretty much any #pragma directives) are ignored. #pragma directives are always compiler specific.
> #pragma comment(lib,"d3d8.lib")
> #pragma comment(lib,"d3dx8.lib")
Because these lines will be ignored, you will have to explicitly link the DirectX libraries by specifying them in the linker options rather than using this nasty non-standard kludge. You will get linker "undefined reference' errors otherwise.
Of course, you will struggle to find DirextX libraries and headers to work with Dev-C++. You cannot use Microsoft's SDK out of the box. There is a DirectX 9 DevPak which I reckon is legally dubious since it distributes MS code. http://www.g-productions.net/page.php?id=23&a=dl
I suggest that you make life easier for yourself, and keep on the right side of the EULA and use a Microsoft tool for this code.
Clifford
"Because these lines will be ignored, you will have to explicitly link the DirectX libraries by specifying them in the linker options rather than using this nasty non-standard kludge. You will get linker "undefined reference' errors otherwise."
I am quoting Clifford, but talking to the original poster
It is possible that the you did this, and the compile log portion of the Basic 3 would show us that. Each element in the Basic 3 has a purpose (none of which is to annoy or inconvenience you)
Wayne
Look at this it is code i just pasted and tried to compile
I am new to this so it must be me but i am not sure what i am doing wrong. As far as SDK i installed the dx9 devpak
Here is the complie log you wanted maybe you can solve my problem This code is differnt from above, also i am having trouble when i try to compile open gl code so who knows
Compiler: Default GCC compiler
Executing g++.exe...
g++.exe "C:\3Dfish\set\D3DSetup\D3DWindow.cpp" -o "C:\3Dfish\set\D3DSetup\D3DWindow.exe" -I"C:\Program Files\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Program Files\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Program Files\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Program Files\Dev-Cpp\include\c++\3.4.2" -I"C:\Program Files\Dev-Cpp\include" -I"C:\Program Files\Dev-Cpp\" -I"C:\Program Files\Dev-Cpp\include\common\wx\msw" -I"C:\Program Files\Dev-Cpp\include\common\wx\generic" -I"C:\Program Files\Dev-Cpp\include\common\wx\fl" -I"C:\Program Files\Dev-Cpp\include\common\wx\gizmos" -I"C:\Program Files\Dev-Cpp\include\common\wx\html" -I"C:\Program Files\Dev-Cpp\include\common\wx\mmedia" -I"C:\Program Files\Dev-Cpp\include\common\wx\net" -I"C:\Program Files\Dev-Cpp\include\common\wx\ogl" -I"C:\Program Files\Dev-Cpp\include\common\wx\plot" -I"C:\Program Files\Dev-Cpp\include\common\wx\protocol" -I"C:\Program Files\Dev-Cpp\include\common\wx\stc" -I"C:\Program Files\Dev-Cpp\include\common\wx\svg" -I"C:\Program Files\Dev-Cpp\include\common\wx\xml" -I"C:\Program Files\Dev-Cpp\include\common\wx\xrc" -I"C:\Program Files\Dev-Cpp\include\common\wx" -I"C:\Program Files\Dev-Cpp\include\common" -L"C:\Program Files\Dev-Cpp\Lib"
C:\3Dfish\set\D3DSetup\D3DWindow.cpp:5:19: dxerr.h: No such file or directory
C:\3Dfish\set\D3DSetup\D3DWindow.cpp: In member function `bool D3DWindow::Create(HINSTANCE__*, unsigned int, unsigned int, bool)':
C:\3Dfish\set\D3DSetup\D3DWindow.cpp:55: warning: cast from pointer to integer of different size
C:\3Dfish\set\D3DSetup\D3DWindow.cpp:56: warning: cast from pointer to integer of different size
C:\3Dfish\set\D3DSetup\D3DWindow.cpp: In member function
bool D3DWindow::InitD3DDevice(unsigned int, unsigned int, bool)': C:\3Dfish\set\D3DSetup\D3DWindow.cpp:304: error:DXGetErrorString' undeclared (first use this function)C:\3Dfish\set\D3DSetup\D3DWindow.cpp:304: error: (Each undeclared identifier is reported only once for each function it appears in.)
C:\3Dfish\set\D3DSetup\D3DWindow.cpp: In member function
bool D3DWindow::HandlePresentRetVal(HRESULT)': C:\3Dfish\set\D3DSetup\D3DWindow.cpp:540: error:DXGetErrorString' undeclared (first use this function)C:\3Dfish\set\D3DSetup\D3DWindow.cpp: In member function
bool D3DWindow::ResetDevice()': C:\3Dfish\set\D3DSetup\D3DWindow.cpp:561: error:DXGetErrorString' undeclared (first use this function)g++.exe: Files\Dev-Cpp\include\common\wx\msw -IC:\Program: Invalid argument
g++.exe: Files\Dev-Cpp\include\common\wx\generic -IC:\Program: Invalid argument
g++.exe: Files\Dev-Cpp\include\common\wx\fl -IC:\Program: Invalid argument
g++.exe: Files\Dev-Cpp\include\common\wx\gizmos -IC:\Program: Invalid argument
g++.exe: Files\Dev-Cpp\include\common\wx\html -IC:\Program: Invalid argument
g++.exe: Files\Dev-Cpp\include\common\wx\mmedia -IC:\Program: Invalid argument
g++.exe: Files\Dev-Cpp\include\common\wx\net -IC:\Program: Invalid argument
g++.exe: Files\Dev-Cpp\include\common\wx\ogl -IC:\Program: Invalid argument
g++.exe: Files\Dev-Cpp\include\common\wx\plot -IC:\Program: Invalid argument
g++.exe: Files\Dev-Cpp\include\common\wx\protocol -IC:\Program: Invalid argument
g++.exe: Files\Dev-Cpp\include\common\wx\stc -IC:\Program: Invalid argument
g++.exe: Files\Dev-Cpp\include\common\wx\svg -IC:\Program: Invalid argument
g++.exe: Files\Dev-Cpp\include\common\wx\xml -IC:\Program: Invalid argument
g++.exe: Files\Dev-Cpp\include\common\wx\xrc -IC:\Program: Invalid argument
g++.exe: Files\Dev-Cpp\include\common\wx -IC:\Program: Invalid argument
g++.exe: Files\Dev-Cpp\include\common -LC:\Program: Invalid argument
g++.exe: Files\Dev-Cpp\Lib : No such file or directory
Execution terminated
Hope that helps
Battlingsteel
Well, one problem (probably not your only one) is that you installed Dev in "Program Files", this is a VERY VERY bad idea, and it is confusing your paths due to the space in the name. (The "Please Read" thread mentions this)
You need to do a clean install (directions can be found in the "Please Read" thread), DO NOT assume you know how to do it yourself and don't need to read them. Then install Dev where it wants to go. (C:\dev-cpp). Please CAREFULLY note the directions in there about noting in detail what you did, and reporting it if you have issues. (probably 90%, even when reminded forcefully to do so, stupidly do not. You don't want to look like a complete idiot, who is too stupid to program, like they did, do you?)
There is a getting started with GLUT section in the "Please Read" thread - it tells you what to get where, and how to link things (I note in your log there are no link commands). Give that a try and report back.
Wayne
p.s. A general tip. Do NOT override a program's default directory during install unless you are REALLR sure that it is OK. If it is not defaulting to program files, there is probably a very good reason.
Feel free to get as mad as you want for using terms like stupid.
If it gets you to provide needed information that helps you - and gets you going in the right direction, I will be happy tohave your hate me.
I suggested the GLUT example by the way since you mentioned issues with getting OpenGL to compile.
Finally, there is a section in the "Please Read" thread on the compile log,including headers and linking libraries that also goes into the mechanics and understanding of that process...tells you what commands like
-lglut32
are meant to do.
Wayne
You can see in the error messages by the way what I mean about spaces in paths:
g++.exe: Files\Dev-Cpp\include\common\wx\msw -IC:\Program: Invalid argument
Note the last part in particular:
-IC:\Program: Invalid argument
This command "-I" is attmpting to set the path to your include directories - but the directory
"Program Files"
is being split at the space - so c:\program files becomes c:\program
Spaces in paths - to Dev, or to your code, cause issues like this. The evil part, is that the problems are erratic. You may get away with this for a while, and then, things stop working.
Wayne
I am using wxdev C++ and it wants to go to program files. When i installed i did not choose that folder the first time, but i installed it to c:\Devccp like you said I also reinstalled the dx9 devpack. The devpak comes with samples, I tried to compile the teapot sample below is the compile log Of course it did not work I am running xp pro
Compiler: Default GCC compiler
Building Makefile: "C:\Dev-Cpp\samples\Makefile.win"
Executing make...
mingw32-make.exe -f "C:\Dev-Cpp\samples\Makefile.win" all
g++.exe -c d3dapp.cpp -o MingW/d3dapp.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/Dev-Cpp/" -I"C:/Dev-Cpp/include/common/wx/msw" -I"C:/Dev-Cpp/include/common/wx/generic" -I"C:/Dev-Cpp/include/common/wx/fl" -I"C:/Dev-Cpp/include/common/wx/gizmos" -I"C:/Dev-Cpp/include/common/wx/html" -I"C:/Dev-Cpp/include/common/wx/mmedia" -I"C:/Dev-Cpp/include/common/wx/net" -I"C:/Dev-Cpp/include/common/wx/ogl" -I"C:/Dev-Cpp/include/common/wx/plot" -I"C:/Dev-Cpp/include/common/wx/protocol" -I"C:/Dev-Cpp/include/common/wx/stc" -I"C:/Dev-Cpp/include/common/wx/svg" -I"C:/Dev-Cpp/include/common/wx/xml" -I"C:/Dev-Cpp/include/common/wx/xrc" -I"C:/Dev-Cpp/include/common/wx" -I"C:/Dev-Cpp/include/common" -D__GNUWIN32__ -Wall -DWIN32 -DNDEBUG -D_WINDOWS -D_MBCS -g3
d3dapp.cpp: In member function
HRESULT CD3DApplication::Initialize3DEnvironment()': d3dapp.cpp:871: error:ULongToHandle' undeclared (first use this function)d3dapp.cpp:871: error: (Each undeclared identifier is reported only once for each function it appears in.)
d3dapp.cpp: In member function `HRESULT CD3DApplication::Reset3DEnvironment()':
d3dapp.cpp:1048: error: `ULongToHandle' undeclared (first use this function)
mingw32-make.exe: *** [MingW/d3dapp.o] Error 1
Execution terminated
You realize how many posts it took you to tell us that you are using wxdwvc++?
You realize that this is not the board supporting that tool?
Wayne
You did Google "ULongToHandle" to find out what it was and where it is defined before posting didn't you? http://cboard.cprogramming.com/showthread.php?t=59466 You might also try updating the Win32API package from www.mingw.org, or through the web update tool (Tools menu). There maybe a a newer version than that installed with Dev-C++, and it may contain the necessary function.
When wxDevCpp started installing to "Program Files", I thought perhaps they had implemented some fix to make this work; but it seems not.
There is another problem with not using c:\dev-cpp as the installation folder. Many if not all DevPak project templates assume that, and have the path hard-coded in their project paths. This is why a large number of the other errors disappeared when you reinstalled.
Clifford
... you might also try removing the line
define WIN32_LEAN_AND_MEAN
That will omit large parts of the Win32 API, and it may be that you already have the necessary files.
I no longer have Dev-C++ installed, so I cannot check.
i asked questions here because the widgets forum NEVER answers, not just me but it seems many people never get an answer, so because wxdev c++ is just an extension of Dev c++ i thought it would be okay to ask here, ( here is where i learned about the DX9 devpak)I did not mention it sooner because i did not think it mattered, sorry. I did google some of those problems i had but do not have enough knowledge to really understand what to do, not clearly anyway. That is why i needed wxdev C++ to work so i can start to learn DX9 by compiling. I will fool around with it a bit more but i think at this point i will just have to bite the bullet and buy a complier that has gui design tools. Wxdev C++ is great and i had fun with making frames. Thanks to you guys for answering so quickly and patiently with me. As a beginner i ask stupid questions If you know where i can get a CHEAP compiler with gui design tools please let me know, preferably one that has no problems with DX9. i will look around for one on the net but i think you will know better than me
> but i think at this point i will just have to bite the
> bullet and buy a complier that has gui design tools.
MSVC++ 2008 Express Edition is free. It has Windows Forms support for visual GUI development. That entails learning a little about the C++/CLI extensions and .NET framework, but frankly it is worth it. That said, I decided to learn C# for .NET development instead. The Free Visual C# Express has a better IDE than the cut down Visual Studio with VC++ EE.
The best thing about the Express Editions are the excellent debug tools.
Take a look at the VC++ EE webste (and C# is you are interested). There are lots of project ideas and free third part tools you can download. If you are interested in DirectX for game development, there is in fact a Game Development Toolkit that will probably save you a lot of work.
You can use VC++ EE for vanilla Win32 code too (but no GUI designer or MFC), and ISO C++.
http://www.microsoft.com/Express/
Clifford
Yeah, i knew about express, I was told express does not have gui design tools but the problem of it is you have to be online to install, for me 98 Megs would be about 6 hours online. leave it to Microsoft to make everything difficult. I asked for a cd on their forum and of course no answer. I will try to get it though. thanks again
> I was told express does not have gui design tools.
Never believe what you are told until you have confirmed it yourself from a reliable source... like the source itself.
> but the problem of it is you have to be online to install,
You can download a DVD ISO image. You'll need a DVD writer, or use "ISO buster" to emulate the DVD from the image. That is an even bigger download, but you can download it unattended. However it is still going to take days at your rate fo 4.6kbps. The Internet has left you behind it seems. Perhaps an Internet cafe, your local library, or a friend, employer or whoever you know with a fast link could help.
There is another option: Borland Turbo Explorer. http://www.turboexplorer.com/ This is the same principle as Microsoft's Express Editions, however you can build Win32 native GUI apps visually using Borland's Visual Component Library rather than .NET/Windows Forms. with the necessary C++/CLI extensions. Some of the limitations on the product are more severe that Microsoft's however. Like you can only install one Turbo product on a single machine (although I reckon you could wok around that with a virtual machine if necessary. Not sure if you can use DirectX with it though. Of course it probably does not help you, it is a 390Mb download.
Clifford