I'll move on to DirectX11 instead. Exciting
- Viewing Profile: Posts: falcon93
Community Stats
- Group Members
- Active Posts 124
- Profile Views 2,031
- Member Title Member
- Age Age Unknown
- Birthday Birthday Unknown
-
Gender
Male
-
Location
Sweden
-
Interests
Programming (C# & C++)
Graphics
Posts I've Made
In Topic: Draw a Textured Quad
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
I'll move on to DirectX11 instead. Exciting
In Topic: Draw a Textured Quad
25 September 2012 - 11:19 AM
Thanks very much for your help ATC 
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
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
In Topic: Draw a Textured Quad
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?
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?
In Topic: Draw a Textured Quad
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:

But instead this is showing up:

Current code below (error checking coming soon):
It's supposed to be a small cloud:

But instead this is showing up:

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);
}
In Topic: Draw a Textured Quad
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
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);
}
- Home
- » Viewing Profile: Posts: falcon93

Find content