Hi!
This have been bothering me for quite a while… I want to make use of textures in my application but the result is just a black triangle! After a lot of error checking I decided to lower the context version from 4 to 3 and the texture worked.
But why does it work in GL 3 and not 4? This is my code for initialize GL:
bool InitializeGL(HWND hWnd, UINT nWidth, UINT nHeight)
{
PIXELFORMATDESCRIPTOR pfd;
// Create dummy context
g_hDC = GetDC(hWnd);
SetPixelFormat(g_hDC, 1, &pfd);
g_hRC = wglCreateContext(g_hDC);
wglMakeCurrent(g_hDC, g_hRC);
// Initialize GLEW to get all extensions
if(glewInit() != GLEW_OK)
{
MessageBox(NULL, "glewInit() failed.", NULL, MB_OK | MB_ICONERROR);
return false;
}
// Check if OpenGL 4.0 is supported
if(!GLEW_VERSION_4_0)
{
MessageBox(NULL, "No support for OpenGL 4.0", NULL, MB_OK | MB_ICONERROR);
return false;
}
// Destroy dummy context
wglMakeCurrent(NULL, NULL);
wglDeleteContext(g_hRC);
ReleaseDC(hWnd, g_hDC);
// Create a proper rendering context
g_hDC = GetDC(hWnd);
int nPixelCount, nPixelFormat;
int nPixelAttributes[] =
{
WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
WGL_COLOR_BITS_ARB, 32,
WGL_DEPTH_BITS_ARB, 32,
WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
0,
};
wglChoosePixelFormatARB(g_hDC, nPixelAttributes, NULL, 1, &nPixelFormat, (PUINT)&nPixelCount);
if(nPixelFormat == -1)
{
ShowWinError();
return false;
}
SetPixelFormat(g_hDC, nPixelFormat, &pfd);
int nContextAttributes[] =
{
WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
WGL_CONTEXT_MINOR_VERSION_ARB, 0,
0,
};
g_hRC = wglCreateContextAttribsARB(g_hDC, NULL, nContextAttributes);
if(!g_hRC)
{
ShowWinError();
return false;
}
if(!wglMakeCurrent(g_hDC, g_hRC))
{
ShowWinError();
return false;
}
return true;
}
This is how it looks in GL 3: http://localhostr.com/file/riwzabn/GL3.png
And here in GL4: http://localhostr.com/file/OijN8uR/GL4.png
The only difference in the code are the context creation number :S. Please tell if I need to post more code.