Bonjour à tous,

Je cherche à afficher une texture vidéo sur un carré OpenGL. Je veux utiliser libvlc pour lire un maximum de formats.
J'ai trouvé ce tuto pour lire une vidéo sur un SDL_Surface : http://wiki.videolan.org/LibVLC_SampleCode_SDL
Ce dernier fonctionne plutôt bien.

Maintenant j'essaie juste d'intégrer un Quad OpenGL là-dedans et d'utiliser la vidéo comme texture mais le seul résultat que j'obtiens est un carré blanc sur fond noir. :/

Voici mon code :
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
#include <stdio.h>
#include <stdint.h>
#include <math.h>
#include <stdlib.h>
 
#include <SDL/SDL.h>
#include <SDL/SDL_mutex.h>
#include <GL/glu.h>
 
#include <vlc/vlc.h>
 
#define WIDTH 640
#define HEIGHT 480
#define VIDEO_FILE "/home/user/path/movie.avi"
 
 
struct ctx {
	SDL_Surface *surf;
	SDL_mutex *mutex;
};
 
static void catchEx (libvlc_exception_t *ex) {
	if(libvlc_exception_raised(ex)) {
		fprintf(stderr, "Exception libvlc : %s\n", libvlc_exception_get_message(ex));
		exit(EXIT_FAILURE);
	}
	libvlc_exception_clear(ex);
}
 
static void lock(struct ctx *ctx, void **pp_ret) {
	SDL_LockMutex(ctx->mutex);
	SDL_LockSurface(ctx->surf);
	*pp_ret = ctx->surf->pixels;
}
 
static void unlock(struct ctx *ctx) {
	SDL_UnlockSurface(ctx->surf);
	SDL_UnlockMutex(ctx->mutex);
}
 
 
 
int main(int argc, char *argv[])
{
    char clock[64], cunlock[64], cdata[64];
    char width[32], height[32], pitch[32];
    libvlc_exception_t ex;
    libvlc_instance_t *libvlc;
    libvlc_media_t *m;
    libvlc_media_player_t *mp;
    char const *vlc_argv[] =
    {
        "--quiet",					/* Ne rien afficher */
        "--ignore-config",			/* Pas d'utilisation des fichiers de configuration de VLC */
        "--no-osd",					/* Pas d'affichage par dessus la vidéo */
        "--noaudio",				/* Pas de son */
        "--vout", "vmem",
        "--vmem-width", width,
        "--vmem-height", height,
        "--vmem-pitch", pitch,
        "--vmem-chroma", "RV16",
        "--vmem-lock", clock,
        "--vmem-unlock", cunlock,
        "--vmem-data", cdata
    };
    int vlc_argc = sizeof(vlc_argv) / sizeof(*vlc_argv);
 
    SDL_Surface *screen;
    SDL_Event event;
    int done = 0, action = 0;
 
    struct ctx ctx;
 
    /*
     *  Initialise libSDL
     */
    if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTTHREAD) == -1)
    {
        printf("cannot initialize SDL\n");
        return EXIT_FAILURE;
    }
 
    ctx.surf = SDL_CreateRGBSurface(SDL_SWSURFACE, WIDTH, HEIGHT, 16, 0xf800, 0x07e0, 0x001f, 0);
 
    ctx.mutex = SDL_CreateMutex();
 
    int options = SDL_ANYFORMAT | SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_OPENGL;
 
    screen = SDL_SetVideoMode(1280, 800, 0, options);
    if(!screen)
    {
        printf("cannot set video mode\n");
        return EXIT_FAILURE;
    }
 
 
 
    /* Récupérer un numéro pour une texture */
    GLuint image;
    glGenTextures(1, &image);
 
 
 
 
    /*
     *  Initialise libVLC
     */
    sprintf(clock, "%lld", (long long int)(intptr_t)lock);
    sprintf(cunlock, "%lld", (long long int)(intptr_t)unlock);
    sprintf(cdata, "%lld", (long long int)(intptr_t)&ctx);
    sprintf(width, "%i", WIDTH);
    sprintf(height, "%i", HEIGHT);
    sprintf(pitch, "%i", WIDTH * 2);
 
    libvlc_exception_init(&ex);
 
    libvlc = libvlc_new(vlc_argc, vlc_argv, &ex);
    catchEx(&ex);
 
    m = libvlc_media_new(libvlc, VIDEO_FILE, &ex);
    catchEx(&ex);
 
    mp = libvlc_media_player_new_from_media(m, &ex);
    catchEx(&ex);
 
    libvlc_media_release(m);
    libvlc_media_player_play(mp, &ex);
    catchEx(&ex);
 
    while(!done) {
        action = 0;
 
        /* Keys: enter (fullscreen), space (pause), escape (quit) */
        while( SDL_PollEvent( &event ) )
        {
            switch(event.type)
            {
            case SDL_QUIT:
                done = 1;
                break;
            case SDL_KEYDOWN:
                action = event.key.keysym.sym;
                break;
            }
        }
 
        switch(action)
        {
        case SDLK_ESCAPE:
            done = 1;
            break;
        }
 
 
        /* Blitting the surface does not prevent it from being locked and
         * written to by another thread, so we use this additional mutex. */
        SDL_LockMutex(ctx.mutex);
        //SDL_BlitSurface(ctx.surf, NULL, screen, NULL);
 
 
        /* Charger une texture */
        glBindTexture(GL_TEXTURE_2D, image);
 
        /* Générer une texture */
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, ctx.surf->w, ctx.surf->h, 0, GL_RGB, GL_UNSIGNED_BYTE, ctx.surf->pixels);
 
        /* Des bon paramètres */
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 
		glBegin(GL_QUADS);
			glTexCoord2d(0, 1);
			glVertex2f(0, 0.9);
			glTexCoord2d(1, 1);
			glVertex2f(0.9, 0.9);
			glTexCoord2d(1, 0);
			glVertex2f(0.9, -0.9);
			glTexCoord2d(0, 0);
			glVertex2f(0, -0.9);
		glEnd();
 
        SDL_UnlockMutex(ctx.mutex);
 
        //SDL_Flip(screen);
	glFlush();
        SDL_GL_SwapBuffers();
        SDL_Delay(10);
 
    }
 
    /*
     * Stop stream and clean up libVLC
     */
    libvlc_media_player_stop(mp, &ex);
    catchEx(&ex);
 
 
    libvlc_media_player_release(mp);
    libvlc_release(libvlc);
 
    /*
     * Close window and clean up libSDL
     */
    SDL_DestroyMutex(ctx.mutex);
    SDL_FreeSurface(ctx.surf);
 
    SDL_Quit();
 
    return 0;
}
Voilà donc si quelqu"un a une idée qui permettrait de faire fonctionner ce code, ce serait chouette.

Merci. :]


PS : Au cas où, mes libs de compilation : g++ -otest main.o -lvlc -lSDL_image -lSDL -lGL