• 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.
Sign in to follow this  
Followers 0
lyzerk

Terrain texture problem

8 posts in this topic

Hello,

I have problem with terrain texture. there is my codes;

[source lang="cpp"]void gameTerrain::SetIndexBuffer(LPDIRECT3DDEVICE9 g_pd3dDevice)
{
short s_Indices[(WIDTH-1)*(HEIGHT-1)*6];


for (int x=0;x< WIDTH-1;x++) {

for (int y=0; y< HEIGHT-1;y++) {
s_Indices[(x+y*(WIDTH-1))*6+2] = x+y*WIDTH;
s_Indices[(x+y*(WIDTH-1))*6+1] = (x+1)+y*WIDTH;
s_Indices[(x+y*(WIDTH-1))*6] = (x+1)+(y+1)*WIDTH;

s_Indices[(x+y*(WIDTH-1))*6+3] = (x+1)+(y+1)*WIDTH;
s_Indices[(x+y*(WIDTH-1))*6+4] = x+y*WIDTH;
s_Indices[(x+y*(WIDTH-1))*6+5] = x+(y+1)*WIDTH;

}
}

if (FAILED(g_pd3dDevice->CreateIndexBuffer((WIDTH-1)*(HEIGHT-1)*6*sizeof(short),D3DUSAGE_WRITEONLY,D3DFMT_INDEX16,D3DPOOL_MANAGED,&Indexs,NULL)))
{
MessageBox(NULL,L"Error while creating IndexBuffer",L"FillIndices()",MB_OK);
}

VOID* p_Indices;
if (FAILED(Indexs->Lock(0, (WIDTH-1)*(HEIGHT-1)*6*sizeof(short), (void**)&p_Indices, 0)))
{
MessageBox(NULL,L"Error trying to lock",L"FillIndices()",MB_OK);
}else{
memcpy(p_Indices, s_Indices, (WIDTH-1)*(HEIGHT-1)*6*sizeof(short));
Indexs->Unlock();
}


D3DXCreateTextureFromFile(g_pd3dDevice,

L"map.jpg",

&g_texture);
}

void gameTerrain::SetVertex(LPDIRECT3DDEVICE9 g_pd3dDevice)
{
for (int x=0; x < WIDTH;x++)
{
for (int y=0; y < HEIGHT;y++)
{
Vertex[y * WIDTH + x].x = -x;
Vertex[y * WIDTH + x].y = y;
Vertex[y * WIDTH + x].z = HeightData[x][y];
Vertex[y * WIDTH + x].color = 0xffffffff;
}
}

if (FAILED(g_pd3dDevice->CreateVertexBuffer(WIDTH*HEIGHT*sizeof(VertexType), D3DUSAGE_WRITEONLY, D3DFVF_XYZ | D3DFVF_TEX1, D3DPOOL_DEFAULT, &VertexBuffer, NULL)))
{
MessageBox(NULL,L"Error while creating VertexBuffer",L"FillVertices()",MB_OK);
}

VOID* p_Vertices;
if (FAILED(VertexBuffer->Lock(0, WIDTH*HEIGHT*sizeof(VertexType), (void**)&p_Vertices, 0)))
{
MessageBox(NULL,L"Error trying to lock",L"FillVertices()",MB_OK);
}
else
{
memcpy(p_Vertices, Vertex, WIDTH*HEIGHT*sizeof(VertexType));
VertexBuffer->Unlock();
}

}

void gameTerrain::Render(LPDIRECT3DDEVICE9 g_pd3dDevice)
{
D3DXMATRIXA16 matWorld;
D3DXMatrixTranslation( &matWorld, 0, 0, 0);
D3DXMatrixRotationX(&matWorld, 90);
g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );

g_pd3dDevice->SetTexture(0, g_texture);
g_pd3dDevice->SetStreamSource( 0, VertexBuffer, 0, sizeof(VertexType) );
g_pd3dDevice->SetFVF(D3DFVF_XYZ|D3DFVF_TEX1 );


g_pd3dDevice->SetIndices(Indexs);



g_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,WIDTH*HEIGHT,0,(WIDTH-1)*(HEIGHT-1)*2);

/*g_pd3dDevice->SetIndices(NULL);
g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, (WIDTH-1)*(HEIGHT-1)*2);*/
}[/source]

and result is ; [url="http://prntscr.com/eobr8"]http://prntscr.com/eobr8[/url]

its something like just taking one pixel of image. what i did wrong ?
0

Share this post


Link to post
Share on other sites
Your vertex structure doesn't contain texture coordinates. As a matter of fact, your vertex structure doesn't match the vertex type declaration.

Your vertex structure is:

class VertexType
{
float x,y,z;
unsigned int color;
};

while it should be:

class VertexType
{
float x,y,z;
float u,v; // <- these members contain the texture coordinates.
};

Cheers!
0

Share this post


Link to post
Share on other sites
ok i did it now like that

[source lang="cpp"] for (int x=0; x < WIDTH;x++)
{
for (int y=0; y < HEIGHT;y++)
{
Vertex[y * WIDTH + x].x = -x;
Vertex[y * WIDTH + x].y = y;
Vertex[y * WIDTH + x].z = HeightData[x][y];
Vertex[y * WIDTH + x].u = x;
Vertex[y * WIDTH + x].v = y;
}
}[/source]

ok its working but, its working weird like;
http://prntscr.com/eoiqy

i want to do one terrain for one texture not like that, i want paint my map in jpg/png/bmp, its possible ?
0

Share this post


Link to post
Share on other sites
Well, you are practically repeating your texture once for each vertex. You'll need to scale your texture coordinates values by some value (I let you to find out the correct scale value) in order to have the texture repeat once over the terrain.

float ScaleX = ?;
float ScaleY = ?;

for (int x=0; x < WIDTH;x++)
{
for (int y=0; y < HEIGHT;y++)
{
Vertex[y * WIDTH + x].x = -x;
Vertex[y * WIDTH + x].y = y;
Vertex[y * WIDTH + x].z = HeightData[x][y];
Vertex[y * WIDTH + x].u = x * SCALEX;
Vertex[y * WIDTH + x].v = y * SCALEY;
}
}

cheers! Edited by kauna
1

Share this post


Link to post
Share on other sites
hmm its a good point but i have some problem still, if Scales bigger texture gonna small. i tried my jpg resolution and more thing, 1024,80,-1024

here is result : http://prntscr.com/eojz5

sorry for my english, its too bad :/
0

Share this post


Link to post
Share on other sites
Well did you try to put scales smaller than 1 ?

Let me give you a hint :

ScaleX = 1.0f / (float)Width;

Changing your texture resolution isn't the key to the problem.
1

Share this post


Link to post
Share on other sites
Check your scale variable type.

The correct type is given in my earlier post.

Cheers!
0

Share this post


Link to post
Share on other sites
[quote name='kauna' timestamp='1346350335' post='4974861']
Check your scale variable type.

The correct type is given in my earlier post.

Cheers!
[/quote]

yes it was my mistake, thanks so much [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0