0
\$\begingroup\$

I want to make a red texture image buffer. Would anyone help me to make it in right way. I have tried following:

std::vector<BYTE> redTexture(w*h*4);
const auto stride = w * 4;
BYTE* buf = redTexture.data();

for (int i = 0; i < h; ++i)
{
  const auto redValue = Gdiplus::Color::Red;
  memcpy(buf, &redValue, stride);
  buf += stride;
}
\$\endgroup\$
  • 1
    \$\begingroup\$ What went wrong with your current code? Did you get a compilation or runtime error? Or does it give a different result than expected? \$\endgroup\$ – DMGregory Dec 23 '18 at 11:16
  • \$\begingroup\$ I could not map the buffer to ID3D11Texture2D using device context - throws exception \$\endgroup\$ – Tajuddin Khandaker Dec 24 '18 at 6:43
  • 1
    \$\begingroup\$ Including the details of the exception you got inside your question itself will help users searching for similar problems. \$\endgroup\$ – DMGregory Dec 29 '18 at 19:07
0
\$\begingroup\$

I have solved the issue by doing the following:

    CImage m_cImage;
    // create a test image
    m_cImage.Create(w, -h, 8 * 4); // 8 bpp * 4 channel
    auto hdc = m_cImage.GetDC();
    Gdiplus::Graphics graphics(hdc);

    // Create a SolidBrush object.
    Gdiplus::SolidBrush redBrush(Gdiplus::Color::Red);

    // Fill the rectangle.
    Gdiplus::Status status = graphics.FillRectangle(&redBrush, 0, 0, w, h);
    TRY_CONDITION(status == Gdiplus::Status::Ok);
    ....
    // Then saved the m_cImage.GetBits() to bmp file using Gdiplus::Bitmap
    // and my expected texture is found
\$\endgroup\$
  • \$\begingroup\$ I'm glad you found a solution. Remember to mark your answer as "Accepted" so other users experiencing similar problems can quickly find working solutions. It will also help them if you add some explanation about why this works when your earlier approach didn't. \$\endgroup\$ – DMGregory Dec 29 '18 at 19:04

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.