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

API graphiques Discussion :

shader recuperer les donnees d'un pbo


Sujet :

API graphiques

  1. #1
    Membre éprouvé
    Avatar de NiamorH
    Inscrit en
    Juin 2002
    Messages
    1 309
    Détails du profil
    Informations forums :
    Inscription : Juin 2002
    Messages : 1 309
    Points : 1 051
    Points
    1 051
    Par défaut shader recuperer les donnees d'un pbo
    Salut,

    J'ai donc mis en place un pbo pour mes textures mais je ne sais pas comment récupérer les données de celui ci dans mon fragment shader afin d'appliquer ma texture.

    Voilà le code que j'ai et qui ne fait pas grand chose encore.

    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
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    #include <windows.h> 
    #include <iostream> 
    #include <GL/glew.h> 
    #include <GL/glext.h> 
     
     
    typedef unsigned int uint;
    #define BUFFER_OFFSET(i) ((char*)NULL + (i))
    #define ITERATIONS 1
     
      ///////////////////////////////////////////////////////////////////////
      /////////////////////  Fenetre visualiseur ////////////////////////////
      ///////////////////////////////////////////////////////////////////////
     
      HWND m_visualiseur_hdl;
     
      HDC m_zone_cliente;
     
      HGLRC m_wgl_contexte_rendu;
     
      HINSTANCE m_hinstance;
     
      uint s_largeur_contexte;
      uint s_hauteur_contexte;
     
     
    LRESULT CALLBACK
    visuProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
    {
      switch (message)
      {
        case WM_COMMAND:
    	    return 0;
        case WM_CLOSE:
          PostQuitMessage(0);
    	    return 0;
        case WM_SIZE:
          return DefWindowProc(hwnd, message, wParam, lParam);
        case WM_DESTROY:
          return DefWindowProc(hwnd, message, wParam, lParam);
        default:
          return DefWindowProc(hwnd, message, wParam, lParam);
      }
    }
     
     
    void
    creerFenetre()
    {
      WNDCLASS wc;
     
      // Description de la classe
     
      wc.style = 0 ;
      wc.lpfnWndProc = visuProc;
      wc.cbClsExtra = 0;
      wc.cbWndExtra = 0;
      wc.hInstance = m_hinstance;
      wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
      wc.hCursor = LoadCursor(NULL, IDC_ARROW);
      wc.hbrBackground = (HBRUSH)(1 + COLOR_BTNFACE);
      wc.lpszMenuName =  NULL;
      wc.lpszClassName = "Visualiseur";
     
      if(!RegisterClass(&wc)) return;
     
      m_visualiseur_hdl = CreateWindowA("Visualiseur", "HD Sequence Viewer",
        WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SIZEBOX,
    											0, 0, 1280, 960,
                                                   NULL, NULL, wc.hInstance, NULL);
     
      // on affiche la fenetre
      ShowWindow(m_visualiseur_hdl,SW_SHOW);
     
      // on cree un contexte
    	m_zone_cliente = GetDC(m_visualiseur_hdl);
     
        PIXELFORMATDESCRIPTOR pfd = { 
        sizeof(PIXELFORMATDESCRIPTOR),   // size of this pfd 
        1,                     // version number 
        PFD_DRAW_TO_WINDOW |   // support window 
        PFD_SUPPORT_OPENGL |   // support OpenGL 
        PFD_DOUBLEBUFFER,      // double buffered 
        PFD_TYPE_RGBA,         // RGBA type 
        24,                    // 24-bit 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,            // accum bits ignored 
        0,                    // 32-bit z-buffer 
        0,                     // no stencil buffer 
        0,                     // no auxiliary buffer 
        PFD_MAIN_PLANE,        // main layer 
        0,                     // reserved 
        0, 0, 0                // layer masks ignored 
        };
     
    	int		nPixelFormat;
     
     
      nPixelFormat = ChoosePixelFormat(m_zone_cliente, &pfd);
    	SetPixelFormat(m_zone_cliente, nPixelFormat, &pfd);
     
    	m_wgl_contexte_rendu = wglCreateContext(m_zone_cliente);
    	wglMakeCurrent(m_zone_cliente, m_wgl_contexte_rendu);
     
     
      // on recupere la taille de la zone cliente (donc du contexte)
      RECT r;
      GetClientRect(m_visualiseur_hdl,&r);
     
     
      s_largeur_contexte = r.right - r.left;
      s_hauteur_contexte = r.bottom - r.top;
    }
     
     
     
     
    void
    setupShaders()
    {
      char *vs,*fs;
     
      GLhandleARB v = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
      GLhandleARB f = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);	
     
      vs = 	"void main()\n"
            "{\n"		
            "	gl_Position = ftransform();\n"
            "}\n";
     
      fs = 	"void main()\n"
            "{\n"		
            "	gl_FragColor = vec4(1.,0.,0.,1.0);\n"
            "}\n";
     
      const char * vv = vs;
      const char * ff = fs;
     
      glShaderSourceARB(v, 1, &vv,NULL);
      glShaderSourceARB(f, 1, &ff,NULL);
     
      glCompileShaderARB(v);
      glCompileShaderARB(f);
     
      GLhandleARB p = glCreateProgramObjectARB();
     
      glAttachObjectARB(p,v);
      glAttachObjectARB(p,f);
     
      glLinkProgramARB(p);
      glUseProgramObjectARB(p);
    }
     
     
     
     
      ///////////////////////////////////////////////////////////////////////
      /////////////////////  Main                ////////////////////////////
      ///////////////////////////////////////////////////////////////////////
    int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    { 
        // Set up GLUT and GLEW 
        creerFenetre(); 
        glewInit(); 
    		if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader)
    			printf("Ready for GLSL\n");
    		else {
          MessageBox(0,"Not totally ready :( \n","",0);
    			exit(1);
    		}
    	  if (glewIsSupported("GL_VERSION_2_0"))
    			printf("Ready for OpenGL 2.0\n");
    		else {
    			MessageBox(0,"OpenGL 2.0 not supported\n","",0);
    			exit(1);
    		}
     
     
        //setupShaders();
     
     
     
     
        // Set up the viewport for 1:1 pixel to texel mapping 
        glMatrixMode(GL_PROJECTION); 
        glLoadIdentity(); 
        gluOrtho2D(0, s_largeur_contexte, 0, s_largeur_contexte); 
        glViewport(0, 0, s_largeur_contexte, s_largeur_contexte); 
        glEnable(GL_TEXTURE_RECTANGLE_ARB);
     
     
     
     
        // Create the texture 
        GLuint tex;
        int w = 2048;
        int h = 2048;
        int size = w * h;
        char* texdata = new char[size*4];
        glGenTextures (1, &tex); 
        glBindTexture(GL_TEXTURE_RECTANGLE_ARB, tex); 
        glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
        glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
    //    glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP); 
    //    glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP); 
        glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); 
     
        for (int i = 0 - 1; i < size; ++i)
        {
          texdata[i*4] = (i / (float)(size-1)) * 255;
          texdata[i*4+1] = (i / (float)(size-1)) * 255;
          texdata[i*4+2] = (i / (float)(size-1)) * 255;
          texdata[i*4+3] = (i / (float)(size-1)) * 255;
        }
     
     
      MessageBox(0,"c'est parti","",0);
     
      for (int i = ITERATIONS + 1; i; --i)
      {
          // Create the PBO
          GLuint pbo; 
          glGenBuffers(1, &pbo); 
          glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
          void * pboMemory = 0;
     
          // Reset the contents of the texSize-sized buffer object
          glBufferData(GL_PIXEL_UNPACK_BUFFER_ARB, size, NULL, GL_STREAM_DRAW);
     
          // Map the texture image buffer (the contents of which
          // are undefined due to the previous glBufferData)
          pboMemory = glMapBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY);
     
          // Modify (sub-)buffer data
          memcpy(pboMemory, texdata, size);
     
          // Unmap the texture image buffer
          glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER_ARB);
     
          // Update (sub-)teximage from texture image buffer
          glTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0));
     
     
    	      glBegin(GL_QUADS); 
              glVertex2i( 0 , 0 );
    	        glVertex2i( s_largeur_contexte , 0 );
              glVertex2i( s_largeur_contexte , s_hauteur_contexte);
    	        glVertex2i( 0 , s_hauteur_contexte );
    	      glEnd();
     
            SwapBuffers(wglGetCurrentDC());
     
          // Clean up 
          glDeleteBuffers(1,&pbo); 
      }
      glDeleteTextures(1, &tex); 
     
      MSG msg;
      while(GetMessage(&msg,NULL,0,0)==TRUE)
      {
        TranslateMessage(&msg);
    	DispatchMessage(&msg);
      }
        return 0; 
    }

  2. #2
    Rédacteur
    Avatar de Laurent Gomila
    Profil pro
    Développeur informatique
    Inscrit en
    Avril 2003
    Messages
    10 651
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2003
    Messages : 10 651
    Points : 15 920
    Points
    15 920
    Par défaut
    Y a plein de bons tutoriels, par exemple ici :
    http://www.lighthouse3d.com/opengl/g...ex.php?texture

  3. #3
    Membre éprouvé
    Avatar de NiamorH
    Inscrit en
    Juin 2002
    Messages
    1 309
    Détails du profil
    Informations forums :
    Inscription : Juin 2002
    Messages : 1 309
    Points : 1 051
    Points
    1 051
    Par défaut
    Excuse moi mais je ne comprends pas du tout le principe.

    Comment savoir quel texture unit je dois utiliser ?

    A quoi ça : gl_TextureMatrix sert ?

    J'ai re écrit mes shaders comme ça sans trop savoir vraiment pourquoi car je ne fais aucun lien entre mon pbo et les shaders nul part...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
      vs = 	"void main()\n"
            "{\n"		
            " gl_TexCoord[0] = gl_MultiTexCoord0;\n"
            "	gl_Position = ftransform();\n"
            "}\n";
     
      fs = 	"uniform sampler2D tex;\n"
    	      "void main()\n"
    	      "{\n"
    	      "	vec4 color = texture2D(tex,gl_TexCoord[0].st);\n"
    	      "	gl_FragColor = color;\n"
    	      "}\n";
    J'aimerais un peu d'aide pour comprendre le fonctionnement qui n'est pas clair du tout et malgré ce que tu dis, je ne trouve pas de tutoriaux pour ce que je cherche à faire qui dissipe le flou.

  4. #4
    Rédacteur
    Avatar de Laurent Gomila
    Profil pro
    Développeur informatique
    Inscrit en
    Avril 2003
    Messages
    10 651
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2003
    Messages : 10 651
    Points : 15 920
    Points
    15 920
    Par défaut
    A quoi ça : gl_TextureMatrix sert ?
    A rien dans ton cas, c'est la matrice courante de transformation de coordonnées de textures (comme tu en as une pour la vue et la projection).

    Comment savoir quel texture unit je dois utiliser ?
    Le premier libre, donc si tu ne fais pas de multi-texturing utilise le 0.

    Ton code est bon, il utilise l'unité de texture 0. Il faut donc comme tu le dis faire le lien entre ton shader et l'unité de texture 0.

    Dans ton programme, après avoir envoyé la texture sur l'unité 0 (avec glBindTexture) il suffit de mettre dans la variable "tex" de ton shader la valeur 0, ainsi le texture sampler de ton shader utilisera la texture bindée sur l'unité 0.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    int Location = glGetUniformLocationARB(p, "tex");
    if (Location != -1)
        glUniform1iARB(Location, 0);

  5. #5
    Membre éprouvé
    Avatar de NiamorH
    Inscrit en
    Juin 2002
    Messages
    1 309
    Détails du profil
    Informations forums :
    Inscription : Juin 2002
    Messages : 1 309
    Points : 1 051
    Points
    1 051
    Par défaut
    ok c'est un peu plus clair.

    Donc c'est glBindTexture qui place la texture dans l'unité 0. ok je n'ai lu ça nul part.

    Bon, mais mon code renvoi toujours un ecran noir.

    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
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    #include <windows.h> 
    #include <iostream> 
    #include <GL/glew.h> 
    #include <GL/glext.h> 
     
     
    using namespace std; 
     
    GLhandleARB p;
     
    typedef unsigned int uint;
    typedef unsigned char uchar;
    #define BUFFER_OFFSET(i) ((char*)NULL + (i))
    #define ITERATIONS 1
     
      ///////////////////////////////////////////////////////////////////////
      /////////////////////  Fenetre visualiseur ////////////////////////////
      ///////////////////////////////////////////////////////////////////////
     
      HWND m_visualiseur_hdl;
     
      HDC m_zone_cliente;
     
      HGLRC m_wgl_contexte_rendu;
     
      HINSTANCE m_hinstance;
     
      uint s_largeur_contexte;
      uint s_hauteur_contexte;
     
     
    LRESULT CALLBACK
    visuProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
    {
      switch (message)
      {
        case WM_COMMAND:
    	    return 0;
        case WM_CLOSE:
          PostQuitMessage(0);
    	    return 0;
        case WM_SIZE:
          return DefWindowProc(hwnd, message, wParam, lParam);
        case WM_DESTROY:
          return DefWindowProc(hwnd, message, wParam, lParam);
        default:
          return DefWindowProc(hwnd, message, wParam, lParam);
      }
    }
     
     
    void
    creerFenetre()
    {
      WNDCLASS wc;
     
      // Description de la classe
     
      wc.style = 0 ;
      wc.lpfnWndProc = visuProc;
      wc.cbClsExtra = 0;
      wc.cbWndExtra = 0;
      wc.hInstance = m_hinstance;
      wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
      wc.hCursor = LoadCursor(NULL, IDC_ARROW);
      wc.hbrBackground = (HBRUSH)(1 + COLOR_BTNFACE);
      wc.lpszMenuName =  NULL;
      wc.lpszClassName = "Visualiseur";
     
      if(!RegisterClass(&wc)) return;
     
      m_visualiseur_hdl = CreateWindowA("Visualiseur", "HD Sequence Viewer",
        WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SIZEBOX,
    											0, 0, 1280, 960,
                                                   NULL, NULL, wc.hInstance, NULL);
     
      // on affiche la fenetre
      ShowWindow(m_visualiseur_hdl,SW_SHOW);
     
      // on cree un contexte
    	m_zone_cliente = GetDC(m_visualiseur_hdl);
     
        PIXELFORMATDESCRIPTOR pfd = { 
        sizeof(PIXELFORMATDESCRIPTOR),   // size of this pfd 
        1,                     // version number 
        PFD_DRAW_TO_WINDOW |   // support window 
        PFD_SUPPORT_OPENGL |   // support OpenGL 
        PFD_DOUBLEBUFFER,      // double buffered 
        PFD_TYPE_RGBA,         // RGBA type 
        24,                    // 24-bit color depth 
        0, 0, 0, 0, 0, 0,      // color bits ignored 
        1,                     // no alpha buffer 
        0,                     // shift bit ignored 
        0,                     // no accumulation buffer 
        0, 0, 0, 0,            // accum bits ignored 
        0,                    // 32-bit z-buffer 
        0,                     // no stencil buffer 
        0,                     // no auxiliary buffer 
        PFD_MAIN_PLANE,        // main layer 
        0,                     // reserved 
        0, 0, 0                // layer masks ignored 
        };
     
    	int		nPixelFormat;
     
     
      nPixelFormat = ChoosePixelFormat(m_zone_cliente, &pfd);
    	SetPixelFormat(m_zone_cliente, nPixelFormat, &pfd);
     
    	m_wgl_contexte_rendu = wglCreateContext(m_zone_cliente);
    	wglMakeCurrent(m_zone_cliente, m_wgl_contexte_rendu);
     
     
      // on recupere la taille de la zone cliente (donc du contexte)
      RECT r;
      GetClientRect(m_visualiseur_hdl,&r);
     
     
      s_largeur_contexte = r.right - r.left;
      s_hauteur_contexte = r.bottom - r.top;
    }
     
     
     
     
    void
    setupShaders()
    {
      char *vs,*fs;
     
      GLhandleARB v = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
      GLhandleARB f = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);	
     
      vs = 	"void main()\n"
            "{\n"		
            " gl_TexCoord[0] = gl_MultiTexCoord0;\n"
            "	gl_Position = ftransform();\n"
            "}\n";
     
      fs = 	"uniform sampler2D tex;\n"
    	      "void main()\n"
    	      "{\n"
    	      "	vec4 color = texture2D(tex,gl_TexCoord[0].st);\n"
            "	gl_FragColor = color;\n"
    	      "}\n";
     
      /*"void main()\n"
            "{\n"		
            "	gl_FragColor = vec4(1.,0.,0.,1.0);\n"
            "}\n";*/
     
      const char * vv = vs;
      const char * ff = fs;
     
      glShaderSourceARB(v, 1, &vv,NULL);
      glShaderSourceARB(f, 1, &ff,NULL);
     
      glCompileShaderARB(v);
      glCompileShaderARB(f);
     
      p = glCreateProgramObjectARB();
     
      glAttachObjectARB(p,v);
      glAttachObjectARB(p,f);
     
      glLinkProgramARB(p);
      glUseProgramObjectARB(p);
    }
     
     
     
     
      ///////////////////////////////////////////////////////////////////////
      /////////////////////  Main                ////////////////////////////
      ///////////////////////////////////////////////////////////////////////
    int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    { 
        // Set up GLUT and GLEW 
        creerFenetre(); 
        glewInit(); 
    		if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader)
    			printf("Ready for GLSL\n");
    		else {
          MessageBox(0,"Not totally ready :( \n","",0);
    			exit(1);
    		}
    	  if (glewIsSupported("GL_VERSION_2_0"))
    			printf("Ready for OpenGL 2.0\n");
    		else {
    			MessageBox(0,"OpenGL 2.0 not supported\n","",0);
    			exit(1);
    		}
     
     
     
     
     
     
        // Set up the viewport for 1:1 pixel to texel mapping 
        glMatrixMode(GL_PROJECTION); 
        glLoadIdentity(); 
        gluOrtho2D(0, s_largeur_contexte, 0, s_largeur_contexte); 
        glViewport(0, 0, s_largeur_contexte, s_largeur_contexte); 
        glEnable(GL_TEXTURE_RECTANGLE_ARB);
     
     
     
     
        // Create the texture 
        GLuint tex;
        int w = 2048;
        int h = 2048;
        int size = w * h;
        uchar* texdata = new uchar[size*4];
        glGenTextures (1, &tex); 
        glBindTexture(GL_TEXTURE_RECTANGLE_ARB, tex); 
        glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
        glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
    //    glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP); 
    //    glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP); 
        glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); 
     
     
        setupShaders();
        int Location = glGetUniformLocationARB(p, "tex");
        if (Location != -1)
          glUniform1iARB(Location, 0);
     
     
     
        for (int i = 0 - 1; i < size; ++i)
        {
          texdata[i*4] = 255;//(i / (float)(size-1)) * 255;
          texdata[i*4+1] = (i / (float)(size-1)) * 255;
          texdata[i*4+2] = (i / (float)(size-1)) * 255;
          texdata[i*4+3] = (i / (float)(size-1)) * 255;
        }
     
     
     
     
      MessageBox(0,"c'est parti","",0);
     
      for (int i = ITERATIONS + 1; i; --i)
      {
          // Create the PBO
          GLuint pbo; 
          glGenBuffers(1, &pbo); 
          glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
          void * pboMemory = 0;
     
          // Reset the contents of the texSize-sized buffer object
          glBufferData(GL_PIXEL_UNPACK_BUFFER_ARB, size, NULL, GL_STREAM_DRAW);
     
          // Map the texture image buffer (the contents of which
          // are undefined due to the previous glBufferData)
          pboMemory = glMapBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY);
     
          // Modify (sub-)buffer data
          memcpy(pboMemory, texdata, size);
     
          // Unmap the texture image buffer
          glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER_ARB);
     
          // Update (sub-)teximage from texture image buffer
          glTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0));
     
     
    	      glBegin(GL_QUADS);
     
    	        glTexCoord2d(0.,0.);   glVertex2i( 0 , 0 );
    	        glTexCoord2d(1./(double)w,0);   glVertex2i( s_largeur_contexte , 0 );
    	        glTexCoord2d(1./(double)w,1./(double)h);   glVertex2i( s_largeur_contexte , s_hauteur_contexte);
    	        glTexCoord2d(0.,1./(double)h);   glVertex2i( 0 , s_hauteur_contexte );
     
    	      glEnd();
     
            SwapBuffers(wglGetCurrentDC());
     
          // Clean up 
          glDeleteBuffers(1,&pbo); 
      }
      glDeleteTextures(1, &tex); 
     
      MSG msg;
      while(GetMessage(&msg,NULL,0,0)==TRUE)
      {
        TranslateMessage(&msg);
    	DispatchMessage(&msg);
      }
        return 0; 
    }

  6. #6
    Rédacteur
    Avatar de Laurent Gomila
    Profil pro
    Développeur informatique
    Inscrit en
    Avril 2003
    Messages
    10 651
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2003
    Messages : 10 651
    Points : 15 920
    Points
    15 920
    Par défaut
    Est-ce que déjà sans shaders ça fonctionne ?

  7. #7
    Membre éprouvé
    Avatar de NiamorH
    Inscrit en
    Juin 2002
    Messages
    1 309
    Détails du profil
    Informations forums :
    Inscription : Juin 2002
    Messages : 1 309
    Points : 1 051
    Points
    1 051
    Par défaut
    Voilà le code qui fonctionne sans les pbos
    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
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    #include <windows.h> 
    #include <iostream> 
    #include <GL/glew.h> 
    #include <GL/glext.h> 
     
     
    using namespace std; 
     
    GLhandleARB p;
     
    typedef unsigned int uint;
    typedef unsigned char uchar;
    #define BUFFER_OFFSET(i) ((char*)NULL + (i))
    #define ITERATIONS 1
     
      ///////////////////////////////////////////////////////////////////////
      /////////////////////  Fenetre visualiseur ////////////////////////////
      ///////////////////////////////////////////////////////////////////////
     
      HWND m_visualiseur_hdl;
     
      HDC m_zone_cliente;
     
      HGLRC m_wgl_contexte_rendu;
     
      HINSTANCE m_hinstance;
     
      uint s_largeur_contexte;
      uint s_hauteur_contexte;
     
     
    LRESULT CALLBACK
    visuProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
    {
      switch (message)
      {
        case WM_COMMAND:
    	    return 0;
        case WM_CLOSE:
          PostQuitMessage(0);
    	    return 0;
        case WM_SIZE:
          return DefWindowProc(hwnd, message, wParam, lParam);
        case WM_DESTROY:
          return DefWindowProc(hwnd, message, wParam, lParam);
        default:
          return DefWindowProc(hwnd, message, wParam, lParam);
      }
    }
     
     
    void
    creerFenetre()
    {
      WNDCLASS wc;
     
      // Description de la classe
     
      wc.style = 0 ;
      wc.lpfnWndProc = visuProc;
      wc.cbClsExtra = 0;
      wc.cbWndExtra = 0;
      wc.hInstance = m_hinstance;
      wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
      wc.hCursor = LoadCursor(NULL, IDC_ARROW);
      wc.hbrBackground = (HBRUSH)(1 + COLOR_BTNFACE);
      wc.lpszMenuName =  NULL;
      wc.lpszClassName = "Visualiseur";
     
      if(!RegisterClass(&wc)) return;
     
      m_visualiseur_hdl = CreateWindowA("Visualiseur", "HD Sequence Viewer",
        WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SIZEBOX,
    											0, 0, 1280, 960,
                                                   NULL, NULL, wc.hInstance, NULL);
     
      // on affiche la fenetre
      ShowWindow(m_visualiseur_hdl,SW_SHOW);
     
      // on cree un contexte
    	m_zone_cliente = GetDC(m_visualiseur_hdl);
     
        PIXELFORMATDESCRIPTOR pfd = { 
        sizeof(PIXELFORMATDESCRIPTOR),   // size of this pfd 
        1,                     // version number 
        PFD_DRAW_TO_WINDOW |   // support window 
        PFD_SUPPORT_OPENGL |   // support OpenGL 
        PFD_DOUBLEBUFFER,      // double buffered 
        PFD_TYPE_RGBA,         // RGBA type 
        24,                    // 24-bit 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,            // accum bits ignored 
        0,                    // 32-bit z-buffer 
        0,                     // no stencil buffer 
        0,                     // no auxiliary buffer 
        PFD_MAIN_PLANE,        // main layer 
        0,                     // reserved 
        0, 0, 0                // layer masks ignored 
        };
     
    	int		nPixelFormat;
     
     
      nPixelFormat = ChoosePixelFormat(m_zone_cliente, &pfd);
    	SetPixelFormat(m_zone_cliente, nPixelFormat, &pfd);
     
    	m_wgl_contexte_rendu = wglCreateContext(m_zone_cliente);
    	wglMakeCurrent(m_zone_cliente, m_wgl_contexte_rendu);
     
     
      // on recupere la taille de la zone cliente (donc du contexte)
      RECT r;
      GetClientRect(m_visualiseur_hdl,&r);
     
     
      s_largeur_contexte = r.right - r.left;
      s_hauteur_contexte = r.bottom - r.top;
    }
     
     
     
     
    void
    setupShaders()
    {
      char *vs,*fs;
     
      GLhandleARB v = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
      GLhandleARB f = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);	
     
      vs = 	"void main()\n"
            "{\n"		
            " gl_TexCoord[0] = gl_MultiTexCoord0;\n"
            "	gl_Position = ftransform();\n"
            "}\n";
     
      fs = 	"uniform sampler2D tex;\n"
    	      "void main()\n"
    	      "{\n"
    	      "	vec4 color = texture2D(tex,gl_TexCoord[0].st);\n"
            "	gl_FragColor = color;\n"
    	      "}\n";
     
     
     
      const char * vv = vs;
      const char * ff = fs;
     
      glShaderSourceARB(v, 1, &vv,NULL);
      glShaderSourceARB(f, 1, &ff,NULL);
     
      glCompileShaderARB(v);
      glCompileShaderARB(f);
     
      p = glCreateProgramObjectARB();
     
      glAttachObjectARB(p,v);
      glAttachObjectARB(p,f);
     
      glLinkProgramARB(p);
      glUseProgramObjectARB(p);
    }
     
     
     
     
      ///////////////////////////////////////////////////////////////////////
      /////////////////////  Main                ////////////////////////////
      ///////////////////////////////////////////////////////////////////////
    int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    { 
        // Set up GLUT and GLEW 
        creerFenetre(); 
        glewInit(); 
    		if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader)
    			printf("Ready for GLSL\n");
    		else {
          MessageBox(0,"Not totally ready :( \n","",0);
    			exit(1);
    		}
    	  if (glewIsSupported("GL_VERSION_2_0"))
    			printf("Ready for OpenGL 2.0\n");
    		else {
    			MessageBox(0,"OpenGL 2.0 not supported\n","",0);
    			exit(1);
    		}
     
     
     
     
     
     
        // Set up the viewport for 1:1 pixel to texel mapping 
        glMatrixMode(GL_PROJECTION); 
        glLoadIdentity(); 
        gluOrtho2D(0, s_largeur_contexte, 0, s_largeur_contexte); 
        glViewport(0, 0, s_largeur_contexte, s_largeur_contexte); 
        glEnable(GL_TEXTURE_RECTANGLE_ARB);
     
     
     
     
        // Create the texture 
        GLuint tex;
        int w = 2048;
        int h = 2048;
        int size = w * h;
        uchar* texdata = new uchar[size*4];
        glGenTextures (1, &tex); 
        glBindTexture(GL_TEXTURE_RECTANGLE_ARB, tex); 
        glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
        glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
    //    glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP); 
    //    glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP); 
     
     
     
     
        for (int i = 0; i < w; ++i)
        {
          for (int j = 0; j < h; ++j)
          {
     
            texdata[(((j*w)+i)*4)] = (255 /(float)w )*i;
            texdata[(((j*w)+i)*4)+1] = (255 /(float)h )*j;
            texdata[(((j*w)+i)*4)+2] = (i/(float)w)*255;
            texdata[(((j*w)+i)*4)+3] = 255;
          }
        }
     
        glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, texdata); 
     
     
     
     
      MessageBox(0,"c'est parti","",0);
     
      for (int i = ITERATIONS ; i; --i)
      {
     
     
    	      glBegin(GL_QUADS);
     
    	        glTexCoord2i(0,0);   glVertex2i( 0 , 0 );
    	        glTexCoord2i(w,0);   glVertex2i( s_largeur_contexte , 0 );
    	        glTexCoord2i(w,h);   glVertex2i( s_largeur_contexte , s_hauteur_contexte);
    	        glTexCoord2i(0,h);   glVertex2i( 0 , s_hauteur_contexte );
     
    	      glEnd();
     
            SwapBuffers(wglGetCurrentDC());
     
      }
     
      MSG msg;
      while(GetMessage(&msg,NULL,0,0)==TRUE)
      {
        TranslateMessage(&msg);
    	DispatchMessage(&msg);
      }
        return 0; 
    }

    Et celui avec les pbos qui laisse l'ecran noir

    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
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    #include <windows.h> 
    #include <iostream> 
    #include <GL/glew.h> 
    #include <GL/glext.h> 
     
     
    using namespace std; 
     
    GLhandleARB p;
     
    typedef unsigned int uint;
    typedef unsigned char uchar;
    #define BUFFER_OFFSET(i) ((char*)NULL + (i))
    #define ITERATIONS 1
     
      ///////////////////////////////////////////////////////////////////////
      /////////////////////  Fenetre visualiseur ////////////////////////////
      ///////////////////////////////////////////////////////////////////////
     
      HWND m_visualiseur_hdl;
     
      HDC m_zone_cliente;
     
      HGLRC m_wgl_contexte_rendu;
     
      HINSTANCE m_hinstance;
     
      uint s_largeur_contexte;
      uint s_hauteur_contexte;
     
     
    LRESULT CALLBACK
    visuProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
    {
      switch (message)
      {
        case WM_COMMAND:
    	    return 0;
        case WM_CLOSE:
          PostQuitMessage(0);
    	    return 0;
        case WM_SIZE:
          return DefWindowProc(hwnd, message, wParam, lParam);
        case WM_DESTROY:
          return DefWindowProc(hwnd, message, wParam, lParam);
        default:
          return DefWindowProc(hwnd, message, wParam, lParam);
      }
    }
     
     
    void
    creerFenetre()
    {
      WNDCLASS wc;
     
      // Description de la classe
     
      wc.style = 0 ;
      wc.lpfnWndProc = visuProc;
      wc.cbClsExtra = 0;
      wc.cbWndExtra = 0;
      wc.hInstance = m_hinstance;
      wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
      wc.hCursor = LoadCursor(NULL, IDC_ARROW);
      wc.hbrBackground = (HBRUSH)(1 + COLOR_BTNFACE);
      wc.lpszMenuName =  NULL;
      wc.lpszClassName = "Visualiseur";
     
      if(!RegisterClass(&wc)) return;
     
      m_visualiseur_hdl = CreateWindowA("Visualiseur", "HD Sequence Viewer",
        WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SIZEBOX,
    											0, 0, 1280, 960,
                                                   NULL, NULL, wc.hInstance, NULL);
     
      // on affiche la fenetre
      ShowWindow(m_visualiseur_hdl,SW_SHOW);
     
      // on cree un contexte
    	m_zone_cliente = GetDC(m_visualiseur_hdl);
     
        PIXELFORMATDESCRIPTOR pfd = { 
        sizeof(PIXELFORMATDESCRIPTOR),   // size of this pfd 
        1,                     // version number 
        PFD_DRAW_TO_WINDOW |   // support window 
        PFD_SUPPORT_OPENGL |   // support OpenGL 
        PFD_DOUBLEBUFFER,      // double buffered 
        PFD_TYPE_RGBA,         // RGBA type 
        24,                    // 24-bit 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,            // accum bits ignored 
        0,                    // 32-bit z-buffer 
        0,                     // no stencil buffer 
        0,                     // no auxiliary buffer 
        PFD_MAIN_PLANE,        // main layer 
        0,                     // reserved 
        0, 0, 0                // layer masks ignored 
        };
     
    	int		nPixelFormat;
     
     
      nPixelFormat = ChoosePixelFormat(m_zone_cliente, &pfd);
    	SetPixelFormat(m_zone_cliente, nPixelFormat, &pfd);
     
    	m_wgl_contexte_rendu = wglCreateContext(m_zone_cliente);
    	wglMakeCurrent(m_zone_cliente, m_wgl_contexte_rendu);
     
     
      // on recupere la taille de la zone cliente (donc du contexte)
      RECT r;
      GetClientRect(m_visualiseur_hdl,&r);
     
     
      s_largeur_contexte = r.right - r.left;
      s_hauteur_contexte = r.bottom - r.top;
    }
     
     
     
     
    void
    setupShaders()
    {
      char *vs,*fs;
     
      GLhandleARB v = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
      GLhandleARB f = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);	
     
      vs = 	"void main()\n"
            "{\n"		
            " gl_TexCoord[0] = gl_MultiTexCoord0;\n"
            "	gl_Position = ftransform();\n"
            "}\n";
     
      fs = 	"uniform sampler2D tex;\n"
    	      "void main()\n"
    	      "{\n"
    	      "	vec4 color = texture2D(tex,gl_TexCoord[0].st);\n"
            "	gl_FragColor = color;\n"
    	      "}\n";
     
      //"void main()\n"
      //      "{\n"		
      //      "	gl_FragColor = vec4(1.,0.,0.,1.0);\n"
      //      "}\n";
     
      const char * vv = vs;
      const char * ff = fs;
     
      glShaderSourceARB(v, 1, &vv,NULL);
      glShaderSourceARB(f, 1, &ff,NULL);
     
      glCompileShaderARB(v);
      glCompileShaderARB(f);
     
      p = glCreateProgramObjectARB();
     
      glAttachObjectARB(p,v);
      glAttachObjectARB(p,f);
     
      glLinkProgramARB(p);
      glUseProgramObjectARB(p);
    }
     
     
     
     
      ///////////////////////////////////////////////////////////////////////
      /////////////////////  Main                ////////////////////////////
      ///////////////////////////////////////////////////////////////////////
    int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    { 
        // Set up GLUT and GLEW 
        creerFenetre(); 
        glewInit(); 
    		if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader)
    			printf("Ready for GLSL\n");
    		else {
          MessageBox(0,"Not totally ready :( \n","",0);
    			exit(1);
    		}
    	  if (glewIsSupported("GL_VERSION_2_0"))
    			printf("Ready for OpenGL 2.0\n");
    		else {
    			MessageBox(0,"OpenGL 2.0 not supported\n","",0);
    			exit(1);
    		}
     
     
     
     
     
     
        // Set up the viewport for 1:1 pixel to texel mapping 
        glMatrixMode(GL_PROJECTION); 
        glLoadIdentity(); 
        gluOrtho2D(0, s_largeur_contexte, 0, s_largeur_contexte); 
        glViewport(0, 0, s_largeur_contexte, s_largeur_contexte); 
        glEnable(GL_TEXTURE_RECTANGLE_ARB);
     
     
     
     
        // Create the texture 
        GLuint tex;
        int w = 2048;
        int h = 2048;
        int size = w * h;
        uchar* texdata = new uchar[size*4];
        glGenTextures (1, &tex); 
        glBindTexture(GL_TEXTURE_RECTANGLE_ARB, tex); 
        glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
        glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
    //    glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP); 
    //    glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP); 
        glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); 
     
     
        setupShaders();
        int Location = glGetUniformLocationARB(p, "tex");
        if (Location != -1)
          glUniform1iARB(Location, 0);
     
     
     
        for (int i = 0; i < w; ++i)
        {
          for (int j = 0; j < h; ++j)
          {
     
            texdata[(((j*w)+i)*4)] = (255 /(float)w )*i;
            texdata[(((j*w)+i)*4)+1] = (255 /(float)h )*j;
            texdata[(((j*w)+i)*4)+2] = (i/(float)w)*255;
            texdata[(((j*w)+i)*4)+3] = 255;
          }
        }
     
     
     
     
      MessageBox(0,"c'est parti","",0);
     
      for (int i = ITERATIONS; i; --i)
      {
          // Create the PBO
          GLuint pbo; 
          glGenBuffers(1, &pbo); 
          glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
          void * pboMemory = 0;
     
          // Reset the contents of the texSize-sized buffer object
          glBufferData(GL_PIXEL_UNPACK_BUFFER_ARB, size*4, NULL, GL_STREAM_DRAW);
     
          // Map the texture image buffer (the contents of which
          // are undefined due to the previous glBufferData)
          pboMemory = glMapBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY);
     
          // Modify (sub-)buffer data
          memcpy(pboMemory, texdata, size*4);
     
          // Unmap the texture image buffer
          glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER_ARB);
     
          // Update (sub-)teximage from texture image buffer
          glTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0));
     
     
    	      glBegin(GL_QUADS);
     
    	        glTexCoord2i(0,0);   glVertex2i( 0 , 0 );
    	        glTexCoord2i(w,0);   glVertex2i( s_largeur_contexte , 0 );
    	        glTexCoord2i(w,h);   glVertex2i( s_largeur_contexte , s_hauteur_contexte);
    	        glTexCoord2i(0,h);   glVertex2i( 0 , s_hauteur_contexte );
     
    	      glEnd();
     
            SwapBuffers(wglGetCurrentDC());
     
          // Clean up 
          glDeleteBuffers(1,&pbo); 
      }
      glDeleteTextures(1, &tex); 
     
      MSG msg;
      while(GetMessage(&msg,NULL,0,0)==TRUE)
      {
        TranslateMessage(&msg);
    	DispatchMessage(&msg);
      }
        return 0; 
    }

  8. #8
    Membre éprouvé
    Avatar de NiamorH
    Inscrit en
    Juin 2002
    Messages
    1 309
    Détails du profil
    Informations forums :
    Inscription : Juin 2002
    Messages : 1 309
    Points : 1 051
    Points
    1 051
    Par défaut
    est ce que ça ne viendrait pas de ce truc là BUFFER_OFFSET(0) je trouve ça bizare, je l'ai récupéré sur internet comme tel

    #define BUFFER_OFFSET(i) ((char*)NULL + (i))

    Je l'utilise lors de glTexSubImage2D

  9. #9
    Rédacteur
    Avatar de Laurent Gomila
    Profil pro
    Développeur informatique
    Inscrit en
    Avril 2003
    Messages
    10 651
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2003
    Messages : 10 651
    Points : 15 920
    Points
    15 920
    Par défaut
    Non, passer un pointeur nul au lieu d'un pointeur sur des pixels signifie juste qu'il faut aller chercher ces derniers dans le PBO actif plutôt que directement en mémoire, ce qui est bien ce que tu veux.
    Note que tu n'es pas obligé d'utiliser BUFFER_OFFSET(0) dans ce cas là, il suffit de passer NULL.

    Bon si j'ai bien compris ce sont les PBOs qui ne fonctionnent pas, pas les shaders.

  10. #10
    Membre éprouvé
    Avatar de NiamorH
    Inscrit en
    Juin 2002
    Messages
    1 309
    Détails du profil
    Informations forums :
    Inscription : Juin 2002
    Messages : 1 309
    Points : 1 051
    Points
    1 051
    Par défaut
    Et bien oui je pense car si je rajoute à mon shader fragment :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
      fs = 	"uniform sampler2D tex;\n"
    	      "void main()\n"
    	      "{\n"
    	      "	vec4 color = texture2D(tex,gl_TexCoord[0].st);\n"
    	      "	gl_FragColor = color + vec4(1.,0.,0.,1.0);\n"
    	      "}\n";
    J'ai bien un écran rouge. Donc les couleurs contenues là dedans texture2D(tex,gl_TexCoord[0].st); sont mal renseignées.

  11. #11
    Rédacteur
    Avatar de Laurent Gomila
    Profil pro
    Développeur informatique
    Inscrit en
    Avril 2003
    Messages
    10 651
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2003
    Messages : 10 651
    Points : 15 920
    Points
    15 920
    Par défaut
    Ce que je voulais dire c'est que le lien shader-texture fonctionne bien. C'est l'utilisation du PBO qui pose problème, peu importe qu'il y ait un shader après ou pas.

  12. #12
    Membre éprouvé
    Avatar de NiamorH
    Inscrit en
    Juin 2002
    Messages
    1 309
    Détails du profil
    Informations forums :
    Inscription : Juin 2002
    Messages : 1 309
    Points : 1 051
    Points
    1 051
    Par défaut
    Est ce que j'ai oublié qqc ?

    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
          // Create the PBO
          GLuint pbo; 
          glGenBuffers(1, &pbo); 
          glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
          void * pboMemory = 0;
     
          // Reset the contents of the texSize-sized buffer object
          glBufferData(GL_PIXEL_UNPACK_BUFFER_ARB, size*4, NULL, GL_STREAM_DRAW);
     
          // Map the texture image buffer (the contents of which
          // are undefined due to the previous glBufferData)
          pboMemory = glMapBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY);
     
          // Modify (sub-)buffer data
          memcpy(pboMemory, texdata, size*4);
     
          // Unmap the texture image buffer
          glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER_ARB);
     
          // Update (sub-)teximage from texture image buffer
          glTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0));
     
          glBegin(GL_QUADS);
     
            glTexCoord2i(0,0);   glVertex2i( 0 , 0 );
            glTexCoord2i(w,0);   glVertex2i( s_largeur_contexte , 0 );
            glTexCoord2i(w,h);   glVertex2i( s_largeur_contexte , s_hauteur_contexte);
            glTexCoord2i(0,h);   glVertex2i( 0 , s_hauteur_contexte );
     
          glEnd();
     
          SwapBuffers(wglGetCurrentDC());
    Ou alors veux-tu dire que c'est ma carte graphique qui supporte pas les pbos ?

  13. #13
    Membre éprouvé
    Avatar de NiamorH
    Inscrit en
    Juin 2002
    Messages
    1 309
    Détails du profil
    Informations forums :
    Inscription : Juin 2002
    Messages : 1 309
    Points : 1 051
    Points
    1 051
    Par défaut
    Bon, j'ai mis ça pour verifier si l'extension etait gérée, a priori oui.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    // Récupération de la liste des extensions
    std::string Extensions = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS));
     
    // Recherche de l'extension qui nous intéresse : GL_ARB_texture_compression
    if (Extensions.find("GL_ARB_pixel_buffer_object") != std::string::npos)
    {
        // Extension trouvée : la fonctionnalité est supportée
    }
    else
    {
      MessageBox(0,"perdu","",0);
        // Extension non trouvée : la fonctionnalité ne pourra pas être utilisée
    }
    S'il vous plait, je suis vraiment coincé sans ça...
    Qu'est ce qui ne va pas dans mon code ?

  14. #14
    Membre éprouvé
    Avatar de NiamorH
    Inscrit en
    Juin 2002
    Messages
    1 309
    Détails du profil
    Informations forums :
    Inscription : Juin 2002
    Messages : 1 309
    Points : 1 051
    Points
    1 051
    Par défaut
    Ne m'abandonne pas

    Peut-être pourrais tu me montrer un example complet qui marche pour toi, que je testerais et que je modifierais pour voir là ou ça coince ?

    J'ai besoin d'aide, je commence à peter un cable de ne pas pouvoir avancer.

  15. #15
    Membre éprouvé
    Avatar de NiamorH
    Inscrit en
    Juin 2002
    Messages
    1 309
    Détails du profil
    Informations forums :
    Inscription : Juin 2002
    Messages : 1 309
    Points : 1 051
    Points
    1 051
    Par défaut
    Ca y est j'ai finalement trouvé la solution par hazard.

    Ce qui n'allait pas c'etait le fragment shader :

    fs = "uniform sampler2DRect tex;\n"
    "void main()\n"
    "{\n"
    " vec4 color = texture2DRect(tex,gl_TexCoord[0].st);\n"
    " gl_FragColor = color;\n"
    "}\n";

    Merci à toi pour m'avoir donné les pistes qui me manquaient.

  16. #16
    Rédacteur
    Avatar de Laurent Gomila
    Profil pro
    Développeur informatique
    Inscrit en
    Avril 2003
    Messages
    10 651
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2003
    Messages : 10 651
    Points : 15 920
    Points
    15 920
    Par défaut
    Ah zut. En plus j'ai pensé aux éventuelles incompatibilités entre textures 2D et RECT, mais j'ai oublié d'en parler

    Par contre si ça vient du shader, je ne comprends pas pourquoi tu avais un code qui fonctionnait sans les PBOs...

  17. #17
    Membre éprouvé
    Avatar de NiamorH
    Inscrit en
    Juin 2002
    Messages
    1 309
    Détails du profil
    Informations forums :
    Inscription : Juin 2002
    Messages : 1 309
    Points : 1 051
    Points
    1 051
    Par défaut
    Parce que le "test sans les pbos" était également un "test sans les shaders"

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [JTable] recuperer les donnees
    Par clemouf dans le forum Composants
    Réponses: 3
    Dernier message: 08/02/2019, 16h44
  2. Réponses: 5
    Dernier message: 06/07/2010, 16h16
  3. Recuperer Les Donnees D'une Table
    Par brute dans le forum Oracle
    Réponses: 9
    Dernier message: 12/05/2006, 13h01
  4. [VB6]recuperer les donnees telephones sur un serveur
    Par Bouassa dans le forum VB 6 et antérieur
    Réponses: 3
    Dernier message: 15/03/2006, 11h02
  5. [Applets] Recuperer les donnees
    Par calypso dans le forum Applets
    Réponses: 11
    Dernier message: 05/04/2005, 17h18

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