open a context Opengl 3.3 with wglCreateContextAttribsARB and texture probleme

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 :frowning: but I have the colors, normals etc…
that must be done in OpenGL 3.3 and more

I need your help :wink:

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;
}

Nobody have an idee ?

Don’t use WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB unless you’re just checking if you have any OpenGL function calls that are to be removed in future versions. It’s possible that the deprecated but not yet removed functions are still useful in the current version + it could even be decided to keep them in the future spec so the function may end up not getting removed at all.
WGL_CONTEXT_DEBUG_BIT_ARB provides extra debug capabilities, the extra error checks/reporting are likely to be at the cost of some performance though.
It looks like you want to get an OpenGL 3.2 Core Profile (which has old functions removed), rather than an OpenGL 3.2 Forward compatible context (all stuff that is marked to be removed in future versions disabled in this version), so you would want:

int attriblist[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 2, WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, 0, 0 };

Answers for all your question about context creation can be found in the OpenGL Registry. Or, more precisely, in WGL_CREATE_CONTEXT spec http://www.opengl.org/registry/specs/ARB/wgl_create_context.txt

WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB had its purpose in GL 3.0 and 3.1 contexts, but now when profiles are defined its function is pretty unclear. As Dan said, it serves to disable functions that are still in the core but MAYBE will be deprecated sometime in the future.

Considering problem with texturing, try to debug and preciselly locate function that makes the trouble. The Debug context along with debug_output extension will help you to do the job.

Thanks for your answers Alexaksandar and Dan.
I would test tonight.

hello all,

if I understood correctly,

int attriblist[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, MAJOR,
WGL_CONTEXT_MINOR_VERSION_ARB, MINOR,
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
0, 0 };

and

int attriblist[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, MAJOR,
WGL_CONTEXT_MINOR_VERSION_ARB, MINOR,
0, 0 };

are equivalent because WGL_CONTEXT_CORE_PROFILE_BIT_ARB is the default value.

about my problem of texture I’ve attached my code
I use visual studio 2010 but it’s easy to convert to any other IDE
that there is a single file.
you just have GL3\gl3.h
and link with opengl32.lib

at the top of the source you have :

#define WIDTH 800
#define HEIGHT 600
#define NBP 32
#define MAJOR 3 // for creating context opengl MAJOR VERSION TRY MAJOR = 3
#define MINOR 1 // for creating context opengl MINOR VERSION TRY MINOR = 2

it is easy to change the context

if the triangle is yellow it’s good you have my texture (work in context 3 . 1 )
but if the triangle is black it means its not working (in context 3.2 or higher)

where is the Bug ???

thank you in advance