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 344839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:01:40+00:00 2026-05-12T11:01:40+00:00

I am new to DirectX and I am trying to draw two rectangles in

  • 0

I am new to DirectX and I am trying to draw two rectangles in one scene using D3DPT_TRIANGLESTRIP. One Rectangle is no problem but two Rectangles is a whole different ball game. Yes i could draw them using four triangles drawn with the D3DPT_TRIANGLELIST primitive type. My curiosity is on the technic involved using D3DPT_TRIANGLESTRIP.
Parts of the code i am using for one Rectangle using D3DPT_TRIANGLESTRIP is as follows:

CUSTOMVERTEX recVertex[] = {
    {  10.0f,  10.0f, 0.10f, 1.0f, 0xffffffff, }, // x, y, z, rhw, color
    { 220.0f,  10.0f, 0.10f, 1.0f, 0xffffffff, },   
    {  10.0f, 440.0f, 0.10f, 1.0f, 0xffffffff, },   
    { 220.0f, 440.0f, 0.10f, 1.0f, 0xffffffff, },
}; 

if( FAILED( g_pd3dDevice->CreateVertexBuffer( 4 * sizeof( CUSTOMVERTEX ),
               0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
{
    return E_FAIL;
}

More vital code…

VOID* precVertex;    
if( FAILED( g_pVB->Lock( 0, sizeof( recVertex ), ( void** )&pGameField, 0 ) ) ) 
{
return E_FAIL; 
}
 memcpy( precVertex, recVertex, sizeof( recVertex ) );

then Render like so…

g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof( CUSTOMVERTEX ) );
g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );

Based on this model I could easily duplicate the code change the x and y values on the Custom Vertex and create another vertex buffer and it would work.

Personally i feel this is not the best way to go especially considering a situation when i have to draw say 100 rectangles or something like that. The thing is, I don’t have other ideas. So my question is, what is the most efficient way to draw two Rectangles with D3DPT_TRIANGLESTRIP? Also is there a possible way of duplicating and transforming the current rectangle?

  • 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-12T11:01:40+00:00Added an answer on May 12, 2026 at 11:01 am

    Add the four vertices for the second rectangle to the vertex buffer, then call DrawPrimitive twice.

    g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof( CUSTOMVERTEX ) );
    g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
    g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );
    g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 4, 2 );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

New to Node.js and Express, I am trying to understand the two seems overlapping
New developer here,Im using the Custom Image Picker by ray wenderlich. But what I
I trying to use twitter API to send direct messages using C# but Twitter
I am new to LINQ and am trying to sort this one out. I
I am trying to load and draw a 2d texture using OpenGL with GLFW
I'm trying to use the Sprite Class in Microsoft.DirectX.Direct3D to draw some sprites to
I'm absolutely new to DirectX and I'd like to draw some untransformed primitives with
i'm trying to deserialize a json string into a new list on C# using
I am new to Haskell and I am trying to understand why one needs
I admit, I'm new at this whole Android stuff. I am trying to make

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.