Voilà je travaille actuellement sur un moteur 3D et j'ai un soucis pour implémenter le multisampling sur le rendu.
Dans ce moteur je créer un contexte bidon au démarrage de la dll du moteur afin de déterminer si le multisampling est ou non supporté par la carte :
//////////////////////////////////////////////////////////////////////////////////////////////
/// CreateWinInfoTest
//////////////////////////////////////////////////////////////////////////////////////////////
void CreateWinInfoTest(int w, int h)
{
MMechostr(1,"---------Fonction Test----------------------\n") ;
ZDetector detect ;
int pf;
HDC hdc;
HWND hwnd;
WNDCLASS wc;
static HINSTANCE hInstance = 0;
/* only register the window class once - use hInstance as a flag. */
if (!hInstance)
{
hInstance = GetModuleHandle(NULL);
wc.style = CS_OWNDC;
wc.lpfnWndProc = (WNDPROC)WindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = "OpenGL";
if (!RegisterClass(&wc)) { MMechostr (1,"---Impossible d'enregistrer la classe de fenêtre------\n") ;}
if (hwnd == NULL) { MMechostr(1,"---Impossible de créer la fenêtre---\n") ;}
// Récupération du contexte
hdc = GetDC(hwnd);
if (hdc == NULL) { MMechostr(1,"---Impossible de créer le context---\n") ;}
// Format de pixel
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 | // Format Must Support Window
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
PFD_DOUBLEBUFFER, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
32, // Select Our Color Depth
0, 0, 0, 0, 0, 0, // Color Bits Ignored
1, // 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
};
pf = ChoosePixelFormat(hdc, &pfd);
if (pf == 0) { MMechostr(1,"---Impossible de choisir le format de pixel----\n") ;}
if (SetPixelFormat(hdc, pf, &pfd) == FALSE) {MMechostr(1,"---Impossible de setter le format de pixel----\n") ;}
hdc = GetDC(hwnd);
HGLRC hglrc = wglCreateContext(hdc);
wglMakeCurrent(hdc, hglrc);
if ( hglrc == NULL ) { MMechostr (1," --------Impossible de définir le redering context-------------\n" ) ;}
MMechostr(1,"--------Création du contexte----------------------\n") ;
// Déclaration du process et vérification multisampling
if (detect.WGLisExtensionSupported("GL_ARB_multisample") == false )
{
arbMultisampleSupported = false ;
MMechostr(1,"---------Le multisampling n'est pas supporté----------------------\n") ;
}
if (detect.WGLisExtensionSupported("GL_ARB_multisample") == true )
{
arbMultisampleSupported = true ;
MMechostr(1,"---------Le multisampling est supporté----------------------\n") ;
}
// Suppression du contexte
if(hglrc)
{
if(wglMakeCurrent(NULL,NULL)==FALSE) MMechostr(1, "------ Can't set the current rendering context to NULL ! ------\n" );
if(wglDeleteContext(hglrc)==FALSE) MMechostr(1, "------ Can't delete the MAIN rendering context ! ------\n" );
else MMechostr(1, "--> mainglrc released : OK\n" );
}
if(hdc)
{
if(ReleaseDC(hwnd, hdc)==0) MMechostr(1, "------ Can't release the MAIN device context ! ------\n" );
else MMechostr(1, "--> mainhdc released : OK\n" );
}
if(hwnd)
{
if(DestroyWindow(hwnd)==0) MMechostr(1, "------ Can't destroy the MAIN window ! ------\n" );
else MMechostr(1, "--> mainhwnd released : OK\n" );
}
hglrc = NULL;
hdc = NULL;
hwnd = NULL;
if(!UnregisterClass("OpenGL", hInstance))
{
MMechostr(1, "----> Could Not Unregister Class !\n");
hInstance=NULL; // Set hInstance To NULL
}
else
MMechostr(1, "--> class scolGL unregistred : OK\n" );
Ensuite, je créer le contexte principal en fonction de l'info renvoyée :
HGLRC CreateMainContext()
{
if (arbMultisampleSupported == false )
{
MMechostr (1,"--------------Le multisampling n'est pas supporté par ta carte--------------\n") ;
HWND hwnd = CreateWindow("scolGL", "scolGL", WS_CHILD, 0, 0, 1, 1, HScol, NULL, NULL, 0);
if ( hwnd == NULL ) { MMechostr(1,"-----Impossible de créer la fenêtre openGL-----\n") ; }
HDC hdc = GetDC(hwnd);
if ( hdc == NULL ) { MMechostr(1,"-------Impossible de créer le handle DC--------\n" ) ; }
// Choix du format de pixel
int pf = 0;
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 | // Format Must Support Window
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
PFD_DOUBLEBUFFER, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
32, // Select Our Color Depth
0, 0, 0, 0, 0, 0, // Color Bits Ignored
1, // 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 (arbMultisampleSupported == true )
{
MMechostr (1,"--------------Le multisampling est supporté par ta carte--------------\n") ;
HWND hwnd = CreateWindow("scolGL", "scolGL", WS_CHILD, 0, 0, 1, 1, HScol, NULL, NULL, 0);
if ( hwnd == NULL ) { MMechostr(1,"-----Impossible de créer la fenêtre openGL-----\n") ; }
HDC hdc = GetDC(hwnd);
if ( hdc == NULL ) { MMechostr(1,"-------Impossible de créer le handle DC--------\n" ) ; }
// Choix du format de pixel
MMechostr(1,"-------Debut du choix de pixel pour le multisampling--------\n" ) ;
int pf = 0;
int valid;
UINT numFormats;
float fAttributes[] = {0,0};
// These Attributes Are The Bits We Want To Test For In Our Sample
// Everything Is Pretty Standard, The Only One We Want To
// Really Focus On Is The SAMPLE BUFFERS ARB And WGL SAMPLES
// These Two Are Going To Do The Main Testing For Whether Or Not
// We Support Multisampling On This Hardware.
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 | // Format Must Support Window
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
PFD_DOUBLEBUFFER, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
32, // Select Our Color Depth
0, 0, 0, 0, 0, 0, // Color Bits Ignored
1, // 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
};
// pfd Tells Windows How We Want Things To Be
// First We Check To See If We Can Get A Pixel Format For 4 Samples
valid = wglChoosePixelFormatARB(hdc,iAttributes,fAttributes,1,&pf,&numFormats);
if (valid && numFormats >= 1){ MMechostr(1," ----Le format de pixel pour le multisampling a bien été choisit!!\n") ;}
DescribePixelFormat(hdc, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
if (SetPixelFormat(hdc, pf, &pfd) ==FALSE) { MMechostr(1," ------Imposible de placer le bon format de pixel-----\n") ;}
Et finalement, j'appelle glEnable(GL_MULTISAMPLE_ARB) à l'initialisation d'OpenGL!
Je me suis inspiré du code NeHe lesson46..
Mon moteur prend bien le bon format de pixel mais le multisampling ne fonctionne pas!!
Si quelqu'un à la moindre idée de ce qui se passe je le remercie d'avance de me répondre au plus vite..
N.B : ma fenêtre openGL de rendu est une fenêtre fille est ce que ça pourrais venir de la?
Bref, je ne sais plus trop quoi faire
Voici une fonction pour tester si une extension est supporter:
(dans ton cas -> "GL_ARB_multisample")
//-----------------------------------------------------------------------------
// Name : CheckExtension(char *extensionName)
// Desc : Check if the extension is supported
//-----------------------------------------------------------------------------
bool CheckExtension(char *extName)
{
//Get the list of supported extensions
char *extList = (char*) glGetString(GL_EXTENSIONS);
//Check if everything's fine...
if(!extName || !extList)
return false;
//Loop throught all extensions
while(*extList){
//find the length of the current extension
UINT ExtLen = strcspn(extList, " ");
//If we've found the extension, return true
if(strlen(extName) == ExtLen && strncmp(extName, extList, ExtLen) == 0)
return true;
//move to the next extension
extList += ExtLen + 1;
}
return false;
}
Et voici le code pour verifier si la version est superieur ou egal a celle donner:
//-----------------------------------------------------------------------------
// Name : CheckVersion(int MajorVerson, int MinorVersion)
// Desc : Check if the version is supported
//-----------------------------------------------------------------------------
bool CheckVersion(int MajorVerson, int MinorVersion)
{
//get the list of supported extensions
char *Ver = (char*) glGetString(GL_VERSION);
//Tell if the given version number is supported
return (Ver[0]-48 > MajorVerson || (Ver[0]-48 == MajorVerson && Ver[2]-48 >= MinorVersion));
}