Archived

This topic is now archived and is closed to further replies.

Rydis

any real point to vertex(vertices)

Recommended Posts

is there really any point do make a matrix that draws polygons with your hand made vertices when you have bitmaps to do all the graphics for you. im reading this book and they gone on and on about vertices and showing some really stupid examples i dont get and just leaving you with matrixes of about 50 diff numberes that when renderd dont show anything...really whats the point of em.

Share this post


Link to post
Share on other sites
I''m going to assume you''re trying to learn 2D graphics, and you''re reading a book that teaches DirectX 8.0.

DirectX 8.0 is much different in the way you have probably programmed before. You want the simplicity of blitting to the screen. This isn''t the case in DX 8.0, DirectDraw was discontinued, so you have to use Direct3D for graphics. In DX 8.0, you have to draw polygons in 3D space, which are made of verticies. Then you can put your bitmaps on the polygons. Matricies are there to move objects around, but that''s such a poor explaination of their full capabilities, so I''ll just let someone else explain them.

Share this post


Link to post
Share on other sites
Heh, you''re reading the same book as I am. I suggest printing out the source code from the CD. Preferably the Draw3D demo in chapter 6.
Look through the source code as you read through the book to follow along and understand what he is talking about more clearly. The more you interact with code, the more you''ll understand. Check the SDK Documentation too if you don''t completely understand what a function does.
Also, there are some things in the source code that are not mentioned in the book, and it could screw you over big time. One thing the author forgot to mention was to set the render state to D3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE) right after you create your vertex buffer. I was confused for days when it wouldn''t draw anything.

Other than that, just remember that all your drawing is in 3D space. Verticies are the corners to the polygons, and you need to use them to define a polygon. It''s a little harder than working in 2D space.

Share this post


Link to post
Share on other sites
y know what functions do ;P mind you. just i dont get vertex stuff all together really...cant figure out how to combine them at certain points in a space..i got the code and just played around mesing with the vertex in the sVertex matrix object he created and i couldn''t get anything to be drawn besides what he already had.

Share this post


Link to post
Share on other sites
quote:
Original post by FlamePixel
If you want to do 2D without messing with vertices, use ID3DXSprite. You simply load a texture and call the Draw method of the interface. and voila!


No No No NOOOOO Not ID3DXSprite!!!

.lick

Share this post


Link to post
Share on other sites
ddin''t feel like creating a new topic can anyone tell me why this comes up all black


#include <windows.h>
#include <stdio.h>
#include <d3d8.h>
#include <d3dx8.h>

//Global

char *g_WindowClass = "Game";
char *g_WindowName = "Game";
HWND g_hWnd;

//graphic-based globels

IDirect3D8 *g_d3d; //globel for device checking and setting

IDirect3DDevice8 *g_d3dd; //device for the vertex drawing


//vertex matrix

struct sVertex
{
int PosX, PosY, PosZ, RHW; //x, y, z cordinates

D3DCOLOR Diffuse; //diffuse color of pixel

float TextureU, TextureV; //texture mappin cordinates

};

//FVF Format

#define VertexFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)

// Vertex buffer

IDirect3DVertexBuffer8 *g_d3dvb;

// Texture

IDirect3DTexture8 *g_d3dt;

//Main Prototypes

HWND CreateNewWindow(HINSTANCE, char *, char *, int, int);
bool RegisterWindow(HINSTANCE, char *);
bool UnRegisterWindow(HINSTANCE, char *);
bool Init();
bool PreFrame();
bool PerFrame();
bool PostFrame();

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
MSG msg;

//Regeister New Window

RegisterWindow(hInst, g_WindowClass);

CreateNewWindow(hInst, g_WindowClass, g_WindowName, 800, 600);

if(Init() == false)
MessageBox(g_hWnd, "test", "test", MB_OK);

if(PerFrame() == false)
MessageBox(g_hWnd, "test", "test", MB_OK);

while(msg.message != WM_QUIT)
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}

UnRegisterWindow(hInst, g_WindowClass);

return msg.wParam;
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
switch (iMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
}

return DefWindowProc (hwnd, iMsg, wParam, lParam);
}

//Create a New Widnow

HWND CreateNewWindow(HINSTANCE hInst,char *WindowClass, char *WindowClassName, int WindowWidth, int WindowHeight)
{
HWND hWnd;

hWnd = CreateWindow (WindowClass, WindowClassName, WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,
CW_USEDEFAULT, WindowWidth, WindowHeight, NULL, NULL, hInst, NULL);

ShowWindow(hWnd, SW_NORMAL);
UpdateWindow(hWnd);

g_hWnd = hWnd;

return hWnd;
}

//Register New Window

bool RegisterWindow(HINSTANCE hInst, char *WindowClass)
{
WNDCLASSEX wndclass;

wndclass.cbSize = sizeof (wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInst;
wndclass.hIcon = LoadIcon (NULL, IDI_WINLOGO);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);

wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = WindowClass;
wndclass.hIconSm = LoadIcon (NULL, IDI_WINLOGO);
RegisterClassEx (&wndclass);

return true;
}

//UnRegesterWindow

bool UnRegisterWindow(HINSTANCE hInst, char *WindowClass)
{
UnregisterClass(WindowClass,hInst);

return true;
}

bool Init()
{
D3DPRESENT_PARAMETERS d3dpp; //display parameters

D3DDISPLAYMODE d3ddm; //display mode

byte *VertexPtr; //vertex pointer

sVertex Verts[4] =
{
{10, 10, 1, 1, D3DCOLOR_RGBA(15, 0, 210, 255) },
{20, 10, 1, 1, D3DCOLOR_RGBA(15, 0, 210, 255)},
{10, 20, 1, 1, D3DCOLOR_RGBA(15, 0, 210, 255)},
{20, 20, 1, 1, D3DCOLOR_RGBA(15, 0, 210, 255)}
};

//window intinalization

//creates a object taht allows creation of other objects

if((g_d3d = Direct3DCreate8(D3D_SDK_VERSION)) == NULL)
return false;

//gets Display Mode

if(FAILED(g_d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))
return false;

//clears the present parameters

ZeroMemory(&d3dpp, sizeof(d3dpp));

//set the present parameters

d3dpp.Windowed = true; //tellss compiler its windowed

d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; //what do so with enpty buffer

d3dpp.BackBufferFormat = d3ddm.Format; //format of backbuffer

d3dpp.EnableAutoDepthStencil = false;

//create display Device

if(FAILED(g_d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_d3dd)))
return false;

// Create the vertex buffer and set data

g_d3dd->CreateVertexBuffer(sizeof(sVertex)*4, 0,
VertexFVF, D3DPOOL_DEFAULT, &g_d3dvb);

g_d3dvb->Lock(0,0, (BYTE**)&VertexPtr, 0); //locks vertex ptr

memcpy(VertexPtr, Verts, sizeof(Verts)); //copys it

g_d3dvb->Unlock(); //then releases


// Load the texture map

D3DXCreateTextureFromFile(g_d3dd, "Texture.bmp", &g_d3dt);

return true;
}

bool PerFrame()
{
// Clear device backbuffer

g_d3dd->Clear(0, NULL, D3DCLEAR_TARGET,
D3DCOLOR_RGBA(255,255,150,255), 1.0f, 0);

// Begin scene

if(SUCCEEDED(g_d3dd->BeginScene()))
{

// Set the vertex stream, shader, and texture

g_d3dd->SetStreamSource(0, g_d3dvb, sizeof(sVertex));
g_d3dd->SetVertexShader(VertexFVF);
g_d3dd->SetTexture(0, g_d3dt);

// Draw the vertex buffer

g_d3dd->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

// Release texture

g_d3dd->SetTexture(0, NULL);

// End the scene

g_d3dd->EndScene();
}

// Display the scene

g_d3dd->Present(NULL, NULL, NULL, NULL);

return true;
}


yes the texture name is right if anyone tries to ask

Share this post


Link to post
Share on other sites
Ah missed this one (and still sometimes do) you didn''t turn off lighting. D3D defaults with lighting on, so if you want to render colored primitives (triangles) set these in your source:

g_d3dd->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
g_d3dd->SetRenderState(D3DRS_LIGHTING, FALSE);

You should see something now, I made the same mistake when I started out.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Make sure you memeset() all your structures. The first time I made a light in D3D8, I didn''t memset my light =\ As a result, all my meshes were yellow-ish. Try running your program in release build, as VC++ (I assume) doesn''t fill uninitialized memory with those odd values. If it works, it''s the memset() problem.

Share this post


Link to post
Share on other sites
i dont know how to do that...anyone try to copy code into their compiler and do it?

besides im not using lights...thery supposed to be disabled fromthem func calls

[edited by - Rydis on July 27, 2003 2:38:07 AM]

Share this post


Link to post
Share on other sites