PDA

View Full Version : Textures just black in GL 4



TraxMate
10-12-2011, 11:32 AM
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.

sqrt[-1]
10-13-2011, 01:40 AM
You are probably making use of some deprecated functionality - either remove the old calls or init the context with the WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB flag.

Probably add WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB

to the nContextAttributes array.

kyle_
10-13-2011, 11:43 AM
You set pixel format for the same window twice. This is illegal.

TraxMate
10-13-2011, 12:25 PM
]You are probably making use of some deprecated functionality - either remove the old calls or init the context with the WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB flag.

Probably add WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB

to the nContextAttributes array. Thanks that helped :). But all the functions I'm using are from the OpenGL SuperBible 5 which is supposed to teach GL 4 so it's weird that it uses deprecated functions :s.


You set pixel format for the same window twice. This is illegal. Didn't know that thanks for telling. I have changed the init code know.

Jesse
10-30-2011, 08:40 PM
Thanks that helped :). But all the functions I'm using are from the OpenGL SuperBible 5 which is supposed to teach GL 4 so it's weird that it uses deprecated functions :s.

This is not true. If you read the back cover of the Superbible 5, it says: "OpenGL Superbible, Fifth Edition is the definitive programmer's guide, ....for.... OpenGL 3.3." As of yet, I am unaware of any book which teaches GL 4.