Hello everyone, I try to program in OpenGL 3.3.
At the opening of a context, I wonder if I use the correct method (I do not want to use any lib like glew etc…).
I have some questions.
what are the various possibilities in attriblist []
I think I understand the following two:
WGL_CONTEXT_MAJOR_VERSION_ARB and WGL_CONTEXT_MINOR_VERSION_ARB.
but for others I confess I swim a little
I guess WGL_CONTEXT_FLAGS_ARB
if I pass the flag (WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB or 2)
in this case I would not have access to the functions depreciates ?
if I pass 0 : mode compatibility with depreciates functions ?
if I pass WGL_CONTEXT_DEBUG_BIT_ARB or 1 : for à debbuging context ?
WGL_CONTEXT_PROFILE_MASK_ARB ???
2 flags (WGL_CONTEXT_CORE_PROFILE_BIT_ARB or WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB)
If I understand if I put the following values in attriblist
int attriblist[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 2, WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, 0, 0 };
I created a context 3.2 or higher that does not use deprecated functions ?
right now another problem happens to me
When I created a context 2.1 textures are displayed, colors, normal etc… everything works
with:
When I created a context 3.3 my textures are not displayed but I have the colors, normals etc…
that must be done in OpenGL 3.3 and more
I need your help
PiouPiou
Init( short width, short height, unsigned char nbp, bool fullscreen, int cmdshow, char *name, int major, int minor )
{
hinst = GetModuleHandle(NULL);
DWORD style;
DWORD exstyle;
mywindows.cbSize = sizeof( WNDCLASSEX ) ;
mywindows.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
mywindows.lpfnWndProc = WndProc;
mywindows.hInstance = hinst;
mywindows.hCursor = LoadCursor( NULL, IDC_HAND );
mywindows.hIcon = LoadIcon(NULL, IDI_ASTERISK);
mywindows.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
mywindows.hbrBackground = 0;
mywindows.lpszMenuName = 0;
mywindows.cbClsExtra = 0;
mywindows.cbWndExtra = 0;
mywindows.lpszClassName = "wc";
RegisterClassEx(&mywindows);
if (fullscreen) // Si on est en plein ecran
{
DEVMODE dm;
memset(&dm, 0, sizeof(dm));
dm.dmSize = sizeof(dm);
dm.dmPelsWidth = width;
dm.dmPelsHeight = height;
dm.dmBitsPerPel = nbp;
dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
if ( ChangeDisplaySettings(&dm, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL )
{
return false;
}
style = WS_POPUP;
exstyle = WS_EX_APPWINDOW;
ShowCursor(FALSE);
}
else
{
style = WS_OVERLAPPEDWINDOW;
exstyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
}
RECT rc = { 0, 0, width, height };
AdjustWindowRectEx( &rc, style, false, exstyle );
hwnd = CreateWindowEx( exstyle, "wc", name, style, 0, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, hinst, NULL );
if( !hwnd )
return false;
static PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be
{
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
1, // Version Number
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
nbp, // Select Our Color Depth
0, 0, 0, 0, 0, 0, // Color Bits Ignored
0, // No Alpha Buffer
0, // Shift Bit Ignored
0, // No Accumulation Buffer
0, 0, 0, 0, // Accumulation Bits Ignored
16, // 16Bit Z-Buffer (Depth Buffer)
0, // No Stencil Buffer
0, // No Auxiliary Buffer
PFD_MAIN_PLANE, // Main Drawing Layer
0, // Reserved
0, 0, 0 // Layer Masks Ignored
};
if ( !( hdc = GetDC(hwnd) ) ) // Did We Get A Device Context?
{
Close();
return FALSE; // Return FALSE
}
unsigned int pixelformat;
if ( !( pixelformat = ChoosePixelFormat(hdc, &pfd) ) ) // Did Windows Find A Matching Pixel Format?
{
Close();
return FALSE; // Return FALSE
}
if( !SetPixelFormat(hdc, pixelformat, &pfd) ) // Are We Able To Set The Pixel Format?
{
Close();
return FALSE; // Return FALSE
}
if (major < 3)
hrc = wglCreateContext(hdc);
else
hrc = wglCreateContextAttribsARB(hdc, 0, attriblist);
if( !wglMakeCurrent(hdc, hrc) ) // Try To Activate The Rendering Context
{
Close();
return FALSE;
}
ShowWindow( hwnd, cmdshow );
return true;
}
Close()
{
if (fullscreen)
{
ChangeDisplaySettings(NULL,0);
ShowCursor(TRUE);
}
if (hrc)
{
wglMakeCurrent(NULL,NULL);
wglDeleteContext(hrc);
hrc = 0;
}
if (hdc)
{
ReleaseDC(hwnd,hdc);
hdc = 0;
}
if (hwnd)
{
DestroyWindow(hwnd);
hwnd = 0;
}
UnregisterClass("wc",hinst);
return true;
}
int attriblist[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 3, WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, 0, 0 };
HGLRC wglCreateContextAttribsARB(HDC hDC, HGLRC hShareContext, const int *attribList)
{
typedef HGLRC (APIENTRY * PFNWGLCREATECONTEXTATTRIBSARBPROC)(HDC hDC, HGLRC hShareContext, const int *attribList);
static PFNWGLCREATECONTEXTATTRIBSARBPROC pfnCreateContextAttribsARB = 0;
HGLRC hContext = 0;
HGLRC hCurrentContext = wglGetCurrentContext();
if (!hCurrentContext)
{
if (!(hCurrentContext = wglCreateContext(hDC)))
return 0;
if (!wglMakeCurrent(hDC, hCurrentContext))
{
wglDeleteContext(hCurrentContext);
return 0;
}
if (!pfnCreateContextAttribsARB)
pfnCreateContextAttribsARB = reinterpret_cast<PFNWGLCREATECONTEXTATTRIBSARBPROC>(wglGetProcAddress(wglCreateContextAttribsARB));
if (pfnCreateContextAttribsARB)
hContext = pfnCreateContextAttribsARB(hDC, hShareContext, attribList);
wglMakeCurrent(hDC, 0);
wglDeleteContext(hCurrentContext);
}
else
{
if (!wglMakeCurrent(hDC, hCurrentContext))
return 0;
pfnCreateContextAttribsARB = reinterpret_cast<PFNWGLCREATECONTEXTATTRIBSARBPROC>(wglGetProcAddress(wglCreateContextAttribsARB));
if (pfnCreateContextAttribsARB)
hContext = pfnCreateContextAttribsARB(hDC, hShareContext, attribList);
}
return hContext;
}