Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6841327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:57:10+00:00 2026-05-26T23:57:10+00:00

Hey guys can anybody help me with texture mapping in Direct3D C++. I have

  • 0

Hey guys can anybody help me with texture mapping in Direct3D C++. I have created a basic game and want to texture the enviroment. I have looked at numerous online tutorials but have had no luck so far

I am creating a custom vertex for my drawing code:

struct CUSTOMVERTEX
{
    FLOAT x, y, z; // The position for the vertex
    DWORD color;        // The vertex color
};

This is how I would draw a square:

CUSTOMVERTEX g_Vertices[] =
{

   {-1.0f,-1.0f,-1.0f,0xFF0000FF},{-1.0f, 1.0f,-1.0f,0xFF0000FF},
   { 1.0f, 1.0f,-1.0f,0xFF0000FF}, { 1.0f, 1.0f,-1.0f,0xFF0000FF},
   { 1.0f,-1.0f,-1.0f,0xFF0000FF},{-1.0f,-1.0f,-1.0f,0xFF0000FF},

};

Here is the buffer:

//*************************** Vertex Buffer ****************************
if( FAILED( g_pd3dDevice->CreateVertexBuffer( numberOfVertecies*sizeof(CUSTOMVERTEX), 
        0 /* Usage */, D3DFVF_CUSTOMVERTEX,D3DPOOL_MANAGED, &g_pVB, NULL ) ) )
    MessageBox(hwnd,"Vertex Buffer problem",NULL,NULL);

VOID* pVertices;

if( FAILED( g_pVB->Lock( 0, sizeof(g_Vertices), (void**)&pVertices, 0 ) ) )
    MessageBox(hwnd,"Vertex Lock Problem",NULL,NULL);

memcpy( pVertices, g_Vertices, sizeof(g_Vertices) );

g_pVB->Unlock();

and here is the square:

g_pd3dDevice->SetTransform( D3DTS_WORLD, &g_matWorld );
g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) );
g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 20);

I just want to see how to texture the square so I can go on to texturing my whole enviroment?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:57:10+00:00Added an answer on May 26, 2026 at 11:57 pm

    If you want to implement texture mapping you have to change your vertex structure to

    struct CUSTOMVERTEX
    {
        FLOAT x, y, z; // The position for the vertex
        FLOAT tu, tv; // Texture Coordinates
    };
    

    When you create the vertices change that color values to texture coordinates (dont forget that the (0,0) coordinate corresponds to the top-left corner of the texture map.

    You also have to adapt your vertex stream declaration:

    #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_TEX1)
    

    Load a texture using D3DXCreateTextureFromFile(). And you also have to tell the device to use the loaded texture. Check DirectX SDK Tutorial 5 to learn how to do that.

    If you just want to apply a texture (and not texture mapping and color per vertex, why would you want to give each vertex a color if you can simply apply the texture???) so use the vertex struct I wrote instead of the one in the tutorial.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys, if anybody can help me out i'd love it... What i have
hey guys can you please help me again, i want my restaurant system to
Hey guys, I have created a navbar and I'm wondering if I can create
Hey guys, this is simple but I can't make it workn... blah! I have
Hey guys i had an idea yesterday. Can you help me with this. Here
Hey guys can you help me with this. I've got this '/[^A-Za-z]/' but cannot
Hey guys, I have this quick bit of code that I can't figure out
Hey guys, before you guys say anything I have searched and can not find
Hey guys, take a look at this, maybe you can help me. This code
Hey guys, I have a bit of a problem that I can't solve. I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.