View Full Version : Using Vectors and glReadPixels

05-05-2004, 12:25 PM
Im trying to use this call like so:

// .h
std::vector<BYTE> m_pix;

// .cpp (onrender)
m_pix.resize( m_nWidth * m_nHeight );
glReadPixels( 0, 0, m_nWidth, m_nHeight, GL_RGB, GL_UNSIGNED_BYTE, reinterpret_cast<LPVOID>( &amp;m_pix ) );This crashes...memory issue?
How can i use vectors with this call?


05-05-2004, 01:42 PM
Generally prefer static_cast over reinterpret_cast.

To get the address of the container's elements, use &m_pix[0].

Note, the C++ library doesn't specify that the elements of a vector are required to be in contiguous memory -- although it is likely the case and is the intention due to a defect report.

Finally, shouldn't you allocate m_nWidth*m_nHeight*3 for the red, green, and blue color components?

glReadPixels(0, 0, m_nWidth, m_nHeight, GL_RGB, GL_UNSIGNED_BYTE, &m_pix[0]);