1. I am using CreateDIBSection() for off screen rendering.
2. Which is working fine in my code as listed below.
3. But i am getting problem with textures as i am getting max texture size is 1024
4. I am getting desired 4096 texture size when i render to application window.
5. Pixel format of main application window and offscreen window is different.
6. The difference of pixel format and returned max texture size is mentioned below.
<red>How can i get 4096 max texture size for offscreen window also?<red>
Getting 1024 max texture size
------------------------------
PFD_DRAW_TO_BITMAP |
PFD_SUPPORT_OPENGL |
PFD_STEREO_DONTCARE,
PFD_TYPE_RGBA,
Getting 1024 max texture size
------------------------------
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
What pixel format should i use to get 4096 max texture size.
bool Create(unsigned int width, unsigned int height)
{
// Create a p-buffer for off-screen rendering
m_uiWidth = width;
m_uiHeight = height;
m_hWnd = g_pMainApplicationWindow->GetHWND();
m_hMainApplicationWindowDC = g_pMainApplicationWindow->GetHDC();
m_hMainApplicationWindowRC = g_pMainApplicationWindow->GetHGLRC();
memset(&m_bmi, 0, sizeof(BITMAPINFO));
m_bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
m_bmi.bmiHeader.biWidth = m_uiWidth;
m_bmi.bmiHeader.biHeight = m_uiHeight;
m_bmi.bmiHeader.biPlanes = 1;
m_bmi.bmiHeader.biBitCount = 32;
m_bmi.bmiHeader.biCompression = BI_RGB;
m_bmi.bmiHeader.biSizeImage = m_uiWidth * m_uiHeight * 4;
// Create DIB
HDC hDC = ::GetDC(m_hWnd);
m_hDib = ::CreateDIBSection(hDC, &m_bmi, DIB_RGB_COLORS, (void**)&m_pTextureData, NULL, (DWORD)0);
ReleaseDC(m_hWnd, hDC);
m_hMemDC = ::CreateCompatibleDC(NULL);
if(!m_hMemDC)
{
DeleteObject(m_hDib);
m_hDib = NULL;
return (false);
}
m_hOldDib = SelectObject(m_hMemDC, m_hDib);
// Setup memory DC's pixel format.
if (!SetDCPixelFormat(m_hMemDC, PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_STEREO_DONTCARE))
{
SelectObject(m_hMemDC, m_hOldDib);
DeleteObject(m_hDib);
m_hDib = NULL;
DeleteDC(m_hMemDC);
m_hMemDC = NULL;
return (false);
}
m_hRC = ::wglCreateContext(m_hMemDC);
if (!m_hRC)
{
SelectObject(m_hMemDC, m_hOldDib);
DeleteObject(m_hDib);
m_hDib = NULL;
DeleteDC(m_hMemDC);
m_hMemDC = NULL;
return (false);
}
}
bool SetDCPixelFormat(HDC hDC, DWORD dwFlags)
{
HDC NewHdc = hDC;
static PIXELFORMATDESCRIPTOR pixelDesc =
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_BITMAP |
PFD_SUPPORT_OPENGL |
PFD_STEREO_DONTCARE,
PFD_TYPE_RGBA,
32,
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
16,
1, // Use stencil buffer
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};
GLuint PixelFormat;
int nPixelIndex = ::ChoosePixelFormat(NewHdc, &pixelDesc);
if (nPixelIndex == 0) // Choose default
{
nPixelIndex = 1;
if (::DescribePixelFormat(hDC, nPixelIndex,
sizeof(PIXELFORMATDESCRIPTOR), &pixelDesc) == 0)
return false;
}
if (!::SetPixelFormat(hDC, nPixelIndex, &pixelDesc))
return false;
return true;
}
bool DIBBuffer::StartRendering(void)
{
wglMakeCurrent(m_hMemDC, m_hRC);
BitBlt();
GLint texSize;
glGetIntegerv( GL_MAX_TEXTURE_SIZE, &texSize );
//i am getting max texture size 1024
//but when i use the below format i am getting 4096 max texture size
static PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
MAIN_APPLICATION_WINDOW_BITS_PER_PIXEL,
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
16,
1, // Use stencil buffer
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};
}