IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

OpenGL Discussion :

wglCreateContextAttribsARB ne fonctionne pas


Sujet :

OpenGL

  1. #1
    Membre extrêmement actif
    Profil pro
    Inscrit en
    Mai 2011
    Messages
    935
    Détails du profil
    Informations personnelles :
    Localisation : France, Vienne (Poitou Charente)

    Informations forums :
    Inscription : Mai 2011
    Messages : 935
    Par défaut wglCreateContextAttribsARB ne fonctionne pas
    A l'aide :

    Bonjour,
    J'ai un projet opengl fonctionne quand je passe wglCreateContext (mais la fonction est obsoléte et sera retirer dans le long terme),
    Mais quand je veux utiliser la fonction de remplacement 'wglCreateContextAttribsARB' , aucun primitive dessiner ,seul la fonction glClearColor fonctionne.

    Sur le web il n'y pas de sample utilisant la fonction wglCreateContextAttribsARB
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
     
    static void
    init_opengl_extensions(void)
    {
    	// Before we can load extensions, we need a dummy OpenGL context, created using a dummy window.
    	// We use a dummy window because you can only set the pixel format for a window once. For the
    	// real window, we want to use wglChoosePixelFormatARB (so we can potentially specify options
    	// that aren't available in PIXELFORMATDESCRIPTOR), but we can't load and use that before we
    	// have a context.
    	WNDCLASSA window_class = { 0 };
    	window_class.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
    	window_class.lpfnWndProc = DefWindowProcA;
    	window_class.hInstance = GetModuleHandle(0);
    	window_class.lpszClassName = "Dummy_WGL_djuasiodwa";
     
     
    	if (!RegisterClassA(&window_class)) {
    		fatal_error("Failed to register dummy OpenGL window.");
    	}
     
    	HWND dummy_window = CreateWindowExA(
    		0,
    		window_class.lpszClassName,
    		"Dummy OpenGL Window",
    		0,
    		CW_USEDEFAULT,
    		CW_USEDEFAULT,
    		CW_USEDEFAULT,
    		CW_USEDEFAULT,
    		0,
    		0,
    		window_class.hInstance,
    		0);
     
    	if (!dummy_window) {
    		fatal_error("Failed to create dummy OpenGL window.");
    	}
     
    	HDC dummy_dc = GetDC(dummy_window);
     
    	PIXELFORMATDESCRIPTOR pfd;
    	pfd.nSize = sizeof(pfd);
    	pfd.nVersion = 1;
    	pfd.iPixelType = PFD_TYPE_RGBA;
    	pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
    		pfd.cColorBits = 32;
    		pfd.cAlphaBits = 8;
    		pfd.iLayerType = PFD_MAIN_PLANE;
    		pfd.cDepthBits = 24;
    		pfd.cStencilBits = 8;
     
     
    	int pixel_format = ChoosePixelFormat(dummy_dc, &pfd);
    	if (!pixel_format) {
    		fatal_error("Failed to find a suitable pixel format.");
    	}
    	if (!SetPixelFormat(dummy_dc, pixel_format, &pfd)) {
    		fatal_error("Failed to set the pixel format.");
    	}
     
    	HGLRC dummy_context = wglCreateContext(dummy_dc);
    	if (!dummy_context) {
    		fatal_error("Failed to create a dummy OpenGL rendering context.");
    	}
     
    	if (!wglMakeCurrent(dummy_dc, dummy_context)) {
    		fatal_error("Failed to activate dummy OpenGL rendering context.");
    	}
     
    	wglCreateContextAttribsARB = (wglCreateContextAttribsARB_type*)wglGetProcAddress(
    		"wglCreateContextAttribsARB");
    	wglChoosePixelFormatARB = (wglChoosePixelFormatARB_type*)wglGetProcAddress(
    		"wglChoosePixelFormatARB");
     
    	wglMakeCurrent(dummy_dc, 0);
    	wglDeleteContext(dummy_context);
    	ReleaseDC(dummy_window, dummy_dc);
    	DestroyWindow(dummy_window);
    }
     
     
    void EnableOpenGL(HWND hWnd, HDC* hDC, HGLRC* hRC)
    {
     
     
    	init_opengl_extensions();
    	// get the device context (DC)
     
     
    		/*wglCreateContextAttribsARB = (wglCreateContextAttribsARB_type*)wglGetProcAddress(
    		"wglCreateContextAttribsARB");
     
    		wglChoosePixelFormatARB = (wglChoosePixelFormatARB_type*)wglGetProcAddress(
    			"wglChoosePixelFormatARB");*/
     
    		if ((wglCreateContextAttribsARB != NULL)&&(wglChoosePixelFormatARB!=NULL))
    		{
     
     
     
     
     
    			*hDC = GetDC(hWnd);
     
     
     
    		//	int pixel_format_attribs[] = {
    		//WGL_DRAW_TO_WINDOW_ARB,     GL_TRUE,
    		//WGL_SUPPORT_OPENGL_ARB,     GL_TRUE,
    		//WGL_DOUBLE_BUFFER_ARB,      GL_TRUE,
    		//WGL_ACCELERATION_ARB,       WGL_FULL_ACCELERATION_ARB,
    		//WGL_PIXEL_TYPE_ARB,         WGL_TYPE_RGBA_ARB,
    		//WGL_SAMPLE_BUFFERS_ARB,  GL_TRUE ,
    		//WGL_COLOR_BITS_ARB,         32,
    		//WGL_DEPTH_BITS_ARB,         24,
    		//WGL_STENCIL_BITS_ARB,       8,
    		//0,0
    		//	};
     
    			int pixel_format_attribs[] = {
    		 WGL_SUPPORT_OPENGL_ARB, 1,
    		WGL_DRAW_TO_WINDOW_ARB, 1,
    		/*WGL_DRAW_TO_BITMAP_ARB, 1,*/
    		WGL_DOUBLE_BUFFER_ARB, 1,
    		//WGL_SWAP_LAYER_BUFFERS_ARB, 1,
    		WGL_COLOR_BITS_ARB, 32,
    		WGL_RED_BITS_ARB, 8,
    		WGL_GREEN_BITS_ARB, 8,
    		WGL_BLUE_BITS_ARB, 8,
    		WGL_ALPHA_BITS_ARB, 8,
    		WGL_DEPTH_BITS_ARB, 8,
    		WGL_STENCIL_BITS_ARB, 8,
    		WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
    		WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
    		0
    			};
     
    			int pixel_format;
    			UINT num_formats;
    			wglChoosePixelFormatARB(*hDC, pixel_format_attribs, 0, 1, &pixel_format, &num_formats);
    			if (!num_formats) {
     				fatal_error("Failed to set the OpenGL 3.3 pixel format.");
    			}
     
    			PIXELFORMATDESCRIPTOR pfd;
    			DescribePixelFormat(*hDC, pixel_format, sizeof(pfd), &pfd);
    			if (!SetPixelFormat(*hDC, pixel_format, &pfd)) {
    				fatal_error("Failed to set the OpenGL 3.3 pixel format.");
    			}
     
     
    			// Specify that we want to create an OpenGL 3.3 core profile context
    			int gl33_attribs[] = {
    				WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
    				WGL_CONTEXT_MINOR_VERSION_ARB, 3,
    				WGL_CONTEXT_PROFILE_MASK_ARB,  WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
    				0,
    			};
     
    			*hRC = wglCreateContextAttribsARB(*hDC, 0, gl33_attribs);
     
    		}
    		else
    		{
    			*hRC = wglCreateContext(*hDC);
    			wglMakeCurrent(*hDC, *hRC);
    		 }
     
     
    	wglMakeCurrent(*hDC, *hRC);
     
     
     
    }
    #endif
    char checkShaderCompilation(GLuint shaderID)
    {
    	GLint compilationStatus = 0;
     
    	// Vérification de la compilation pour le vertex shader
    	glGetShaderiv(opengl.vertexID, GL_COMPILE_STATUS, &compilationStatus);
    	//if (compilationStatus != GL_TRUE)
    	{
    		// Nous savons que la compilation a échoué, donc nous devons savoir pourquoi
    		// Nous devons récupéré la taille du log
    		GLint logLength = 0;
    		char* log = NULL;
     
    		glGetShaderiv(shaderID, GL_INFO_LOG_LENGTH, &logLength);
    		if (logLength > 0)
    		{
    			// Maintenant que nous avons la taille, nous pouvons alloué la mémoire suffisante pour ce log
    			log = (char*)malloc(logLength);
    			if (log == NULL)
    			{
    				fprintf(stderr, "Erreur d'allocation de mémoire pour le log de la compilation du shader\n");
    				return 0;
    			}
     
    			glGetShaderInfoLog(shaderID, logLength, &logLength, log);
     
    			// On peut afficher le message
    			fprintf(stderr, "Erreur de compilation:\n%s", log);
    			MessageBox(NULL, log, NULL, MB_ICONHAND);
    			// Et on n'oublie pas de libéré la mémoire
    			free(log);
     
    			return 0;
    		}
    		else
    			return 1;
    	}
     
    	return 1; // Pas d'erreur
    }
    Ca ne marche pas , et j'y suis depuis 3 heures.
    Pourtant je ne passe pas à la fonction fatal_error



    Pour information je travaille sous Vmware player 17.01 : 17.0.1 build-21139696

    Pour conclure ce n'est pas un problème de shader.

    Merci

  2. #2
    Expert confirmé

    Avatar de dragonjoker59
    Homme Profil pro
    Software Developer
    Inscrit en
    Juin 2005
    Messages
    2 036
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Software Developer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2005
    Messages : 2 036
    Billets dans le blog
    12
    Par défaut
    Bonjour !

    Alors pour pouvoir utiliser la fonction wglCreateContextAttribsARB, il faut un contexte actif.
    On a donc un code qui ressemble à ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    wglMakeCurrent( hDC, dummyContext );
    *hRC = wglCreateContextAttribsARB( hDC, NULL, gl33_attribs );
    wglMakeCurrent( hDC, NULL );
    wglDeleteContext( dummyContext );
    Tu peux voir comment je fais, ici : https://github.com/DragonJoker/Ashes...ntext.cpp#L407

    Et puis :
    (mais la fonction est obsoléte et sera retirer dans le long terme)
    OpenGL est obsolète et sera retiré dans le long terme (Vulkan, Metal, D3D12...).
    Si vous ne trouvez plus rien, cherchez autre chose...

    Vous trouverez ici des tutoriels OpenGL moderne.
    Mon moteur 3D: Castor 3D, presque utilisable (venez participer, il y a de la place)!
    Un projet qui ne sert à rien, mais qu'il est joli (des fois) : ProceduralGenerator (Génération procédurale d'images, et post-processing).

  3. #3
    Membre extrêmement actif
    Profil pro
    Inscrit en
    Mai 2011
    Messages
    935
    Détails du profil
    Informations personnelles :
    Localisation : France, Vienne (Poitou Charente)

    Informations forums :
    Inscription : Mai 2011
    Messages : 935
    Par défaut
    Citation Envoyé par dragonjoker59 Voir le message
    Bonjour !

    OpenGL est obsolète et sera retiré dans le long terme (Vulkan, Metal, D3D12...).

    Tu veux dire que tout OpenGl va disparaitre c'est à dire retirer ???

  4. #4
    Expert confirmé

    Avatar de dragonjoker59
    Homme Profil pro
    Software Developer
    Inscrit en
    Juin 2005
    Messages
    2 036
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Software Developer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2005
    Messages : 2 036
    Billets dans le blog
    12
    Par défaut
    Pas retiré, je suppose, mais au mieux émulé.
    Si vous ne trouvez plus rien, cherchez autre chose...

    Vous trouverez ici des tutoriels OpenGL moderne.
    Mon moteur 3D: Castor 3D, presque utilisable (venez participer, il y a de la place)!
    Un projet qui ne sert à rien, mais qu'il est joli (des fois) : ProceduralGenerator (Génération procédurale d'images, et post-processing).

  5. #5
    Membre extrêmement actif
    Profil pro
    Inscrit en
    Mai 2011
    Messages
    935
    Détails du profil
    Informations personnelles :
    Localisation : France, Vienne (Poitou Charente)

    Informations forums :
    Inscription : Mai 2011
    Messages : 935
    Par défaut
    Citation Envoyé par dragonjoker59 Voir le message
    Pas retiré, je suppose, mais au mieux émulé.
    1)Il sera remplacer par quoi ?
    2)Opengl emulé : oui mais la rendu 3d sera t'il logiciel(emulé) ou matériel(carte graphique ) ?

  6. #6
    Expert confirmé

    Avatar de dragonjoker59
    Homme Profil pro
    Software Developer
    Inscrit en
    Juin 2005
    Messages
    2 036
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Software Developer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2005
    Messages : 2 036
    Billets dans le blog
    12
    Par défaut
    Remplacé par les API modernes (Vulkan, Metal, D3D12)
    Et il sera émulé via une API moderne (les appels OpenGL seront convertis en appels dans l'api choisie)
    Si vous ne trouvez plus rien, cherchez autre chose...

    Vous trouverez ici des tutoriels OpenGL moderne.
    Mon moteur 3D: Castor 3D, presque utilisable (venez participer, il y a de la place)!
    Un projet qui ne sert à rien, mais qu'il est joli (des fois) : ProceduralGenerator (Génération procédurale d'images, et post-processing).

  7. #7
    Membre extrêmement actif
    Profil pro
    Inscrit en
    Mai 2011
    Messages
    935
    Détails du profil
    Informations personnelles :
    Localisation : France, Vienne (Poitou Charente)

    Informations forums :
    Inscription : Mai 2011
    Messages : 935
    Par défaut
    J'ai regarder un sample de vulkan ici qui affiche un triangle , c'est 10 fois plus complexes que OpenGL --> plus de 1000 lignes pour afficher un triangle.
    Je ne vois pas pourquoi openGL serais obsolète : c'est bien plus simple et accessible.

  8. #8
    Expert confirmé

    Avatar de dragonjoker59
    Homme Profil pro
    Software Developer
    Inscrit en
    Juin 2005
    Messages
    2 036
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Software Developer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2005
    Messages : 2 036
    Billets dans le blog
    12
    Par défaut
    OpenGL n'évolue plus (dernière évolution en 2017), alors que les GPU n'ont pas arrêté, eux, d'évoluer ...

    EDIT:

    Et sinon, pour ton soucis de création de contexte moderne, c'est réglé ?
    Si vous ne trouvez plus rien, cherchez autre chose...

    Vous trouverez ici des tutoriels OpenGL moderne.
    Mon moteur 3D: Castor 3D, presque utilisable (venez participer, il y a de la place)!
    Un projet qui ne sert à rien, mais qu'il est joli (des fois) : ProceduralGenerator (Génération procédurale d'images, et post-processing).

Discussions similaires

  1. Réponses: 6
    Dernier message: 27/01/2004, 12h14
  2. [FP]Writeln ne fonctionne pas !
    Par néo333 dans le forum Turbo Pascal
    Réponses: 4
    Dernier message: 02/11/2003, 00h47
  3. UNION qui ne fonctionne pas
    Par r-zo dans le forum Langage SQL
    Réponses: 7
    Dernier message: 21/07/2003, 11h04
  4. Un Hint sur un PopupMenu ne fonctionne pas !!??
    Par momox dans le forum C++Builder
    Réponses: 6
    Dernier message: 26/05/2003, 17h48
  5. ca ne fonctionne pas (generateur auto-incrémentant)
    Par tripper.dim dans le forum SQL
    Réponses: 7
    Dernier message: 26/11/2002, 01h10

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo