Using Vectors and glReadPixels

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>( &m_pix ) );

This crashes…memory issue?
How can i use vectors with this call?

TIA

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_nWidthm_nHeight3 for the red, green, and blue color components?

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