• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

theJ89

Members
  • Content count

    15
  • Joined

  • Last visited

Community Reputation

122 Neutral

About theJ89

  • Rank
    Member
  1. I stumbled upon this ancient thread the other day looking for a solution to the same problem, and I've been reading through it and all the related materials that jyk had posted. It's been a great amount of help to me so far, but I'm having trouble understanding a few things. Looking on Wikipedia's page for the Seperating Axis Theorem, it mentions that this is an intersection test for convex polygons, but doesn't that imply that the two shapes must contain at least 3 vertices each? A line segment would only contain two vertices; is the line segment being treated like a collapsed triangle? Second, for the cross products I noticed you posted: boxExtents.Dot(abs(axis[sub]i[/sub])) I understand that (for the purposes of finding the box "radius") you are making the axis vector's components all positive, but wouldn't this result in an axis pointed in a different direction in some cases? I figured that you would have to change the sign of the x/y/z/ values of the box extents vector depending on what octant the axis vector was located in to get the "radius", but by making the axis vector all positive, and keeping the box extents vector constant, you're acheiving the same result with less work? Third, if this test was being performed in 2D (i.e. a 2D AABB and a 2D line segment) wouldn't you have to test the axis perpendicular to the line segment? Why does this not have to be done in 3D? Do the cross-products take the place of this test (since they're all perpendicular to the line segment)? Fourth, can you give an example of a line segment and AABB that only the cross product tests could detect a non-collision on? Thanks, theJ89 PS: jyk, if you're still around, you might want to change the metanet tutorial link: http://www.metanetsoftware.com/technique/tutorialA.html
  2. Hello again, GameDev. Here's a bit of background behind what I'm trying to accomplish: After rendering my 3D game world I want to render a simple 2D HUD on top of that. To start, I want to draw a simple, untextured solid triangle to the screen. The problem is I'm not really sure how to approach this. In the past, I've used an XYZ vertex format for 3D drawing and an XYZRHW vertex format for 2D drawing. Does this mean I'll have to swap between vertex formats to swap between 3D and 2D drawing? Or is it better to just set up the view/projection matrices in such a way to accomplish the same effect? Second issue, render states and matrices. Anything I should reset before swapping to 2D drawing? Any other pitfalls I should look out for? Thanks for your time, theJ89
  3. Thanks guys, I'll try them out and see what the results are. Edit: Doing sleep worked fine. Thanks for the help, guys! [Edited by - theJ89 on January 22, 2007 8:54:32 PM]
  4. Hey, recently I've taken to making an application that uses Direct 3D to draw a rotating cube. I've initilized Direct X, set up the matrices, and drawn my cube with the vertex buffer and index buffer. However, whenever I start the application, it uses up 50% of my processor! Why is this? Here is the source code: #include <windows.h> #include <d3d9.h> #include <d3dx9.h> #include <time.h> #define WIN32_LEAN_AND_MEAN //Vertex FVF and Vertex Structure const DWORD VERTEX_FLAGS = (D3DFVF_XYZ | D3DFVF_DIFFUSE); struct Vertex3D { float x,y,z; D3DCOLOR color; }; //Application Name const LPCTSTR pszAppName="theJ89's Direct3D Test"; //Instance and Window HINSTANCE hInst=NULL; HWND hWnd=NULL; bool bRun=true; float i=0.0f; //Direct3D interfaces. IDirect3D9* d3d=NULL; IDirect3DDevice9* d3dDevice=NULL; IDirect3DVertexBuffer9* d3dVertexBuffer=NULL; IDirect3DIndexBuffer9* d3dIndexBuffer=NULL; //Vertices Vertex3D cubeVerts[] = { {-1.0f, 1.0f,-1.0f, D3DCOLOR_COLORVALUE( 1.0, 0.0, 0.0, 1.0 ) }, // 0 { 1.0f, 1.0f,-1.0f, D3DCOLOR_COLORVALUE( 0.0, 1.0, 0.0, 1.0 ) }, // 1 {-1.0f,-1.0f,-1.0f, D3DCOLOR_COLORVALUE( 0.0, 0.0, 1.0, 1.0 ) }, // 2 { 1.0f,-1.0f,-1.0f, D3DCOLOR_COLORVALUE( 1.0, 1.0, 0.0, 1.0 ) }, // 3 {-1.0f, 1.0f, 1.0f, D3DCOLOR_COLORVALUE( 1.0, 0.0, 1.0, 1.0 ) }, // 4 {-1.0f,-1.0f, 1.0f, D3DCOLOR_COLORVALUE( 0.0, 1.0, 1.0, 1.0 ) }, // 5 { 1.0f, 1.0f, 1.0f, D3DCOLOR_COLORVALUE( 1.0, 1.0, 1.0, 1.0 ) }, // 6 { 1.0f,-1.0f, 1.0f, D3DCOLOR_COLORVALUE( 1.0, 0.0, 0.0, 1.0 ) } // 7 }; //Indices WORD cubeIndices[] = { 0, 1, 2, 3, // Quad 0 4, 5, 6, 7, // 1 4, 6, 0, 1, // 2 5, 2, 7, 3, // 3 1, 6, 3, 7, // 4 0, 2, 4, 5 // 5 }; //Alert displays a message box with the name of the application, an "OK" button, an exclamation mark and the intended message. void Alert(LPCTSTR pszMessage) { if(hWnd!=NULL){ MessageBox(hWnd,pszMessage,pszAppName,MB_OK | MB_ICONEXCLAMATION); } else { MessageBox(NULL,pszMessage,pszAppName,MB_OK | MB_ICONEXCLAMATION); } } //Confirm is like alert, but instead it has a question icon, yes/no buttons, and it returns the user's choice - true for yes and false for no. bool Confirm(LPCTSTR pszMessage) { int returnedValue=0; if(hWnd!=NULL){ returnedValue=MessageBox(hWnd,pszMessage,pszAppName,MB_YESNO | MB_ICONQUESTION); } else { returnedValue=MessageBox(NULL,pszMessage,pszAppName,MB_YESNO | MB_ICONQUESTION); } if(returnedValue==IDYES){ return true; } else { return false; } } //Message Handler for windows LRESULT CALLBACK WndProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam) { switch(uMessage) { case WM_DESTROY: bRun=false; break; case WM_LBUTTONDOWN: if(Confirm("Do you want to quit now?")){ bRun=false; } break; default: break; } return DefWindowProc(hWnd,uMessage,wParam,lParam); } HRESULT MakeWindow(HINSTANCE hInstance) { WNDCLASSEX wc; wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = NULL; wc.hCursor = NULL; wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = "DXTest3D"; wc.hIconSm = NULL; if(!RegisterClassEx(&wc)){ Alert("Could not register window class."); return E_FAIL; } if(!(hWnd=CreateWindowEx(NULL,"DXTest3D",pszAppName,WS_CAPTION | WS_VISIBLE,0,0,640,480,NULL,NULL,hInstance,NULL))){ Alert("Could not create window."); return E_FAIL; } return true; } HRESULT InitD3D() { //Create D3D interface if(NULL==(d3d=Direct3DCreate9(D3D_SDK_VERSION))){ Alert("D3D failed to initilize!"); return E_FAIL; } //Adapter information, need this for presentation params below to get backbuffer format D3DDISPLAYMODE d3ddm; d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&d3ddm); //Presentation Params D3DPRESENT_PARAMETERS d3dpp; ZeroMemory( &d3dpp, sizeof(d3dpp) ); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = d3ddm.Format; d3dpp.EnableAutoDepthStencil = TRUE; d3dpp.AutoDepthStencilFormat = D3DFMT_D16; d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; //Create D3D Device Interface to let us do most Direct 3D related things. Presentation params above are passed to this. if(FAILED(d3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_HARDWARE_VERTEXPROCESSING,&d3dpp,&d3dDevice))) { Alert("D3D failed to create the device!"); return E_FAIL; } d3dDevice->SetRenderState(D3DRS_LIGHTING,false); d3dDevice->SetRenderState(D3DRS_ZENABLE,true); D3DXMATRIX matProj; D3DXMatrixPerspectiveFovLH( &matProj, D3DXToRadian( 45.0f ), 640.0f / 480.0f, 0.1f, 100.0f ); d3dDevice->SetTransform( D3DTS_PROJECTION, &matProj ); if(FAILED(d3dDevice->CreateVertexBuffer(8*sizeof(Vertex3D),D3DUSAGE_WRITEONLY,VERTEX_FLAGS,D3DPOOL_DEFAULT,&d3dVertexBuffer,NULL))) { Alert("D3D failed to create the vertex buffer!"); return E_FAIL; } //This is (I think) the location of the vertex buffer on video memory. Lock sets this on the line below. void* pVerts=NULL; d3dVertexBuffer->Lock(0,sizeof(cubeVerts),(void**)&pVerts,0); memcpy(pVerts,cubeVerts,sizeof(cubeVerts)); d3dVertexBuffer->Unlock(); if(FAILED(d3dDevice->CreateIndexBuffer(24*sizeof(WORD),D3DUSAGE_WRITEONLY,D3DFMT_INDEX16,D3DPOOL_DEFAULT,&d3dIndexBuffer,NULL))) { Alert("D3D failed to create the index buffer!"); return E_FAIL; } //This is (I think) the location of the index buffer on video memory. Lock sets this on the line below. WORD* pIndices = NULL; d3dIndexBuffer->Lock(0,sizeof(cubeIndices),(void**)&pIndices,0); memcpy(pIndices,cubeIndices,sizeof(cubeIndices)); d3dIndexBuffer->Unlock(); return S_OK; } void render() { d3dDevice->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,D3DCOLOR_XRGB(0,0,0),1.0f,0); D3DXMATRIX matTrans; D3DXMATRIX matRot; D3DXMATRIX matWorld; D3DXMatrixTranslation( &matTrans, 0.0f, 0.0f, 5.0f+(i/25) ); //D3DXToRadian() i=i+0.02f; if(i>=360.0f){ i=i-360.0f; } D3DXMatrixRotationYawPitchRoll( &matRot, D3DXToRadian(i), D3DXToRadian(i), 0); matWorld = matRot * matTrans; d3dDevice->SetTransform( D3DTS_WORLD, &matWorld ); d3dDevice->BeginScene(); d3dDevice->SetStreamSource( 0, d3dVertexBuffer, 0, sizeof(Vertex3D) ); d3dDevice->SetIndices(d3dIndexBuffer); d3dDevice->SetFVF(VERTEX_FLAGS); d3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLESTRIP, 0, 0, 8, 0, 2 ); d3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLESTRIP, 0, 0, 8, 4, 2 ); d3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLESTRIP, 0, 0, 8, 8, 2 ); d3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLESTRIP, 0, 0, 8, 12, 2 ); d3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLESTRIP, 0, 0, 8, 16, 2 ); d3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLESTRIP, 0, 0, 8, 20, 2 ); d3dDevice->EndScene(); d3dDevice->Present(NULL,NULL,NULL,NULL); } void shutDown( void ) { if( d3dIndexBuffer!=NULL) d3dIndexBuffer->Release(); if(d3dVertexBuffer!=NULL) d3dVertexBuffer->Release(); if(d3dDevice!=NULL) d3dDevice->Release(); if( d3d!=NULL ) d3d->Release(); } //Main windows function. Message loop, initilizes Direct X and renders the scene. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCommandLine, int nCommandShow) { MSG msg; hInst=hInstance; ZeroMemory(&msg,sizeof(msg)); if(FAILED(MakeWindow(hInst))){ shutDown(); return 0; } if(FAILED(InitD3D())){ shutDown(); return 0; } while(bRun) { //Exactly what is the difference between PeekMessage and GetMessage? if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } render(); } shutDown(); return 1; } The example I was following: http://www.codesampler.com/dx9src/dx9src_2.htm#dx9_indexed_geometry If you need any additional information, just ask.
  5. Oh! Yes, one last thing if you will. I am having trouble using diffusion to color my quads. For some reason, they become a jumble of red and black lines. For the time being, D3DFVF_DIFFUSE has been removed from the FVF. Do you know a possible solution for this?
  6. Quote:Original post by Serapth Keep in mind, alot of what im about to say is nitpicking. Just the little stuff you might not see or care about. First of, you really should consider using STL classes instead of fixed sized containers, you would make your code a whole lot easier. Thanks for the reply. I am considering using Linked lists or vectors, which ever is faster. Quote:Original post by Serapth That said, for the most part it all looks good. This is going to sound like an odd compliment, but your commenting style is very good. You actually write comments that might help you, as opposed to doing it "because your supposed to" or *shudder* not doing it at all. Thank you, when I was working on a game project written in javascript (it was a scripted game created with HTML) I made sure that I commented each function specifically so that if someone else were to read it, it would help them out. I'm kind of being slack on this because I'm not taking it as seriously as I should be. Quote:Original post by Serapth #defines are nasty evil. Switch them to const strings. This makes a night and day difference when debugging, and for other people working with your code. I've been wondering why this is. From what I can tell #define just replaces all instances of the keyword with the given code when it's building the source files. I can see how this would considerably increase the size of the file if, say for example you defined a string and then used the keyword all over the file, thus creating the same string in several places in the file which would be un-necessary. From what I understand consts are just read-only memory. The reason I was using defines is that I didn't want to take up unnecessary memory for things that were not called very often. Quote:Original post by Serapth *** Source Snippet Removed *** Is a bug waiting to happen. In debug mode, the compiler zeros all memory, however in release it doesnt. If you dont implicity ZeroMemory() or memset() to 0 cImages array, this code could lead to a hard to find bug down the road. ( Another reason to use vectors [smile] ) Also, this is a matter of opinion, but move oIndex out of the for loop and replace it with a break statement. Its much easier to read and maintain: *** Source Snippet Removed *** I havent gotten to where cImages[index] was called ( Aka, the call to new Image() ), but if you newed the Image() this is a memory leak. Image::~Image() { cImages[index]=NULL; } EDIT::: NOPE, not a memory leak, you statically declared every Image. Still leaving this comment in as an object lesson to others that might read this, or for yourself if you decide to go more dynamic in the future. Actually, cImages is not used for dynamically allocating images in. It's used for keeping track of images in the program. Now that you mention it, I should use break. I don't use break very often. Plus, that's one less condition check I need to do in that loop. Quote:Original post by Serapth Potential gotcha bug or exploit: strcat(message, "Cannot load texture "); strcat(message, pszImgPath); strcat(message, " - No available slots."); Alert(message); If pszImgPath ends up being really long, you can have a buffer overflow here. Probrably not a big deal, but still worth checking the size of pszImgPath before copying to an memory buffer with a fixed sized limit ( 255 ). Youu repeat this behavour a few times. Ahhh, yeah, I noticed this here! I couldn't come up with an acceptable solution so I just left it that way. With other languages I don't have to worry about buffer sizes so I don't really know a solution to it offhand. Quote:Original post by Serapth Call me Mr Anti compound logic in an if statement guy, but I would break this into two tests. Keep in mind, the compiler compiles it down to the same code in the end: if(cImages[i]!=NULL&&cImages[i]->show) I figured it was just a matter of style. According to a book on C++ I read if the first condition is false none of the other conditions are even considered - but, the way you mentioned is usually the way I do it. Quote:Original post by Serapth Finally: Image MyImages[100]={ Image(0,0,32,32,dx3d.d3dTextures[0]), Image(32,0,32,32,dx3d.d3dTextures[0]), Image(64,0,32,32,dx3d.d3dTextures[0]), Image(96,0,32,32,dx3d.d3dTextures[0]), <snip><snip> My god man, put that in a loop! ;) You could drop about 70+ lines of code easily there. Also, ill use this time once again to recommend vectors :) Oh god I know. I was hoping to use a default constructer and then manually move them in a loop but then C++ threw the whole "you can't a default constructor with arguments" crap at me. Oh well. Quote:Original post by Serapth for(int y = 0; y < 10; y ++) { for(int x = 0; x< 10; x++) { Image(x*32,y*32,32,32,dx3d.d3dTextures[0]) } } Only problem I can see here is that "Image" isn't stored in a variable. It needs to be, the only thing that cImages does is point to existing images. Thanks for all of the help, I'll be working on my code to see if I can improve it.
  7. Quote:Original post by Serapth You will probrably get alot more responses if you post the code in with your posts instead of getting people to download it. Just paste it into [ source ] and [ / source] blocks in your post ( loose the spaces though ). From your description, is there a reason you are using fixed sized arrays instead of Vectors? If not, without having read your code that would be my first suggestion. I will have more if you post the code in [smile] Thank you for the reply! I'll post the code in source tags now. I have been told Vectors are slow for fast access purposes, so I have been using arrays.
  8. I've updated the first post to be more organized and detailed.
  9. Hello. I'm finally completed with my first application in Direct X. However I get the feeling that it's really messy and inefficent. Would anybody like to help me out? I've got the actual application and source code posted at this location. http://www.guilddnr.net/dunescape/d3d_app.rar (this code was compiled with Visual C++ .NET 2003 edition, with the Direct X 9.0c SDK) Additionally, here is the code plainly: //theJ89's Direct X Test and window creation program #include <windows.h> //Includes windows, #include <d3d9.h> //D3D, #include <time.h> //D3D, #include <d3dx9.h> //D3D, #include <dxerr9.h> //and the D3D error handler? //Removes rarely used things in windows. #define WIN32_LEAN_AND_MEAN //Describes the format of the vertex... //Even though I make my own custom vertex structure I think it has to conform to these specifications. #define POINT_FLAGS (D3DFVF_XYZRHW | D3DFVF_TEX1) //Width and height of the menu along with the name of my program. #define APP_NAME "theJ89's DirectX Test Program" #define SCREEN_WIDTH 1024 #define SCREEN_HEIGHT 768 #define MAX_TEXTURES 16 #define MAX_QUADS 256 //Window and instance pointers HWND window; HINSTANCE hInst; //Program stops running when bRun is set to false bool bRun=true; //Alert displays a message box with the name of the application, an "OK" button, an exclamation mark and the intended message. void Alert(LPCTSTR lpMessage) { ShowCursor(true); if(window!=NULL){ MessageBox(window,lpMessage,APP_NAME,MB_OK | MB_ICONEXCLAMATION); } else { MessageBox(NULL,lpMessage,APP_NAME,MB_OK | MB_ICONEXCLAMATION); } ShowCursor(false); } //Confirm is like alert, but instead it has a question icon, yes/no buttons, and it returns the user's choice - true for yes and false for no. bool Confirm(LPCTSTR lpMessage) { ShowCursor(true); int returnedValue=0; if(window!=NULL){ returnedValue=MessageBox(window,lpMessage,APP_NAME,MB_YESNO | MB_ICONQUESTION); } else { returnedValue=MessageBox(NULL,lpMessage,APP_NAME,MB_YESNO | MB_ICONQUESTION); } ShowCursor(false); if(returnedValue==IDYES){ return true; } else { return false; } } //This is my vertex format, according to the second DX3D tutorial. It's got X, Y, and Z along with a reciprocol homogeneous w component and the color. struct Vertex2D { float x,y,z,rhw,u,v; D3DCOLOR color; }; //This is my array of vertices, arranged like so: /* 1----2 | / | | / | 0----3 */ Vertex2D vertices[MAX_QUADS*4]; class Image { public: Image(); Image(float x, float y, float width, float height, IDirect3DTexture9* cTex); ~Image(); void Move(float x, float y); void UpdateVerts(); bool show; float x,y,width,height,rotation; short unsigned int index; D3DCOLOR color; IDirect3DTexture9* cSource; }; Image* cImages[MAX_QUADS]; Image::Image() { //Init index to -1; find open slot. int oIndex=-1; for(int i=0; i<MAX_QUADS&&oIndex<0; i++) { if(cImages[i]==NULL) { oIndex=i; } } if(oIndex<0) { Alert("Attempted to create image but no open slots."); return; } else { index=oIndex; } cImages[index]=this; this->show=false; this->cSource=NULL; this->x=0; this->y=0; this->width=0; this->height=0; this->rotation=0.0f; //Set U, V coordinates and RHW, Z, and Color to defaults vertices[(index*4)].u=0.0f; vertices[(index*4)].v=1.0f; vertices[(index*4)+1].u=0.0f; vertices[(index*4)+1].v=0.0f; vertices[(index*4)+2].u=1.0f; vertices[(index*4)+2].v=0.0f; vertices[(index*4)+3].u=1.0f; vertices[(index*4)+3].v=1.0f; for(int i=0; i<4; i++) { vertices[(index*4)+i].rhw=1.0f; vertices[(index*4)+i].z=1.0f; vertices[(index*4)+i].color=0xFFFFFFFF; } //Set X/Y positions UpdateVerts(); } Image::Image(float x, float y, float width, float height, IDirect3DTexture9* cTex) { //Init index to -1; find open slot. int oIndex=-1; for(int i=0; i<MAX_QUADS&&oIndex<0; i++) { if(cImages[i]==NULL) { oIndex=i; } } if(oIndex<0) { Alert("Attempted to create image but no open slots."); return; } else { index=oIndex; } cImages[index]=this; this->show=true; this->cSource=cTex; this->x=x; this->y=y; this->width=width; this->height=height; this->rotation=0.0f; //Set U, V coordinates and RHW, Z, and Color to defaults vertices[(index*4)].u=0.0f; vertices[(index*4)].v=1.0f; vertices[(index*4)+1].u=0.0f; vertices[(index*4)+1].v=0.0f; vertices[(index*4)+2].u=1.0f; vertices[(index*4)+2].v=0.0f; vertices[(index*4)+3].u=1.0f; vertices[(index*4)+3].v=1.0f; for(int i=0; i<4; i++) { vertices[(index*4)+i].rhw=1.0f; vertices[(index*4)+i].z=1.0f; vertices[(index*4)+i].color=0xFFFFFFFF; } //Set X/Y positions UpdateVerts(); } Image::~Image() { cImages[index]=NULL; } void Image::Move(float x, float y) { this->x=x; this->y=y; UpdateVerts(); } void Image::UpdateVerts() { vertices[(index*4)].x=x; vertices[(index*4)].y=y+height; vertices[(index*4)+1].x=x; vertices[(index*4)+1].y=y; vertices[(index*4)+2].x=x+width; vertices[(index*4)+2].y=y; vertices[(index*4)+3].x=x+width; vertices[(index*4)+3].y=y+height; } //DXGraphics is my singleton class to handle the Direct 3D interface, the device, the vertex buffer, rendering, and manage creation and cleanup. //Currently I have the Render function set to draw a triangle fan that forms a rect as you can tell by the vertices. class DXGraphics { public: IDirect3DTexture9* d3dTextures[MAX_TEXTURES]; //Constructor, makes sure all pointers are initilized to NULL DXGraphics() { d3d=NULL; d3dDevice=NULL; d3dVertexBuffer=NULL; for(int i=0; i<MAX_TEXTURES; i++) { d3dTextures[i]=NULL; } } //Destructor, releases the vertex buffers, device, and d3d interface ~DXGraphics() { for(int i=0; i<MAX_TEXTURES; i++) { if(d3dTextures[i]!=NULL) d3dTextures[i]->Release(); } if(d3dVertexBuffer!=NULL) d3dVertexBuffer->Release(); if(d3dDevice!=NULL) d3dDevice->Release(); if(d3d!=NULL) d3d->Release(); } //Initilizes the interface and allows me to create the device... HRESULT createD3D() { if(NULL==(d3d=Direct3DCreate9(D3D_SDK_VERSION))) { Alert("Could not create Direct3D object."); return E_FAIL; } Alert("Successfully created Direct3D object!"); return S_OK; } //Creates the device used to handle... um, pretty much everything. HRESULT createDevice() { D3DPRESENT_PARAMETERS d3dPresent; ZeroMemory(&d3dPresent,sizeof(d3dPresent)); d3dPresent.Windowed=TRUE; d3dPresent.SwapEffect=D3DSWAPEFFECT_DISCARD; d3dPresent.BackBufferFormat=D3DFMT_UNKNOWN; if( FAILED( d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dPresent, &d3dDevice))) { Alert("Could not create device!"); return E_FAIL; } Alert("Created device successfully!"); d3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE); d3dDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA); d3dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA); d3dDevice->SetFVF(POINT_FLAGS); return S_OK; } HRESULT loadTexture(const char* pszImgPath) { int iEmpty=-1; char message[255]; char cBuffer[33]; ZeroMemory(&message,sizeof(message)); for(int i=0; i<MAX_TEXTURES&&iEmpty<0; i++) { if(d3dTextures[i]==NULL) iEmpty=i; } if(iEmpty<0) { strcat(message, "Cannot load texture "); strcat(message, pszImgPath); strcat(message, " - No available slots."); Alert(message); return E_FAIL; } if(FAILED(D3DXCreateTextureFromFile(d3dDevice, pszImgPath, &d3dTextures[iEmpty]))){ strcat(message, "Attempting to load texture "); strcat(message, pszImgPath); strcat(message, " has failed."); Alert(message); return E_FAIL; } strcat(message, "Loading texture "); strcat(message, pszImgPath); itoa(iEmpty,cBuffer,10); strcat(message, "(slot "); strcat(message, cBuffer); strcat(message, ")"); strcat(message, " has succeeded!"); Alert(message); return S_OK; } //Creates a vertex buffer for my polygons. HRESULT createVertexBuffer() { if( FAILED( d3dDevice->CreateVertexBuffer(MAX_QUADS*4*sizeof(Vertex2D),0, POINT_FLAGS, D3DPOOL_DEFAULT, &d3dVertexBuffer, NULL ) ) ) { Alert("Could not create vertex buffer!"); return E_FAIL; } Alert("Created vertex buffer!"); return S_OK; } //Copies the vertexes from the array in physical memory to the buffer on video memory, if I understood that correctly. HRESULT fillVertexBuffer() { VOID* pVertices; if(FAILED(d3dVertexBuffer->Lock(0,sizeof(vertices),(void**)&pVertices,0))) { Alert("Attempting to fill the vertex buffer has failed!"); return E_FAIL; } memcpy(pVertices,vertices,sizeof(vertices)); d3dVertexBuffer->Unlock(); //Alert("The vertex buffer has been filled!"); return S_OK; } //Clears the back buffer to black, starts drawing the scene, //sets the stream to the buffer, sets the vertex format (I don't think //it should be here but whatever works), and lastly draws the //primative - a triangle fan comprised of the four vertices. //From there it just ends the scene and displays it. void Render() { if(d3dDevice!=NULL) { d3dDevice->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0),1.0f,0); if(SUCCEEDED(d3dDevice->BeginScene())) { d3dDevice->SetStreamSource(0,d3dVertexBuffer,0,sizeof(Vertex2D)); for(int i=0;i<MAX_QUADS;i++) { if(cImages[i]!=NULL&&cImages[i]->show) { d3dDevice->SetTexture(0,cImages[i]->cSource); d3dDevice->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_SELECTARG1); d3dDevice->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE); d3dDevice->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE); d3dDevice->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG1); d3dDevice->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE); d3dDevice->SetTextureStageState(0,D3DTSS_ALPHAARG2,D3DTA_DIFFUSE); d3dDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,i*4,2); } } d3dDevice->EndScene(); } d3dDevice->Present(NULL,NULL,NULL,NULL); } } private: IDirect3D9* d3d; IDirect3DDevice9* d3dDevice; IDirect3DVertexBuffer9* d3dVertexBuffer; }; //Creates the singleton object that handles Direct3D DXGraphics dx3d; Image* pMyImage=NULL; //Message Handler for windows LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam) { POINTS coords; switch(uMessage) { case WM_DESTROY: bRun=false; break; case WM_MOUSEMOVE: coords = MAKEPOINTS (lParam); if(pMyImage!=NULL) { pMyImage->Move(coords.x-16,coords.y-16); } break; case WM_LBUTTONDOWN: Alert("Left mouse button pressed. Goodbye!"); bRun=false; break; /* case WM_PAINT: dx3d.Render(); ValidateRect( hWnd, NULL ); break; */ default: break; } return DefWindowProc(hWnd,uMessage,wParam,lParam); } //I made a function to create a window because I like having everything for this in one function. int MakeWindow(HINSTANCE hInstance) { WNDCLASSEX wc; wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WindowProcedure; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = NULL; wc.hCursor = NULL; wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = "DXTest"; wc.hIconSm = NULL; if(!RegisterClassEx(&wc)) return false; window=CreateWindowEx(NULL,"DXTest",APP_NAME,WS_CAPTION | WS_VISIBLE,0,0,SCREEN_WIDTH,SCREEN_HEIGHT,NULL,NULL,hInstance,NULL); if(!window) return false; return true; } //Main windows function. Message loop, initilizes Direct X and renders the scene. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCommandLine, int nCommandShow) { MSG msg; hInst=hInstance; int iTime=time(NULL); int framecount=0; float fps=1; ZeroMemory(&vertices,sizeof(vertices)); for(int i=0; i<MAX_QUADS; i++) { cImages[i]=NULL; } MakeWindow(hInst); ShowCursor(false); if(FAILED(dx3d.createD3D())) return 0; if(FAILED(dx3d.createDevice())) return 0; if(FAILED(dx3d.createVertexBuffer())) return 0; if(FAILED(dx3d.loadTexture("tex.tga"))) return 0; if(FAILED(dx3d.loadTexture("cursor.tga"))) return 0; Image MyImages[100]={ Image(0,0,32,32,dx3d.d3dTextures[0]), Image(32,0,32,32,dx3d.d3dTextures[0]), Image(64,0,32,32,dx3d.d3dTextures[0]), Image(96,0,32,32,dx3d.d3dTextures[0]), Image(128,0,32,32,dx3d.d3dTextures[0]), Image(160,0,32,32,dx3d.d3dTextures[0]), Image(192,0,32,32,dx3d.d3dTextures[0]), Image(224,0,32,32,dx3d.d3dTextures[0]), Image(256,0,32,32,dx3d.d3dTextures[0]), Image(288,0,32,32,dx3d.d3dTextures[0]), Image(0,32,32,32,dx3d.d3dTextures[0]), Image(32,32,32,32,dx3d.d3dTextures[0]), Image(64,32,32,32,dx3d.d3dTextures[0]), Image(96,32,32,32,dx3d.d3dTextures[0]), Image(128,32,32,32,dx3d.d3dTextures[0]), Image(160,32,32,32,dx3d.d3dTextures[0]), Image(192,32,32,32,dx3d.d3dTextures[0]), Image(224,32,32,32,dx3d.d3dTextures[0]), Image(256,32,32,32,dx3d.d3dTextures[0]), Image(288,32,32,32,dx3d.d3dTextures[0]), Image(0,64,32,32,dx3d.d3dTextures[0]), Image(32,64,32,32,dx3d.d3dTextures[0]), Image(64,64,32,32,dx3d.d3dTextures[0]), Image(96,64,32,32,dx3d.d3dTextures[0]), Image(128,64,32,32,dx3d.d3dTextures[0]), Image(160,64,32,32,dx3d.d3dTextures[0]), Image(192,64,32,32,dx3d.d3dTextures[0]), Image(224,64,32,32,dx3d.d3dTextures[0]), Image(256,64,32,32,dx3d.d3dTextures[0]), Image(288,64,32,32,dx3d.d3dTextures[0]), Image(0,96,32,32,dx3d.d3dTextures[0]), Image(32,96,32,32,dx3d.d3dTextures[0]), Image(64,96,32,32,dx3d.d3dTextures[0]), Image(96,96,32,32,dx3d.d3dTextures[0]), Image(128,96,32,32,dx3d.d3dTextures[0]), Image(160,96,32,32,dx3d.d3dTextures[0]), Image(192,96,32,32,dx3d.d3dTextures[0]), Image(224,96,32,32,dx3d.d3dTextures[0]), Image(256,96,32,32,dx3d.d3dTextures[0]), Image(288,96,32,32,dx3d.d3dTextures[0]), Image(0,128,32,32,dx3d.d3dTextures[0]), Image(32,128,32,32,dx3d.d3dTextures[0]), Image(64,128,32,32,dx3d.d3dTextures[0]), Image(96,128,32,32,dx3d.d3dTextures[0]), Image(128,128,32,32,dx3d.d3dTextures[0]), Image(160,128,32,32,dx3d.d3dTextures[0]), Image(192,128,32,32,dx3d.d3dTextures[0]), Image(224,128,32,32,dx3d.d3dTextures[0]), Image(256,128,32,32,dx3d.d3dTextures[0]), Image(288,128,32,32,dx3d.d3dTextures[0]), Image(0,160,32,32,dx3d.d3dTextures[0]), Image(32,160,32,32,dx3d.d3dTextures[0]), Image(64,160,32,32,dx3d.d3dTextures[0]), Image(96,160,32,32,dx3d.d3dTextures[0]), Image(128,160,32,32,dx3d.d3dTextures[0]), Image(160,160,32,32,dx3d.d3dTextures[0]), Image(192,160,32,32,dx3d.d3dTextures[0]), Image(224,160,32,32,dx3d.d3dTextures[0]), Image(256,160,32,32,dx3d.d3dTextures[0]), Image(288,160,32,32,dx3d.d3dTextures[0]), Image(0,192,32,32,dx3d.d3dTextures[0]), Image(32,192,32,32,dx3d.d3dTextures[0]), Image(64,192,32,32,dx3d.d3dTextures[0]), Image(96,192,32,32,dx3d.d3dTextures[0]), Image(128,192,32,32,dx3d.d3dTextures[0]), Image(160,192,32,32,dx3d.d3dTextures[0]), Image(192,192,32,32,dx3d.d3dTextures[0]), Image(224,192,32,32,dx3d.d3dTextures[0]), Image(256,192,32,32,dx3d.d3dTextures[0]), Image(288,192,32,32,dx3d.d3dTextures[0]), Image(0,224,32,32,dx3d.d3dTextures[0]), Image(32,224,32,32,dx3d.d3dTextures[0]), Image(64,224,32,32,dx3d.d3dTextures[0]), Image(96,224,32,32,dx3d.d3dTextures[0]), Image(128,224,32,32,dx3d.d3dTextures[0]), Image(160,224,32,32,dx3d.d3dTextures[0]), Image(192,224,32,32,dx3d.d3dTextures[0]), Image(224,224,32,32,dx3d.d3dTextures[0]), Image(256,224,32,32,dx3d.d3dTextures[0]), Image(288,224,32,32,dx3d.d3dTextures[0]), Image(0,256,32,32,dx3d.d3dTextures[0]), Image(32,256,32,32,dx3d.d3dTextures[0]), Image(64,256,32,32,dx3d.d3dTextures[0]), Image(96,256,32,32,dx3d.d3dTextures[0]), Image(128,256,32,32,dx3d.d3dTextures[0]), Image(160,256,32,32,dx3d.d3dTextures[0]), Image(192,256,32,32,dx3d.d3dTextures[0]), Image(224,256,32,32,dx3d.d3dTextures[0]), Image(256,256,32,32,dx3d.d3dTextures[0]), Image(288,256,32,32,dx3d.d3dTextures[0]), Image(0,288,32,32,dx3d.d3dTextures[0]), Image(32,288,32,32,dx3d.d3dTextures[0]), Image(64,288,32,32,dx3d.d3dTextures[0]), Image(96,288,32,32,dx3d.d3dTextures[0]), Image(128,288,32,32,dx3d.d3dTextures[0]), Image(160,288,32,32,dx3d.d3dTextures[0]), Image(192,288,32,32,dx3d.d3dTextures[0]), Image(224,288,32,32,dx3d.d3dTextures[0]), Image(256,288,32,32,dx3d.d3dTextures[0]), Image(288,288,32,32,dx3d.d3dTextures[0]) }; Image Cursor=Image(288,288,32,32,dx3d.d3dTextures[1]); pMyImage=&Cursor; for(int i=0; i<100; i++) { MyImages[i]; } while (bRun) { framecount++; if(time(NULL)>iTime) { fps=framecount; framecount=0; } //Exactly what is the difference between PeekMessage and GetMessage? if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } //The vertex buffer is filled each frame because I used to have something that moved the vertexes one pixel each frame, and needed to refresh the buffer. dx3d.fillVertexBuffer(); //Last step, render the scene with the singleton's functions. dx3d.Render(); } return 0; } I've created two classes to handle Direct 3D, for the most part - DXGraphics and Image - and of course a custom struct for my vertex which contains x,y,z,rhw,u,v, and a D3DCOLOR. As you can tell by the RHW parameter, I am making a 2D application with Direct 3D. I have defined the max number of quads (256 last I checked) and the max number of textures (16). These limits are set when the application is compiled. The size of the vertex buffer, and the size of my global vertex array is equal to MAX_QUADS*4. My class, DXGraphics, contains the array of textures (however it is not a static variable, instead it is simply an array of IDirect3DTexture9 the size of MAX_TEXTURES (16)). Only one object is of the DXGraphics class, and I call it dx3d. Whenever my DXGraphics object constructs, it sets all of it's interface pointers to NULL. Likewise it releases all of the interfaces not equal to NULL whenever it's destructed. It contains a D3D interface pointer, Device interface pointer, Vertex Buffer pointer, and of course 16 texture interface pointers for loaded textures (however at the time only two are used). I have functions created for initilizing each of these interfaces. Additionally in DXGraphics there are also functions for filling the vertex buffer and rendering. My image class, Image, is used to handle and display quads. Image contains the float variables X, Y, Width, Height, and Rotation. Additionally there is the integer value index, a boolean value show which determines if the Image is drawn, and a D3DCOLOR (also integer I believe but whatever) variable Color. The image class contains functions for constructing and destructing the Image class, Moving the image onscreen, and updating the vertices. Every Image when constructed is automatically placed in the first available slot in a global array of Image pointers. Likewise when the Image is destructed the pointer is set to NULL. The vertices associated with the Image are determined by the Image's index in this array - so, if it's index was 5, then the vertices associated with it would be 20,21,22, and 23, because 5*4=20. This keeps track of the Images so that the renderer can know what vertices in the array to draw. So far this setup has worked wonderfully for me, but I am very unexperienced and this is only a simple setup. Could you possibly give me some pointers? [Edited by - theJ89 on September 26, 2006 4:32:07 PM]
  10. Well, I've completed the alpha bit. I just had to set a few things in the device when it initilized. But I am still having problems with D3DFVF_DIFFUSE. All but three lines of my code is exactly the same as above (only the createDevice function has changed). How do I use vertex color with textures?
  11. Quote:Original post by EasilyConfused Not sure what you mean about doing it with RHW. Create your vertex format like this: const DWORD D3DFVF_CVERTEX=(D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1); struct CVertex { FLOAT x,y,z,rhw; DWORD color; FLOAT u,v; }; Then just assign u and v the correct texture co-ordinates when you set up the verticies for the quad. Assuming a texture has been selected into the device before you call draw primitive, and that your rhw values are set to 1.0f, texturing will work fine. D3DXLoadTextureFromFileEx will let you load a TGA file I believe. This is a snippet from my 2D D3D set up code that covers the matrixy bit. Dev is the D3DDevice and W and H are the screen width and height. *** Source Snippet Removed *** Thank you for the example, but I have finally figured out the texturing bit. I had to disable D3DFVF_DIFFUSE because if I didn't for some reason the quads would render with dark red and black stripes. So my next question is a two part question. The texture I am using has an alpha layer (it's a 32x32 .tga) that I want to use to hide parts of the texture (the background specifically). So, the first question would have to be how do I set up Direct 3D to use an Alpha Operation that uses the current texture's alpha? My second question is relatively simple. I want to use vertex color diffusion with my vertexes to change the colors of the textured quads, however when I use them strange red and black bar patterns appear on the quad instead of the given texture. How do I set up Direct 3D to render with vertex color diffusion? Here is my current source code: //theJ89's Direct X Test and window creation program #include <windows.h> //Includes windows, #include <d3d9.h> //D3D, #include <d3dx9.h> //D3D, #include <dxerr9.h> //and the D3D error handler? //Removes rarely used things in windows. #define WIN32_LEAN_AND_MEAN //Describes the format of the vertex... //Even though I make my own custom vertex structure I think it has to conform to these specifications. #define POINT_FLAGS (D3DFVF_XYZRHW | D3DFVF_TEX1) //Width and height of the menu along with the name of my program. #define APP_NAME "theJ89's DirectX Test Program" #define SCREEN_WIDTH 1024 #define SCREEN_HEIGHT 768 //Window and instance pointers HWND window; HINSTANCE hInst; //Program stops running when bRun is set to false bool bRun=true; //Alert displays a message box with the name of the application, an "OK" button, an exclamation mark and the intended message. void Alert(LPCTSTR lpMessage) { if(window!=NULL){ MessageBox(window,lpMessage,APP_NAME,MB_OK | MB_ICONEXCLAMATION); } else { MessageBox(NULL,lpMessage,APP_NAME,MB_OK | MB_ICONEXCLAMATION); } } //Confirm is like alert, but instead it has a question icon, yes/no buttons, and it returns the user's choice - true for yes and false for no. bool Confirm(LPCTSTR lpMessage) { int returnedValue=0; if(window!=NULL){ returnedValue=MessageBox(window,lpMessage,APP_NAME,MB_YESNO | MB_ICONQUESTION); } else { returnedValue=MessageBox(NULL,lpMessage,APP_NAME,MB_YESNO | MB_ICONQUESTION); } if(returnedValue==IDYES){ return true; } else { return false; } } //This is my vertex format, according to the second DX3D tutorial. It's got X, Y, and Z along with a reciprocol homogeneous w component and the color. struct Vertex2D { float x,y,z,rhw,u,v; D3DCOLOR color; }; //This is my array of vertices, arranged like so: /* 1----2 | / | | / | 0----3 */ Vertex2D vertices[] = { {0.0f, 32.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0xffffffff}, {0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0xffffffff}, {32.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0xffffffff}, {32.0f, 32.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0xffffffff}, {32.0f, 32.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0xff0000ff}, {32.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0xff0000ff}, {64.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0xff0000ff}, {64.0f, 32.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0xff0000ff} }; //DXGraphics is my singleton class to handle the Direct 3D interface, the device, the vertex buffer, rendering, and manage creation and cleanup. //Currently I have the Render function set to draw a triangle fan that forms a rect as you can tell by the vertices. class DXGraphics { public: //Constructor, makes sure all pointers are initilized to NULL DXGraphics() { d3d=NULL; d3dDevice=NULL; d3dVertexBuffer=NULL; } //Destructor, releases the vertex buffers, device, and d3d interface ~DXGraphics() { if(d3dVertexBuffer!=NULL) d3dVertexBuffer->Release(); if(d3dDevice!=NULL) d3dDevice->Release(); if(d3d!=NULL) d3d->Release(); } //Initilizes the interface and allows me to create the device... HRESULT createD3D() { if(NULL==(d3d=Direct3DCreate9(D3D_SDK_VERSION))) { Alert("Could not create Direct3D object."); return E_FAIL; } Alert("Successfully created Direct3D object!"); return S_OK; } //Creates the device used to handle... um, pretty much everything. HRESULT createDevice() { D3DPRESENT_PARAMETERS d3dPresent; ZeroMemory(&d3dPresent,sizeof(d3dPresent)); d3dPresent.Windowed=TRUE; d3dPresent.SwapEffect=D3DSWAPEFFECT_DISCARD; d3dPresent.BackBufferFormat=D3DFMT_UNKNOWN; if( FAILED( d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dPresent, &d3dDevice))) { Alert("Could not create device!"); return E_FAIL; } Alert("Created device successfully!"); return S_OK; } HRESULT loadTexture(const char* pszImgPath) { char* message=new char[255]; ZeroMemory(message,sizeof(message)); if(FAILED(D3DXCreateTextureFromFile(d3dDevice, pszImgPath, &d3dTexture))){ strcat(message, "Attempting to load texture "); strcat(message, pszImgPath); strcat(message, " has failed."); Alert(message); delete [] message; return E_FAIL; } strcat(message, "Attempting to load texture "); strcat(message, pszImgPath); strcat(message, " has succeeded!"); Alert(message); delete [] message; return S_OK; } //Creates a vertex buffer for my polygons. HRESULT createVertexBuffer() { if( FAILED( d3dDevice->CreateVertexBuffer(4*sizeof(Vertex2D),0, POINT_FLAGS, D3DPOOL_DEFAULT, &d3dVertexBuffer, NULL ) ) ) { Alert("Could not create vertex buffer!"); return E_FAIL; } Alert("Created vertex buffer!"); return S_OK; } //Copies the vertexes from the array in physical memory to the buffer on video memory, if I understood that correctly. HRESULT fillVertexBuffer() { VOID* pVertices; if(FAILED(d3dVertexBuffer->Lock(0,sizeof(vertices),(void**)&pVertices,0))) { Alert("Attempting to fill the vertex buffer has failed!"); return E_FAIL; } memcpy(pVertices,vertices,sizeof(vertices)); d3dVertexBuffer->Unlock(); //Alert("The vertex buffer has been filled!"); return S_OK; } //Clears the back buffer to black, starts drawing the scene, sets the stream to the buffer, sets the vertex format (I don't think it should be here but whatever works), and lastly draws the primative - a triangle fan comprised of the four vertices. From there it just ends the scene and displays it. void Render() { if(d3dDevice!=NULL) { d3dDevice->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0),1.0f,0); if(SUCCEEDED(d3dDevice->BeginScene())) { d3dDevice->SetTexture(0,d3dTexture); d3dDevice->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_SELECTARG1); d3dDevice->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE); d3dDevice->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE); d3dDevice->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG1); d3dDevice->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE); d3dDevice->SetTextureStageState(0,D3DTSS_ALPHAARG2,D3DTA_DIFFUSE); d3dDevice->SetStreamSource(0,d3dVertexBuffer,0,sizeof(Vertex2D)); d3dDevice->SetFVF(POINT_FLAGS); d3dDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,0,2); d3dDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,4,2); d3dDevice->EndScene(); } d3dDevice->Present(NULL,NULL,NULL,NULL); } } private: IDirect3D9* d3d; IDirect3DDevice9* d3dDevice; IDirect3DVertexBuffer9* d3dVertexBuffer; IDirect3DTexture9* d3dTexture; }; //Creates the singleton object that handles Direct3D DXGraphics dx3d; //Message Handler for windows LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam) { switch(uMessage) { case WM_DESTROY: bRun=false; break; case WM_LBUTTONDOWN: Alert("Left mouse button pressed. Goodbye!"); bRun=false; break; /* case WM_PAINT: dx3d.Render(); ValidateRect( hWnd, NULL ); break; */ default: break; } return DefWindowProc(hWnd,uMessage,wParam,lParam); } //I made a function to create a window because I like having everything for this in one function. int MakeWindow(HINSTANCE hInstance) { WNDCLASSEX wc; wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WindowProcedure; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = NULL; wc.hCursor = NULL; wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = "DXTest"; wc.hIconSm = NULL; if(!RegisterClassEx(&wc)) return false; window=CreateWindowEx(NULL,"DXTest",APP_NAME,WS_CAPTION | WS_VISIBLE,0,0,SCREEN_WIDTH,SCREEN_HEIGHT,NULL,NULL,hInstance,NULL); if(!window) return false; return true; } //Main windows function. Message loop, initilizes Direct X and renders the scene. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCommandLine, int nCommandShow) { MSG msg; hInst=hInstance; MakeWindow(hInst); if(FAILED(dx3d.createD3D())) return 0; if(FAILED(dx3d.createDevice())) return 0; if(FAILED(dx3d.createVertexBuffer())) return 0; if(FAILED(dx3d.loadTexture("tex.tga"))) return 0; while (bRun) { //Exactly what is the difference between PeekMessage and GetMessage? if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } //The vertex buffer is filled each frame because I used to have something that moved the vertexes one pixel each frame, and needed to refresh the buffer. dx3d.fillVertexBuffer(); //Last step, render the scene with the singleton's functions. dx3d.Render(); } return 0; }
  12. Is there any way to do it using RHW? That just uses matrixes to orient the camera into a 2D view which isn't really what I was looking for. [Edited by - theJ89 on September 16, 2006 11:21:59 PM]
  13. I'm using Visual C++ 2003 and the DirectX 9 SDK to create a simple windows program that renders a quad in 2D. So far I've completed Tutorials 1 and 2 on MSDN for DirectX 9. Here is the code I have come up with so far: Edit: Sorry, new to the forums, didn't know about the "source" tag. //theJ89's Direct X Test and window creation program #include &lt;windows.h&gt; //Includes windows, #include &lt;d3d9.h&gt; //D3D, #include &lt;dxerr9.h&gt; //and the D3D error handler? //Removes rarely used things in windows. #define WIN32_LEAN_AND_MEAN //Describes the format of the vertex... //Even though I make my own custom vertex structure I think it has to conform to these specifications. #define POINT_FLAGS (D3DFVF_XYZRHW | D3DFVF_DIFFUSE) //Width and height of the menu along with the name of my program. #define APP_NAME "theJ89's DirectX Test Program" #define SCREEN_WIDTH 1024 #define SCREEN_HEIGHT 768 //Window and instance pointers HWND window; HINSTANCE hInst; //Program stops running when bRun is set to false bool bRun=true; //Alert displays a message box with the name of the application, an "OK" button, an exclamation mark and the intended message. void Alert(LPCTSTR lpMessage) { if(window!=NULL){ MessageBox(window,lpMessage,APP_NAME,MB_OK | MB_ICONEXCLAMATION); } else { MessageBox(NULL,lpMessage,APP_NAME,MB_OK | MB_ICONEXCLAMATION); } } //Confirm is like alert, but instead it has a question icon, yes/no buttons, and it returns the user's choice - true for yes and false for no. bool Confirm(LPCTSTR lpMessage) { int returnedValue=0; if(window!=NULL){ returnedValue=MessageBox(window,lpMessage,APP_NAME,MB_YESNO | MB_ICONQUESTION); } else { returnedValue=MessageBox(NULL,lpMessage,APP_NAME,MB_YESNO | MB_ICONQUESTION); } if(returnedValue==IDYES){ return true; } else { return false; } } //This is my vertex format, according to the second DX3D tutorial. It's got X, Y, and Z along with a reciprocol homogeneous w component and the color. struct Vertex2D { float x,y,z,rhw; D3DCOLOR color; }; //This is my array of vertices, arranged like so: /* 1----2 | / | | / | 0----3 */ Vertex2D vertices[] = { {0.0f, 100.0f, 1.0f, 1.0f, 0xffffffff}, {0.0f, 0.0f, 1.0f, 1.0f, 0xffffffff}, {100.0f, 0.0f, 1.0f, 1.0f, 0xffffffff}, {100.0f, 100.0f, 1.0f, 1.0f, 0xffffffff} }; //DXGraphics is my singleton class to handle the Direct 3D interface, the device, the vertex buffer, rendering, and manage creation and cleanup. //Currently I have the Render function set to draw a triangle fan that forms a rect as you can tell by the vertices. class DXGraphics { public: //Constructor, makes sure all pointers are initilized to NULL DXGraphics() { d3d=NULL; d3dDevice=NULL; d3dVertexBuffer=NULL; } //Destructor, releases the vertex buffers, device, and d3d interface ~DXGraphics() { if(d3dVertexBuffer!=NULL) d3dVertexBuffer-&gt;Release(); if(d3dDevice!=NULL) d3dDevice-&gt;Release(); if(d3d!=NULL) d3d-&gt;Release(); } //Initilizes the interface and allows me to create the device... HRESULT createD3D() { if(NULL==(d3d=Direct3DCreate9(D3D_SDK_VERSION))) { Alert("Could not create Direct3D object."); return E_FAIL; } Alert("Successfully created Direct3D object!"); return S_OK; } //Creates the device used to handle... um, pretty much everything. HRESULT createDevice() { D3DPRESENT_PARAMETERS d3dPresent; ZeroMemory(&d3dPresent,sizeof(d3dPresent)); d3dPresent.Windowed=TRUE; d3dPresent.SwapEffect=D3DSWAPEFFECT_DISCARD; d3dPresent.BackBufferFormat=D3DFMT_UNKNOWN; if( FAILED( d3d-&gt;CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dPresent, &d3dDevice))) { Alert("Could not create device!"); return S_OK; } Alert("Created device successfully!"); return E_FAIL; } //Creates a vertex buffer for my polygons. HRESULT createVertexBuffer() { if( FAILED( d3dDevice-&gt;CreateVertexBuffer(4*sizeof(Vertex2D),0, POINT_FLAGS, D3DPOOL_DEFAULT, &d3dVertexBuffer, NULL ) ) ) { Alert("Could not create vertex buffer!"); return E_FAIL; } Alert("Created vertex buffer!"); return S_OK; } //Copies the vertexes from the array in physical memory to the buffer on video memory, if I understood that correctly. HRESULT fillVertexBuffer() { VOID* pVertices; if(FAILED(d3dVertexBuffer-&gt;Lock(0,sizeof(vertices),(void**)&pVertices,0))) { Alert("Attempting to fill the vertex buffer has failed!"); return E_FAIL; } memcpy(pVertices,vertices,sizeof(vertices)); d3dVertexBuffer-&gt;Unlock(); //Alert("The vertex buffer has been filled!"); return S_OK; } //Clears the back buffer to black, starts drawing the scene, sets the stream to the buffer, sets the vertex format (I don't think it should be here but whatever works), and lastly draws the primative - a triangle fan comprised of the four vertices. From there it just ends the scene and displays it. void Render() { if(d3dDevice!=NULL) { d3dDevice-&gt;Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0),1.0f,0); if(SUCCEEDED(d3dDevice-&gt;BeginScene())) { d3dDevice-&gt;SetStreamSource(0,d3dVertexBuffer,0,sizeof(Vertex2D)); d3dDevice-&gt;SetFVF(POINT_FLAGS); d3dDevice-&gt;DrawPrimitive(D3DPT_TRIANGLEFAN,0,2); d3dDevice-&gt;EndScene(); } d3dDevice-&gt;Present(NULL,NULL,NULL,NULL); } } private: IDirect3D9* d3d; IDirect3DDevice9* d3dDevice; IDirect3DVertexBuffer9* d3dVertexBuffer; }; //Creates the singleton object that handles Direct3D DXGraphics dx3d; //Message Handler for windows LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam) { switch(uMessage) { case WM_DESTROY: bRun=false; break; case WM_LBUTTONDOWN: Alert("Left mouse button pressed. Goodbye!"); bRun=false; break; /* case WM_PAINT: dx3d.Render(); ValidateRect( hWnd, NULL ); break; */ default: break; } return DefWindowProc(hWnd,uMessage,wParam,lParam); } //I made a function to create a window because I like having everything for this in one function. int MakeWindow(HINSTANCE hInstance) { WNDCLASSEX wc; wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WindowProcedure; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = NULL; wc.hCursor = NULL; wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = "DXTest"; wc.hIconSm = NULL; if(!RegisterClassEx(&wc)) return false; window=CreateWindowEx(NULL,"DXTest",APP_NAME,WS_CAPTION | WS_VISIBLE,0,0,SCREEN_WIDTH,SCREEN_HEIGHT,NULL,NULL,hInstance,NULL); if(!window) return false; return true; } //Main windows function. Message loop, initilizes Direct X and renders the scene. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCommandLine, int nCommandShow) { MSG msg; hInst=hInstance; MakeWindow(hInst); dx3d.createD3D(); dx3d.createDevice(); dx3d.createVertexBuffer(); while (bRun) { //Exactly what is the difference between PeekMessage and GetMessage? if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } //The vertex buffer is filled each frame because I used to have something that moved the vertexes one pixel each frame, and needed to refresh the buffer. dx3d.fillVertexBuffer(); //Last step, render the scene with the singleton's functions. dx3d.Render(); } return 0; } Now what I want to do is texture these quads. I have a 32x32 .tga that I want to use as a texture for the quad. However so far I can't find a tutorial for texturing quads using the XYZRHW vertex format... so, can somebody help me out here? [Edited by - theJ89 on September 16, 2006 9:32:24 PM]
  14. Quote:Original post by Sria Good read, I would never have guessed that it culminated with you needing to make a 3d cube with textures though ;) Heh. The whole reason I'm trying to get into writing real programs and learning Direct X is because HTML is just far too slow - not to mention that I have no sure way of knowing if memory is properly garbage collected. If you've read my first post you can figure out I'm really good at scripting. I don't know if it was a mistake or not to focus entirely on scripting. On one hand it taught me a lot about the programatic way things are done and gave me a feel for the syntax of the programming languages that they're derived from (one of the things I noticed when I started learning C++ was that the syntax was [u]VERY[/u] similar to javascript). Although when I started programming it was really shocking to see how programs differed from scripts. I expected to specify data types for variables and load the necessary modules I needed for my program but then I realized I don't know the libraries or purposes of them. I figured learning C++ would be a good move because it was a popular language with a lot of history, and several games I can think of use C++. If I ever want to mod for the Source Engine, or create a server plugin for source I'll need to know C++, so it just seemed like a good move. I'm aware that I could also use OpenGL, and at some point I might learn to use the API, but I have just heard more about DirectX so I figured it would be a good place to start. I'm kind of at ends though, this is so different from what I've done in the past - I can't just create an image object and position it on the screen per-se. I like the flexibility this gives me but for starting out it's really difficult to understand. Coupled with a lack of experience in C++ and the Windows SDK (although from what I've read Windows doesn't play anywhere near as big as a role as DirectX does) this is really tough to get my head around. Thank you for the links, I'll be checking those out now and I'll post any questions that I might have here. Edit: Okay, here's my first question. I'm following the Direct3D initilization step at this URL: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/Step_2___Initializing_Direct3D.asp And I have come across this piece of code: D3DPRESENT_PARAMETERS d3dpp; ZeroMemory( &d3dpp, sizeof(d3dpp) ); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; Just out of curiosity, why is it that the memory has to be zeroed for the parameters? I've seen this in the other two samples I have been following so I'm assuming it's the normal routine. If I had to take a guess at this, does zeroing the memory ensure that all of the values inside of the d3dpp structure are equal to NULL by default? [Edited by - theJ89 on September 4, 2006 11:29:06 PM]
  15. Hello, before I begin I'd like to give you a little bit of background on myself. I am not new to the game scene. Ever since I was 6 I've been playing games for the consoles - mostly RPGs such as Chrono Trigger, Secret of Mana, and Final Fantasy 2/3 (the US versions) for the SNES. I also played Legend of Zelda: A Link to the Past which personally I couldn't get enough of. This started my interest in videogames and to this day has not changed. When I was 8 we bought our first computer (an old gateway with a 4gb harddrive and 64mb of memory). It was around this time that I began to get into PC games. The first professional game I played for the PC was Command and Conquer, one of the best strategy games of all time. After Command and Conquer, an offshoot series was released called Command and Conquer: Red Alert. It was in this game that I got a chance to play online and things were never the same - an entire world of possibilities had been laid out before me! At the time the idea of being able to play games online, which before I had only played by myself was an awesome thought. Real people to play with or against. I made friends with people I played with online and as I played online I started learning the game terminology that I would come to swear by. Eventually, I got my hands on a third party map editor for Red Alert called C&C-RAED. I learned to create maps for Red Alert, host them on online games or play them singleplayer. I learned to mod the game through configuration files, tutorials on the net, other users and examples of modified maps. I created an entire Before that I explored Microsoft Word and found the Visual Basic editor that was included with it, and got a feel for designing UI, placing forms, buttons, tabs and the like and scripting in VBScript(although I have not scripted with VBScript for years, and my knowledge of how to do this has faded from disuse). I thought that it was really cool that I could figure out how to use Word to do this. At the time I didn't even know I was scripting but I knew that it was something that I liked to do and I was good at. Around this same time my sister gave me a Trial version of software called Hyperstudio, which I came to learn is a type of presentation software for schools. But as I looked around the sample projects in Hyperstudio, I noticed that there were some things that certain projects could do that I couldn't figure out. Then by going into edit and looking around, I found that they were using a scripting language called HyperScript. I started to write down some of the commands I could understand and then imitated what they had done in their projects in my own scripts - and I did. I learned how to move objects dynamically, make the script wait, take advantage of the system 'beep' sound, animate, display dialogs and more. I created one of my first games ever, a simple puzzle game that involved you having to drag and drop objects in the right places (this functionality was built into the software, I didn't script it). I used what I had learned from scripting to move, hide, or show things through scripting. There were other alternatives but I liked scripting because I had more control than what the UI of the program offered. Then, one of my friends introduced me to a game that I thought I would not like but ended up being a huge thing for me: Starcraft, Blizzard's futuristic RTS. This game was a huge deal for me. I started playing online before I even beat any of the single-player campaigns and what I found on Battle.net blew my mind! Hundreds upon thousands of user created maps! Huge masses of players, clans, several different gamemodes that differed from the campaigns that Blizzard had created for Starcraft. I played the game daily for hours on end, and it introduced me to one of my best friends. I was really stunned by the quality of some of these maps. Intricate RPGs on a realm-sized map, intense defense maps, competetive zone control, and free-form RP maps. I found the Starcraft Map editor and started to create simple maps, place units, and design terrain and forts. I found I could modify the names, attack and damage of the units in the unit editor. Even better, for the first time ever, I could edit scripts without scripting knowledge! Enter the trigger editor. I could issue commands without knowing a scripting language. There was a list where I could add commands, specify what events triggered the trigger, and add conditions to specify when this should happen. I got a feel for the nature of programming by working with triggers in mapping. I created over 50 maps (mostly based on spur-of-the-moment ideas) for starcraft that I can remember. I became an avid roleplayer when playing starcraft online and we composed epic adventures. I created three good maps for starcraft. One of them was an action map called Ghost Mansion 7 which was a team based escape map. The other was an epic roleplaying map called Realm of Dunescape, which at one time was one of the most popular maps on Battle.net, and a heavily modified version of that map called Realm of Mystica. While I was playing starcraft I was also getting into javascript, which I think all of you around here probably know is a popular scripting language used in the design of web pages. It was a steep learning curve but it was lessened by the fact that almost all scripts written for it are readable (some of them are encoded). I quickly learned from scripts I found around the internet, along with many available code samples from around the net and the many tutorials that existed on the net. I learned the basic routines from javascript - Arithmatic, for loops, setting and declaring variables, and so on. javascript also introduced me to Object Orientated Programming, which confused me at first but then I came to love. With the advent of DHTML, I could now fully manipulate all of the effects I could find in CSS with javascript. I found a code sample on the net that showed me how to change the position of an object on the screen. So, I used my HTML editor (Frontpage Express - it was a free version of Frontpage that Microsoft no longer supports) a blank page with a black background, created a .jpg in paint and created a script object that moved it to the very utmost top of the screen. I can still remember it: imageObject.style.position="absolute"; imageObject.style.pixelLeft=0; imageObject.style.pixelTop=0; Using this knowledge along with my mapping and scripting experience and understanding of HTML I created a simple puzzle game I call "Twisted" (It's still hosted on my free site at http://www.angelfire.com/tv/jeffhut/ but the host has placed ads all over the place. Keep in mind I was only 10 when I made it, and my skills have improved). I was very much into playing Runescape (and I know how much people hate it but I thought it was a good game before they added the paid members accounts) so I created a game based off of what I saw in Runescape - Dunescape. Dunescape's name is a clear ripoff of Runescape obviously, but that's besides the point. Dunescape was my first ever major game project - I scripted it entirely, planned for it, drew maps, tables of items, their damages, defense ratings, planned math ahead, thought of how I would design the various systems and spent hours of my own time working in Frontpage Express and it's script editor designing the various systems. In addition to that I had to make my own art because I was no good at myself. I didn't have a gif animatior so I also did the animation myself. It was very poorly scripted because even then I was only a moderately experienced scripter and had never looked at any real reference, except for the W3C DOM. However I designed collision, tile triggers, map transitions, basic combat, a character settings manager, and even fooled with cookies to have it remember the player's stats. I made basic AI that made agressive enemies try to follow and then attack you. I bought Warcraft 3 and stopped playing Starcraft. I was involved in mapping for a while with it but ultimately it just was not what I had seen in Starcraft. However during the time that I did play starcraft, I created a nearly complete trigger guide which can be found here: http://www.wc3campaigns.net/showthread.php?t=17723 Tired with Warcraft 3 and nostalgic for the times where I worked on Dunescape, I started up on the Second version of it. I learned how to use 3DS Max to create models and then render them, and I acquired a better editor for graphics called Paint Shop Pro. My skills involving computer graphics as a whole improved and I learned a lot during this period. I also learned to use a little bit of PHP, enough to create a server-side player manager and, through an inefficent refresh-and-check for changes method I suddenly found a way to make Dunescape multiplayer. One page refreshed the content from the server, which fed it into the script that managed incoming data. It compared it with existing data and made changes accordingly. It sent data out by simply changing the request portion of the refresh page. It was a pretty hacky solution but it worked. Ultimately, however, I gave up on the project. It was too laggy, too unstable, and I lacked the effort to continue it. It was around this time that I started hearing about people who had modded a game called Half-Life - I had seldom heard about the game before, so I picked it up. It was really a thrilling game, even though it was created in 1996 and it was now 2001. Despite that, I scrutinized the game while I was playing it - observing the way the textures were mapped onto the surfaces of the polygons, observing back-face culling (although at the time I didn't know that was what it was) in action, Watching how the distinct lines of the polygons shifted while I moved, the acceleration and deceleration of the player as he moved, the actions of the alpha channels, the custom lighting, the NPCs, everything. It was a work of art that I was looking at. And then 2003 rolled around and Half-Life 2 was released - and I got a new computer - absolutely STUNNING! It blew away my former perceptions of what was possible in a computer game and motivated me to work on a third version of Dunescape. Still in HTML and javascript however the game suffered from the ineffecient structure of internet explorer. I finally realized, as I went along, that Internet Explorer was not the proper environment to be developing games in and it never was. Distraught over this appalling failure I wandered into the Garry's Mod community (http://forums.facepunchstudios.com/) and started to map for it, around version 7. I released one good map and several prefabs but I was not heavily involved in the community until Garry's Mod 9, the current release. Garry's Mod 9 added an instance of Lua to the source engine code, and Garry bound commands in the source engine to Lua. I quickly caught onto this and created the first Roleplay Mod for Garry's Mod. It was a hit until Underseeg released his. But, by creating this I was introduced to Lua. I found it to be a very simple language, and based on what I had seen in other languages. But, now that I've told you about what I've done and where I am now, I'll get to the real subject of my post... I am fairly new to the C++ language, although I feel I have a good grasp of it and have been able to make several successful console applications in the past. I do not have any experience with the Windows SDK or Direct X SDK. What I'm trying to accomplish is something pretty simple. I want to create a Windows Application by using C++ that initilizes Direct X fullscreen, loads a texture, and draws a quad to the screen. I've been following these two tutorials: http://www.flipcode.com/articles/article_guidedx82d.shtml http://www.gamedev.net/reference/articles/article1972.asp However I noticed that when I looked at the source files they accomplished a 2D perspective in different ways. Could somebody help me out here?