Sign in to follow this  
Udi Raz

color is changes

Recommended Posts

Hi, I am drawing a red ( pure red 0xFFFF0000 ) rectangle in screen space. Then i am loading a model and set texture. When I set the texture the color of the rect changes to a dark red. Here is the code of Render()

  //Clear the buffer to our new colour.
   hr=g_d3d_device->Clear(0,  //Number of rectangles to clear, we're clearing everything so set it to 0
                          NULL, //Pointer to the rectangles to clear, NULL to clear whole display
                          D3DCLEAR_TARGET,   //What to clear.  We don't have a Z Buffer or Stencil Buffer
                          0x000000FF, //Colour to clear to (AARRGGBB)
                          1.0f,  //Value to clear ZBuffer to, doesn't matter since we don't have one
                          0 );   //Stencil clear value, again, we don't have one, this value doesn't matter
      return hr;

   //Notify the device that we're ready to render
      return hr;


   //Bind our Vertex Buffer
   g_d3d_device->SetStreamSource(0,                   //StreamNumber
                                 g_list_vb,           //StreamData
                                 0,                   //OffsetInBytes
                                 sizeof(TriVertex)); //Stride

   //Render from our Vertex Buffer
   g_d3d_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, //PrimitiveType
                               0,                  //StartVertex
                               2);      //PrimitiveCount


   for( DWORD j=0; j<g_dwNumMaterials; j++ )
   	// Set the material and texture for this subset
   	g_d3d_device->SetMaterial( &g_pMeshMaterials[j] );
   	g_d3d_device->SetTexture( 0, g_pMeshTextures[j] );
   	// Draw the mesh subset
   	g_pMesh->DrawSubset( j );

   //Notify the device that we're finished rendering for this frame

   //Show the results
   hr=g_d3d_device->Present(NULL,  //Source rectangle to display, NULL for all of it
                            NULL,  //Destination rectangle, NULL to fill whole display
                            NULL,  //Target window, if NULL uses device window set in CreateDevice
                            NULL );//Unused parameter, set it to NULL

   return hr;

Any Ideas ?

Share this post

Link to post
Share on other sites
Hey bud,

The only thing i can think of is that the texture might have red in it, and therefor being drawn onto the quad for the rect.


Share this post

Link to post
Share on other sites
You'll need to disable texturing before drawing the rectangle. Otherwise direct3d will texture the rectangle using the texture - and since you havn't set any texture coordinates you'll probably just get a single pixel of the texture stretched across the entire rectangle. This would explain the effect you're seeing.

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