Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Draw a Textured Quad


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 falcon93   Members   -  Reputation: 121

Like
0Likes
Like

Posted 22 September 2012 - 07:49 AM

Hello everyone!

I'm trying to draw a textured quad made from 4 vertices using DirectX9. I've followed some tutorials but it simply wont work. I've pasted the code below and I would appreciate it very much if someone could look through it and help me.

I know that the code should be splitted up into methods and classes, but before i do that I want to keep it as simple as possible and be able to see and learn the entire process.

What i want this code to do is to simply draw my quad with a texture on it. Could anyone please help me?

My current code (I've also attached the project):

#include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>

#define FULLSCREEN   FALSE
#define SCREEN_WIDTH  1280
#define SCREEN_HEIGHT 800

#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9.lib")

const DWORD D3DFVF_TLVERTEX = D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1;

struct TLVERTEX { float x, y, z; float rhw; D3DCOLOR color; float u, v; };

LPDIRECT3D9	d3d;
LPDIRECT3DDEVICE9  d3ddev;
LPDIRECT3DVERTEXBUFFER9 vertexBuffer;
D3DPRESENT_PARAMETERS d3dpp;
LPDIRECT3DTEXTURE9  d3dTexture;
TLVERTEX*	vertices;

LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
HRESULT WINAPI D3DXCreateTextureFromFile(LPDIRECT3DDEVICE9 pDevice, LPCTSTR pSrcFile, LPDIRECT3DTEXTURE9 *ppTexture);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	HWND	hWnd;
	WNDCLASSEX wc;
MSG	 msg;
	ZeroMemory(&wc, sizeof(WNDCLASSEX));
	wc.cbSize   = sizeof(WNDCLASSEX);
	wc.style   = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc  = WindowProc;
	wc.hInstance  = hInstance;
	wc.hCursor   = LoadCursor(NULL, IDC_ARROW);
	wc.lpszClassName = L"WindowClass";
	RegisterClassEx(&wc);
if (FULLSCREEN)
{
  hWnd = CreateWindowEx(NULL, L"WindowClass", L"Window 1", WS_EX_TOPMOST | WS_POPUP, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL);
}
else
{
  hWnd = CreateWindowEx(NULL, L"WindowClass", L"Window 1", WS_OVERLAPPEDWINDOW, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL);
}
	ShowWindow(hWnd, nCmdShow);
d3d = Direct3DCreate9(D3D_SDK_VERSION);
	ZeroMemory(&d3dpp, sizeof(d3dpp));
	d3dpp.Windowed	 = !FULLSCREEN;
	d3dpp.SwapEffect	= D3DSWAPEFFECT_DISCARD;
	d3dpp.hDeviceWindow	= hWnd;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
	d3dpp.BackBufferWidth  = SCREEN_WIDTH;
	d3dpp.BackBufferHeight = SCREEN_HEIGHT;
	d3d -> CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);
d3ddev -> CreateVertexBuffer(sizeof(TLVERTEX) * 4, NULL, D3DFVF_TLVERTEX, D3DPOOL_MANAGED, &vertexBuffer, NULL);
vertexBuffer->Lock(0, 0, (void**)&vertices, NULL);
vertices[0].x   = 0.0F;
vertices[0].y   = 0.0F;
vertices[0].z   = 0.0F;
vertices[0].u   = 0.0F;
vertices[0].v   = 0.0F;
vertices[0].rhw   = 1.0F;
vertices[0].color = D3DCOLOR_ARGB(255, 255, 255, 255);
vertices[0].x   = 64.0F;
vertices[0].y   = 0.0F;
vertices[0].z   = 0.0F;
vertices[0].u   = 1.0F;
vertices[0].v   = 0.0F;
vertices[0].rhw   = 1.0F;
vertices[0].color = D3DCOLOR_ARGB(255, 255, 255, 255);
vertices[0].x   = 0.0F;
vertices[0].y   = 64.0F;
vertices[0].z   = 0.0F;
vertices[0].u   = 0.0F;
vertices[0].v   = 1.0F;
vertices[0].rhw   = 1.0F;
vertices[0].color = D3DCOLOR_ARGB(255, 255, 255, 255);
vertices[0].x   = 64.0F;
vertices[0].y   = 64.0F;
vertices[0].z   = 0.0F;
vertices[0].u   = 1.0F;
vertices[0].v   = 1.0F;
vertices[0].rhw   = 1.0F;
vertices[0].color = D3DCOLOR_ARGB(255, 255, 255, 255);
vertexBuffer->Unlock();
VOID* pVoid;

vertexBuffer -> Lock(0, 0, (void**)&pVoid, 0);
memcpy(pVoid, vertices, sizeof(vertices));
vertexBuffer -> Unlock();
D3DXCreateTextureFromFile(d3ddev, L"ParticleSmokeCloud64x64.png", &d3dTexture);
	while (TRUE)
	{
		while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage (&msg);
		}
		if (msg.message == WM_QUIT) break;
  d3ddev -> Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255, 255, 255), 1.0f, 0);
  d3ddev -> BeginScene();
  d3ddev -> SetRenderState(D3DRS_LIGHTING, FALSE);
  d3ddev -> SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
  d3ddev -> SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
  d3ddev -> SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
  d3ddev -> SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
  d3ddev -> SetTexture (0, d3dTexture);
  d3ddev -> SetVertexShader(NULL);
  d3ddev -> SetFVF(D3DFVF_TLVERTEX);
  d3ddev -> SetStreamSource(0, vertexBuffer, 0, sizeof(TLVERTEX));
  d3ddev -> DrawPrimitive (D3DPT_TRIANGLEFAN, 0, 2);
  d3ddev -> EndScene();
  d3ddev -> Present(NULL, NULL, NULL, NULL);
	}
	d3ddev -> Release();
	d3d	-> Release();
	return msg.wParam;
}

LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
		case WM_DESTROY: PostQuitMessage(0); return 0; break;
	}
	return DefWindowProc(hWnd, message, wParam, lParam);
}

Attached Files


Edited by falcon93, 22 September 2012 - 07:51 AM.


Sponsor:

#2 Kaptein   Prime Members   -  Reputation: 2180

Like
0Likes
Like

Posted 22 September 2012 - 05:03 PM

i don't know directx, but i dont see any viewport setting, so z = 0.0 might be invalid
have you checked for errors? in opengl you have a command called glGetError() which you can use to check the validity of your calls

second, do you even have a valid directx context opened? i see you opening the window in software mode
then you start making a vertex buffer, the texture and finally you render it all

i think i would guess that you don't have a valid viewport
a viewport is defined as a region of your window that you draw on

second, you'll need to initialize how you wish to render 3D (it's defined as a 4x4 matrix)
the typical frustums are ortographic (2D-ish), and perspective frustum (3D-ish) Posted Image
so, maybe you'll need to check out a tutorial on the various ways you can represent 3d!

if, however directx has a default viewport and frustum, perhaps z = 0.0 is the problem

Edited by Kaptein, 22 September 2012 - 05:06 PM.


#3 falcon93   Members   -  Reputation: 121

Like
0Likes
Like

Posted 22 September 2012 - 05:34 PM

I've tried to rewrite everything, so now it atleast appears a quad. However, the quad isn't textured but instead some sort of a gradient with black and red.

I guess that I don't have to set up any veiwport, otherways the quad itself wouldn't appear, right? Any other ideas? I've pasted the new code below

#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>
#include <d3dx9.h>

#define FULLSCREEN   FALSE
#define SCREEN_WIDTH  1280
#define SCREEN_HEIGHT 800

#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9.lib")

#define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1)

LPDIRECT3D9    d3d;
LPDIRECT3DDEVICE9  d3ddev;
LPDIRECT3DVERTEXBUFFER9 v_buffer;
LPDIRECT3DTEXTURE9  d3dtex;
D3DPRESENT_PARAMETERS d3dpp;

struct CUSTOMVERTEX { float X, Y, Z, RHW, U, V; DWORD COLOR; };

LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    HWND    hWnd;
    WNDCLASSEX wc;
MSG	 msg;
    ZeroMemory(&wc, sizeof(WNDCLASSEX));
    wc.cbSize   = sizeof(WNDCLASSEX);
    wc.style   = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc  = WindowProc;
    wc.hInstance  = hInstance;
    wc.hCursor   = LoadCursor(NULL, IDC_ARROW);
    wc.lpszClassName = L"WindowClass";
    RegisterClassEx(&wc);
if (FULLSCREEN)
{
  hWnd = CreateWindowEx(NULL, L"WindowClass", L"Window 1", WS_EX_TOPMOST | WS_POPUP, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL);
}
else
{
  hWnd = CreateWindowEx(NULL, L"WindowClass", L"Window 1", WS_OVERLAPPEDWINDOW, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL);
}
    ShowWindow(hWnd, nCmdShow);
d3d = Direct3DCreate9(D3D_SDK_VERSION);
    ZeroMemory(&d3dpp, sizeof(d3dpp));
    d3dpp.Windowed	 = !FULLSCREEN;
    d3dpp.SwapEffect    = D3DSWAPEFFECT_DISCARD;
    d3dpp.hDeviceWindow    = hWnd;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    d3dpp.BackBufferWidth  = SCREEN_WIDTH;
    d3dpp.BackBufferHeight = SCREEN_HEIGHT;
    d3d -> CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);
D3DXCreateTextureFromFile(d3ddev, L"ParticleSmokeCloud64x64", &d3dtex);
struct CUSTOMVERTEX vertices[] =
    {
	    { 10.0f,  10.0f,  0.0f, 1.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(0, 255, 0),   },
	    { 110.0f, 10.0f,  0.0f, 1.0f, 1.0f, 0.0f, D3DCOLOR_XRGB(0, 0, 255),   },
	    { 10.0f,  110.0f, 0.0f, 1.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0),   },
  { 110.0f, 110.0f, 0.0f, 1.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(0, 255, 255), },
    };
d3ddev -> CreateVertexBuffer(4 * sizeof(CUSTOMVERTEX), NULL, CUSTOMFVF, D3DPOOL_MANAGED, &v_buffer, NULL);
VOID* pVoid;
v_buffer -> Lock(0, 0, (void**)&pVoid, 0);
    memcpy(pVoid, vertices, sizeof(vertices));
    v_buffer -> Unlock();
    while (TRUE)
    {
	    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
	    {
		    TranslateMessage(&msg);
		    DispatchMessage (&msg);
	    }
	    if (msg.message == WM_QUIT) break;
  d3ddev -> Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255, 255, 255), 1.0f, 0);
 
  d3ddev -> BeginScene();
  d3ddev -> SetFVF(CUSTOMFVF);
 
  d3ddev -> SetTexture(0, d3dtex);
  d3ddev -> SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));
  d3ddev -> DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
  d3ddev -> EndScene();
  d3ddev -> Present(NULL, NULL, NULL, NULL);
    }
v_buffer -> Release();
    d3ddev  -> Release();
    d3d   -> Release();
    return msg.wParam;
}

LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
	    case WM_DESTROY: PostQuitMessage(0); return 0; break;
    }
    return DefWindowProc(hWnd, message, wParam, lParam);
}


#4 Waaayoff   Members   -  Reputation: 783

Like
1Likes
Like

Posted 24 September 2012 - 02:35 PM

I see that you are not doing any error checking. I realize you're a beginner but it can help a lot. Most DirectX functions return an error value if they fail. You should check for that :)

I believe you forgot the texture file extension in this line:
D3DXCreateTextureFromFile(d3ddev, L"ParticleSmokeCloud64x64", &d3dtex);
"Spending your life waiting for the messiah to come save the world is like waiting around for the straight piece to come in Tetris...even if it comes, by that time you've accumulated a mountain of shit so high that you're fucked no matter what you do. "

#5 falcon93   Members   -  Reputation: 121

Like
0Likes
Like

Posted 24 September 2012 - 04:23 PM

Thanks for your reply Waaayoff. I've added the file extension, ".png". I'll look deeper into error checking, while I do that; I've done some minor chages to the code again, and there's actually something appearing on the screen now, however, the texture just looks strange.

It's supposed to be a small cloud:
Posted Image

But instead this is showing up:
Posted Image


Current code below (error checking coming soon):

#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>
#include <d3dx9.h>

#define FULLSCREEN   FALSE
#define SCREEN_WIDTH  1280
#define SCREEN_HEIGHT 800

#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9.lib")

#define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_TEX1)

LPDIRECT3D9    d3d;
LPDIRECT3DDEVICE9  d3ddev;
LPDIRECT3DVERTEXBUFFER9 v_buffer;
LPDIRECT3DTEXTURE9  d3dtex;
D3DPRESENT_PARAMETERS d3dpp;

struct CUSTOMVERTEX { float X, Y, Z, RHW, U, V; };

LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    HWND    hWnd;
    WNDCLASSEX wc;
MSG	 msg;
    ZeroMemory(&wc, sizeof(WNDCLASSEX));
    wc.cbSize   = sizeof(WNDCLASSEX);
    wc.style   = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc  = WindowProc;
    wc.hInstance  = hInstance;
    wc.hCursor   = LoadCursor(NULL, IDC_ARROW);
    wc.lpszClassName = L"WindowClass";
    RegisterClassEx(&wc);
if (FULLSCREEN)
{
  hWnd = CreateWindowEx(NULL, L"WindowClass", L"Window 1", WS_EX_TOPMOST | WS_POPUP, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL);
}
else
{
  hWnd = CreateWindowEx(NULL, L"WindowClass", L"Window 1", WS_OVERLAPPEDWINDOW, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL);
}
    ShowWindow(hWnd, nCmdShow);
d3d = Direct3DCreate9(D3D_SDK_VERSION);
    ZeroMemory(&d3dpp, sizeof(d3dpp));
    d3dpp.Windowed	 = !FULLSCREEN;
    d3dpp.SwapEffect    = D3DSWAPEFFECT_DISCARD;
    d3dpp.hDeviceWindow    = hWnd;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    d3dpp.BackBufferWidth  = SCREEN_WIDTH;
    d3dpp.BackBufferHeight = SCREEN_HEIGHT;
    d3d -> CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);
D3DXCreateTextureFromFile(d3ddev, L"ParticleSmokeCloud64x64.png", &d3dtex);
struct CUSTOMVERTEX vertices[] =
    {
	    { 10.0f,  10.0f,  0.0f, 1.0f, 0.0f, 0.0f, },
	    { 110.0f, 10.0f,  0.0f, 1.0f, 1.0f, 0.0f, },
	    { 10.0f,  110.0f, 0.0f, 1.0f, 0.0f, 1.0f, },
  { 110.0f, 110.0f, 0.0f, 1.0f, 1.0f, 1.0f, },
    };
d3ddev -> CreateVertexBuffer(4 * sizeof(CUSTOMVERTEX), NULL, CUSTOMFVF, D3DPOOL_MANAGED, &v_buffer, NULL);
VOID* pVoid;
v_buffer -> Lock(0, 0, (void**)&pVoid, 0);
    memcpy(pVoid, vertices, sizeof(vertices));
    v_buffer -> Unlock();
    while (TRUE)
    {
	    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
	    {
		    TranslateMessage(&msg);
		    DispatchMessage (&msg);
	    }
	    if (msg.message == WM_QUIT) break;
  d3ddev -> Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255, 255, 255), 1.0f, 0);
 
  d3ddev -> BeginScene();
  d3ddev -> SetRenderState( D3DRS_LIGHTING, TRUE);
  d3ddev -> SetTexture(0, d3dtex);
  d3ddev -> SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));
  d3ddev -> SetFVF(CUSTOMFVF);
 
  d3ddev -> DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
  d3ddev -> EndScene();
  d3ddev -> Present(NULL, NULL, NULL, NULL);
    }
v_buffer -> Release();
    d3ddev  -> Release();
    d3d   -> Release();
    return msg.wParam;
}

LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
	    case WM_DESTROY: PostQuitMessage(0); return 0; break;
    }
    return DefWindowProc(hWnd, message, wParam, lParam);
}


#6 ATC   Members   -  Reputation: 551

Like
0Likes
Like

Posted 24 September 2012 - 08:09 PM

If you don't mind me asking, why are you learning DirectX9...an "ancient" DirectX API from circa 2002? Why not start learning DirectX10 and/or 11? I actually think 10 and 11 are a lot easier to work with as they don't suffer from 9's technical flaws and bugs. They also share the common DXGI layer which encapsulates and simplifies dealing with graphics hardware.

It would also help you a LOT if you separated your game/scene code from the Windows app code. In other words, write a new class called "Game" or "Scene" and let it handle the initialization of DirectX and the drawing of your 3D scene. It will make editing and debugging your code 10,000% easier because things will be logically separated and much neater. Besides, you need to learn good software engineering practices such as encapsulization and decoupling.
_______________________________________________________________________________
CEO & Lead Developer at ATCWARE™
"Project X-1"; a 100% managed, platform-agnostic game & simulation engine


Please visit our new forums and help us test them and break the ice!
___________________________________________________________________________________

#7 falcon93   Members   -  Reputation: 121

Like
0Likes
Like

Posted 25 September 2012 - 06:31 AM

Thanks for your reply ATC.

I actually wanted to learn DirectX11, but I havn't managed to find any good tutorials about textured quads. The only tutorial I found was really overkill, using shaders etc. I would really like to learn DirectX11, but could you help me to find any totorial that just picks the absolutely neccessary to draw a textured quad?

I'm already familiar with encapsulization and separating into classes as I have 5 years experience of C# and XNA. I just felt that I wanted to move on with something more advanced than XNA, and therefore decided to learn C++ and DirectX. I know that the code should be splitted into classes, but before I do that, I just want everything in one place so I can overveiw it easy. The only purpose of the current project is so I learn the simpliest basics. When I've learn these, I'll move along with a new project where I'll split the code into classes and learn more complicated things.

Could you please help me find a good tutorial with only the absolutely neccessary steps to render a textured quad in DirectX11?
Or, if you want to be very kind, would you like to spend like 10-15 minutes and write a short tutorial with the absolutely neccessary steps?

#8 ATC   Members   -  Reputation: 551

Like
1Likes
Like

Posted 25 September 2012 - 10:27 AM

Thanks for your reply ATC.

I actually wanted to learn DirectX11, but I havn't managed to find any good tutorials about textured quads. The only tutorial I found was really overkill, using shaders etc. I would really like to learn DirectX11, but could you help me to find any totorial that just picks the absolutely neccessary to draw a textured quad?


Shaders are absolutely necessary to getting anything on the screen nowadays. The days of the FFP (fixed-function pipeline) are dead. This is even true in XNA, though they provide the BasicEffect class which may have hidden that fact from you. There's certainly nothing overkill about using shaders. Shaders are simple, easy to use and very powerful. I will certainly be happy to help you write a very basic shader and understand how it works.

I'm already familiar with encapsulization and separating into classes as I have 5 years experience of C# and XNA. I just felt that I wanted to move on with something more advanced than XNA, and therefore decided to learn C++ and DirectX. I know that the code should be splitted into classes, but before I do that, I just want everything in one place so I can overveiw it easy. The only purpose of the current project is so I learn the simpliest basics. When I've learn these, I'll move along with a new project where I'll split the code into classes and learn more complicated things.


I think it's more complicated to mix a bunch of DirectX code in with Win32 code. That's a LOT of code lol. It's just a pain to read, imo. It's so easy to split it into two files/classes that I just think you're doing yourself a disservice to keep it all jumbled up. We could create you a C++ template you can use anytime you start a new project that will automatically set your code up properly if you like.

Also, if you're good with C# and have XNA experience perhaps you jumped to the wrong platform. Were you aware of SlimDX (and even SharpDX)? These are both very good C# wrappers for DirectX, and SlimDX (not sure about SharpDX) covers the entirety of DirectX 9, 10 and 11 (even 10.1 and 11.1). Basically, SlimDX is just DirectX for C#. It's almost a 1:1 wrapper, so there's really nothing you can do with native DirectX that can't be done with SlimDX. It's more than powerful enough for professional software development. I'm using it for the DirectX back-end of my engine. And if I was going to write a DirectX-based PC game I would definitely choose SlimDX.

That being said there's nothing wrong with learning native DirectX and C++. It will actually be a valuable learning experience, and there's no reason you can't learn both at the same time. Also, since they're almost exactly the same, language differences aside, knowledge from one translates to the other. So if you were to learn either one the other would make perfect sense.

Could you please help me find a good tutorial with only the absolutely neccessary steps to render a textured quad in DirectX11?
Or, if you want to be very kind, would you like to spend like 10-15 minutes and write a short tutorial with the absolutely neccessary steps?


Yes. Here is a great place to start.

But I will help you too if you need me. If you like, we can start a new C++ project and I'll show you how to draw a textured quad and explain the shader part of things so you'll see how easy and powerful it is. Hit me up with a pm. We could also do the same thing with C# and SlimDX.
_______________________________________________________________________________
CEO & Lead Developer at ATCWARE™
"Project X-1"; a 100% managed, platform-agnostic game & simulation engine


Please visit our new forums and help us test them and break the ice!
___________________________________________________________________________________

#9 falcon93   Members   -  Reputation: 121

Like
0Likes
Like

Posted 25 September 2012 - 11:19 AM

Thanks very much for your help ATC Posted Image

I've heard of different wrappers of DirectX for C#. The reason that I chose C++ and DirectX anyway, is becouse many companies in the game industry uses it. As I'm a student, having knowledge in these areas can be a very good qualification when it's time to search for a job.

I'll take a look at the link and try a little bit by my own again. However I recently tried to get it work with DirectX11, but problems accured and I guess that they will this time too. If so, I'll send you a pm so you can help me.

Thanks again so much for your help Posted Image

#10 Waaayoff   Members   -  Reputation: 783

Like
0Likes
Like

Posted 25 September 2012 - 01:33 PM

I tested your code and it works correctly. Are you sure it's not working for you?

I second learning DX11 by the way. Shaders can be daunting at first but you will have to learn them eventually :)
"Spending your life waiting for the messiah to come save the world is like waiting around for the straight piece to come in Tetris...even if it comes, by that time you've accumulated a mountain of shit so high that you're fucked no matter what you do. "

#11 falcon93   Members   -  Reputation: 121

Like
0Likes
Like

Posted 25 September 2012 - 02:02 PM

Yes, I've compiled it a couple of times and it builds successfully, the window appears and there's something drawn, but it draws realy strange (see image in previous post).

I'll move on to DirectX11 instead. Exciting Posted Image




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS