annotate libvo/vo_gl.c @ 1982:b190d3e9427c

init version
author pontscho
date Thu, 27 Sep 2001 12:56:01 +0000
parents d40f2b686846
children bf7764f429c9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1 #define DISP
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
2
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
3 // this can be 3 or 4 (regarding 24bpp and 32bpp)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
4 #define BYTES_PP 3
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
5
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
6 #define TEXTUREFORMAT_32BPP
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
7
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8 /*
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
9 * video_out_gl.c, X11/OpenGL interface
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
10 * based on video_out_x11 by Aaron Holtzman,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
11 * and WS opengl window manager by Pontscho/Fresh!
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
12 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
13
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
14 #include <stdio.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
15 #include <stdlib.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16 #include <string.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17 #include <math.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
18
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
19 #include "config.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
20 #include "video_out.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21 #include "video_out_internal.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 LIBVO_EXTERN(gl)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 #include <X11/Xlib.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 #include <X11/Xutil.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 //#include <X11/keysym.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 #include <GL/glx.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 #include <errno.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 #include "yuv2rgb.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 #include <GL/gl.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34
31
1fc618eba830 added check_events() interface
arpi_esp
parents: 1
diff changeset
35 #include "x11_common.h"
1fc618eba830 added check_events() interface
arpi_esp
parents: 1
diff changeset
36
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 static vo_info_t vo_info =
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 "X11 (OpenGL)",
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40 "gl",
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41 "Arpad Gereoffy <arpi@esp-team.scene.hu>",
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 ""
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 /* private prototypes */
1109
a013b2124f05 -Wall like fixes
al3x
parents: 614
diff changeset
46 // static void Display_Image (unsigned char *ImageData);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 /* local data */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 static unsigned char *ImageData=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 /* X11 related variables */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 static Display *mydisplay;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 static Window mywindow;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 //static GC mygc;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 //static XImage *myximage;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 //static int depth,mode;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 static XWindowAttributes attribs;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 static int X_already_started = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59
1109
a013b2124f05 -Wall like fixes
al3x
parents: 614
diff changeset
60 //static int texture_id=1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 static GLXContext wsGLXContext;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 //XVisualInfo * wsVisualInfo;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 int wsGLXAttrib[] = { GLX_RGBA,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 GLX_RED_SIZE,1,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 GLX_GREEN_SIZE,1,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 GLX_BLUE_SIZE,1,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 // GLX_DEPTH_SIZE,16,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 GLX_DOUBLEBUFFER,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 None };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 static uint32_t image_width;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 static uint32_t image_height;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 static uint32_t image_format;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 static uint32_t image_bpp;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 static uint32_t image_bytes;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 static uint32_t texture_width;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 static uint32_t texture_height;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81
612
77e0094f0cce some warnings killed
szabii
parents: 384
diff changeset
82 static void resize(int x,int y){
1290
af0b764f34c5 no segfault if no glx present
alex
parents: 1137
diff changeset
83 printf("[gl] Resize: %dx%d\n",x,y);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84 glViewport( 0, 0, x, y );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 glMatrixMode(GL_PROJECTION);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 glLoadIdentity();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 glOrtho(0, image_width, image_height, 0, -1,1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 glMatrixMode(GL_MODELVIEW);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91 glLoadIdentity();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
94 /* connect to server, create and map window,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95 * allocate colors and (shared) memory
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97 static uint32_t
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98 init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100 int screen;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
101 unsigned int fg, bg;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102 char *hello = (title == NULL) ? "OpenGL rulez" : title;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103 char *name = ":0.0";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104 XSizeHints hint;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105 XVisualInfo *vinfo;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106 XEvent xev;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107
1109
a013b2124f05 -Wall like fixes
al3x
parents: 614
diff changeset
108 // XGCValues xgcv;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109 XSetWindowAttributes xswa;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110 unsigned long xswamask;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
112 image_height = height;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113 image_width = width;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
114 image_format = format;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
115
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
116 if (X_already_started) return -1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
117
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
118 if(getenv("DISPLAY")) name = getenv("DISPLAY");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
119
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
120 mydisplay = XOpenDisplay(name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
121
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
122 if (mydisplay == NULL)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
123 {
1290
af0b764f34c5 no segfault if no glx present
alex
parents: 1137
diff changeset
124 printf("[gl] Can not open display\n");
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
125 return -1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
126 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
127
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
128 screen = DefaultScreen(mydisplay);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
129
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
130 hint.x = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
131 hint.y = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
132 hint.width = d_width;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
133 hint.height = d_height;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
134 hint.flags = PPosition | PSize;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
135
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
136 /* Get some colors */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
137
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
138 bg = WhitePixel(mydisplay, screen);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
139 fg = BlackPixel(mydisplay, screen);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
140
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
141 /* Make the window */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
142
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
143 XGetWindowAttributes(mydisplay, DefaultRootWindow(mydisplay), &attribs);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
144
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
145 #if 0
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
146 /*
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
147 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
148 * depth in X11 terminology land is the number of bits used to
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
149 * actually represent the colour.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
150 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
151 * bpp in X11 land means how many bits in the frame buffer per
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
152 * pixel.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
153 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
154 * ex. 15 bit color is 15 bit depth and 16 bpp. Also 24 bit
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
155 * color is 24 bit depth, but can be 24 bpp or 32 bpp.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
156 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
157
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
158 depth = attribs.depth;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
159
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
160 if (depth != 15 && depth != 16 && depth != 24 && depth != 32)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
161 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
162 /* The root window may be 8bit but there might still be
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
163 * visuals with other bit depths. For example this is the
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
164 * case on Sun/Solaris machines.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
165 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
166 depth = 24;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
167 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
168 //BEGIN HACK
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
169 //mywindow = XCreateSimpleWindow(mydisplay, DefaultRootWindow(mydisplay),
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
170 //hint.x, hint.y, hint.width, hint.height, 4, fg, bg);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
171 //
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
172 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
173
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
174 // XMatchVisualInfo(mydisplay, screen, depth, TrueColor, &vinfo);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
175 vinfo=glXChooseVisual( mydisplay,screen,wsGLXAttrib );
1290
af0b764f34c5 no segfault if no glx present
alex
parents: 1137
diff changeset
176 if (vinfo == NULL)
af0b764f34c5 no segfault if no glx present
alex
parents: 1137
diff changeset
177 {
af0b764f34c5 no segfault if no glx present
alex
parents: 1137
diff changeset
178 printf("[gl] no GLX support present\n");
af0b764f34c5 no segfault if no glx present
alex
parents: 1137
diff changeset
179 return -1;
af0b764f34c5 no segfault if no glx present
alex
parents: 1137
diff changeset
180 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
181
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
182 xswa.background_pixel = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
183 xswa.border_pixel = 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
184 // xswa.colormap = XCreateColormap(mydisplay, RootWindow(mydisplay,screen), vinfo.visual, AllocNone);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
185 xswa.colormap = XCreateColormap(mydisplay, RootWindow(mydisplay,screen), vinfo->visual, AllocNone);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
186 xswamask = CWBackPixel | CWBorderPixel | CWColormap;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
187 // xswamask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWCursor | CWOverrideRedirect | CWSaveUnder | CWX | CWY | CWWidth | CWHeight;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
188
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
189 mywindow = XCreateWindow(mydisplay, RootWindow(mydisplay,screen),
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
190 hint.x, hint.y, hint.width, hint.height, 4, vinfo->depth,CopyFromParent,vinfo->visual,xswamask,&xswa);
1137
4c7b219e126c patch: some X11 compliance fixed: set ClassHint and better fullscreen mode
arpi_esp
parents: 1109
diff changeset
191
4c7b219e126c patch: some X11 compliance fixed: set ClassHint and better fullscreen mode
arpi_esp
parents: 1109
diff changeset
192 vo_x11_classhint( mydisplay,mywindow,"gl" );
384
b0e4e5744899 Autohide X11 cursor
lgb
parents: 31
diff changeset
193 vo_hidecursor(mydisplay,mywindow);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
194
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
195 wsGLXContext=glXCreateContext( mydisplay,vinfo,NULL,True );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
196 // XStoreName( wsDisplay,wsMyWin,wsSysName );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
197
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
198 // printf("GLXcontext ok\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
199
31
1fc618eba830 added check_events() interface
arpi_esp
parents: 1
diff changeset
200 if ( fullscreen ) vo_x11_decoration( mydisplay,mywindow,0 );
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
201
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
202 XSelectInput(mydisplay, mywindow, StructureNotifyMask);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
203
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
204 /* Tell other applications about this window */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
205
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
206 XSetStandardProperties(mydisplay, mywindow, hello, hello, None, NULL, 0, &hint);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
207
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
208 /* Map window. */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
209
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
210 XMapWindow(mydisplay, mywindow);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
211
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
212 /* Wait for map. */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
213 do
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
214 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
215 XNextEvent(mydisplay, &xev);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
216 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
217 while (xev.type != MapNotify || xev.xmap.event != mywindow);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
218
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
219 XSelectInput(mydisplay, mywindow, NoEventMask);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
220
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
221 glXMakeCurrent( mydisplay,mywindow,wsGLXContext );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
222
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
223 XFlush(mydisplay);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
224 XSync(mydisplay, False);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
225
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
226 // mygc = XCreateGC(mydisplay, mywindow, 0L, &xgcv);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
227
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
228 // myximage = XGetImage(mydisplay, mywindow, 0, 0,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
229 // width, image_height, AllPlanes, ZPixmap);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
230 // ImageData = myximage->data;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
231 // bpp = myximage->bits_per_pixel;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
232
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
233 //XSelectInput(mydisplay, mywindow, StructureNotifyMask); // !!!!
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
234 XSelectInput(mydisplay, mywindow, StructureNotifyMask | KeyPressMask );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
235
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
236 // printf("Window setup ok\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
237
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
238 #if 0
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
239 // If we have blue in the lowest bit then obviously RGB
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
240 mode = ((myximage->blue_mask & 0x01) != 0) ? MODE_RGB : MODE_BGR;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
241 #ifdef WORDS_BIGENDIAN
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
242 if (myximage->byte_order != MSBFirst)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
243 #else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
244 if (myximage->byte_order != LSBFirst)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
245 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
246 {
1302
2460ebcb6e69 Fixed a typo and wrong varname.
atmos4
parents: 1290
diff changeset
247 printf("[gl] no support for non-native XImage byte order!\n");
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
248 return -1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
249 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
250
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
251 printf("DEPTH=%d BPP=%d\n",depth,bpp);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
252 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
253
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
254 /*
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
255 * If depth is 24 then it may either be a 3 or 4 byte per pixel
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
256 * format. We can't use bpp because then we would lose the
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
257 * distinction between 15/16bit depth (2 byte formate assumed).
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
258 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
259 * FIXME - change yuv2rgb_init to take both depth and bpp
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
260 * parameters
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
261 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
262
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
263 texture_width=32;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
264 while(texture_width<image_width) texture_width*=2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
265 while(texture_width<image_height) texture_width*=2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
266 texture_height=texture_width;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
267
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
268 if(format==IMGFMT_YV12){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
269 yuv2rgb_init(8*BYTES_PP, MODE_BGR);
1290
af0b764f34c5 no segfault if no glx present
alex
parents: 1137
diff changeset
270 printf("[gl] YUV init OK!\n");
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
271 image_bpp=8*BYTES_PP;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
272 image_bytes=BYTES_PP;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
273 } else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
274 image_bpp=format&0xFF;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
275 image_bytes=(image_bpp+7)/8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
276 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
277
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
278 ImageData=malloc(texture_width*texture_height*image_bytes);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
279 memset(ImageData,128,texture_width*texture_height*image_bytes);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
280
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
281 glDisable(GL_BLEND);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
282 glDisable(GL_DEPTH_TEST);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
283 glDepthMask(GL_FALSE);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
284 glDisable(GL_CULL_FACE);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
285
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
286 glEnable(GL_TEXTURE_2D);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
287
1290
af0b764f34c5 no segfault if no glx present
alex
parents: 1137
diff changeset
288 printf("[gl] Creating %dx%d texture...\n",texture_width,texture_height);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
289
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
290 #if 1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
291 // glBindTexture(GL_TEXTURE_2D, texture_id);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
292 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
293 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
294 #ifdef TEXTUREFORMAT_32BPP
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
295 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, texture_width, texture_height, 0,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
296 #else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
297 glTexImage2D(GL_TEXTURE_2D, 0, BYTES_PP, texture_width, texture_height, 0,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
298 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
299 (image_bytes==4)?GL_RGBA:GL_BGR, GL_UNSIGNED_BYTE, ImageData);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
300 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
301
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
302 resize(d_width,d_height);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
303
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
304 glClearColor( 1.0f,0.0f,1.0f,0.0f );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
305 glClear( GL_COLOR_BUFFER_BIT );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
306
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
307 // printf("OpenGL setup OK!\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
308
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
309 X_already_started++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
310 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
311 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
312
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
313 static const vo_info_t*
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
314 get_info(void)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
315 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
316 return &vo_info;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
317 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
318
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
319 static void
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
320 Terminate_Display_Process(void)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
321 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
322 getchar(); /* wait for enter to remove window */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
323 XDestroyWindow(mydisplay, mywindow);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
324 XCloseDisplay(mydisplay);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
325 X_already_started = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
326 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
327
31
1fc618eba830 added check_events() interface
arpi_esp
parents: 1
diff changeset
328
1fc618eba830 added check_events() interface
arpi_esp
parents: 1
diff changeset
329 static void check_events(void)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
330 {
31
1fc618eba830 added check_events() interface
arpi_esp
parents: 1
diff changeset
331 int e=vo_x11_check_events(mydisplay);
1fc618eba830 added check_events() interface
arpi_esp
parents: 1
diff changeset
332 if(e&VO_EVENT_RESIZE) resize(vo_dwidth,vo_dheight);
1fc618eba830 added check_events() interface
arpi_esp
parents: 1
diff changeset
333 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
334
1501
d40f2b686846 changes according to -utf8 option, draw_osd() function added
atlka
parents: 1302
diff changeset
335 static void draw_osd(void)
d40f2b686846 changes according to -utf8 option, draw_osd() function added
atlka
parents: 1302
diff changeset
336 {
d40f2b686846 changes according to -utf8 option, draw_osd() function added
atlka
parents: 1302
diff changeset
337 }
31
1fc618eba830 added check_events() interface
arpi_esp
parents: 1
diff changeset
338
1fc618eba830 added check_events() interface
arpi_esp
parents: 1
diff changeset
339 static void
1fc618eba830 added check_events() interface
arpi_esp
parents: 1
diff changeset
340 flip_page(void)
1fc618eba830 added check_events() interface
arpi_esp
parents: 1
diff changeset
341 {
1fc618eba830 added check_events() interface
arpi_esp
parents: 1
diff changeset
342
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
343 // glEnable(GL_TEXTURE_2D);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
344 // glBindTexture(GL_TEXTURE_2D, texture_id);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
345
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
346 glColor3f(1,1,1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
347 glBegin(GL_QUADS);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
348 glTexCoord2f(0,0);glVertex2i(0,0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
349 glTexCoord2f(0,1);glVertex2i(0,texture_height);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
350 glTexCoord2f(1,1);glVertex2i(texture_width,texture_height);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
351 glTexCoord2f(1,0);glVertex2i(texture_width,0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
352 glEnd();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
353
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
354 // glFlush();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
355 glFinish();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
356 glXSwapBuffers( mydisplay,mywindow );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
357
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
358 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
359
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
360 //static inline uint32_t draw_slice_x11(uint8_t *src[], uint32_t slice_num)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
361 static uint32_t draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
362 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
363 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
364 int dstride=w*BYTES_PP;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
365
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
366 // dstride=(dstride+15)&(~15);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
367
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
368 yuv2rgb(ImageData, src[0], src[1], src[2],
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
369 w,h, dstride, stride[0],stride[1]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
370
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
371 // emms ();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
372
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
373 for(i=0;i<h;i++){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
374 glTexSubImage2D( GL_TEXTURE_2D, // target
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
375 0, // level
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
376 x, // x offset
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
377 y+i, // y offset
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
378 w, // width
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
379 1, // height
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
380 (BYTES_PP==4)?GL_RGBA:GL_RGB, // format
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
381 GL_UNSIGNED_BYTE, // type
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
382 ImageData+i*dstride ); // *pixels
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
383 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
384
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
385 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
386 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
387
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
388 static inline uint32_t
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
389 draw_frame_x11_yv12(uint8_t *src[])
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
390 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
391 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
392 // printf("Converting YUV->RGB...\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
393 yuv2rgb(ImageData, src[0], src[1], src[2],
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
394 image_width, image_height,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
395 image_width*BYTES_PP, image_width, image_width/2 );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
396 // printf("Ready!\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
397
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
398 // emms ();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
399
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
400 for(i=0;i<image_height;i++){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
401 glTexSubImage2D( GL_TEXTURE_2D, // target
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
402 0, // level
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
403 0, // x offset
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
404 i, // y offset
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
405 image_width, // width
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
406 1, // height
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
407 (BYTES_PP==4)?GL_RGBA:GL_RGB, // format
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
408 GL_UNSIGNED_BYTE, // type
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
409 ImageData+i*BYTES_PP*image_width ); // *pixels
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
410 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
411
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
412 // Display_Image(ImageData);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
413 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
414 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
415
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
416
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
417 static inline uint32_t
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
418 draw_frame_x11_bgr(uint8_t *src[])
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
419 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
420 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
421 uint8_t *s=src[0];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
422 uint8_t *de=&ImageData[3*image_width];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
423
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
424 for(i=0;i<image_height;i++){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
425 uint8_t *d=ImageData;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
426 while(d<de){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
427 d[0]=s[2];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
428 d[1]=s[1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
429 d[2]=s[0];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
430 s+=3;d+=3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
431 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
432 glTexSubImage2D( GL_TEXTURE_2D, // target
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
433 0, // level
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
434 0, // x offset
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
435 // image_height-1-i, // y offset
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
436 i, // y offset
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
437 image_width, // width
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
438 1, // height
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
439 (image_bytes==4)?GL_RGBA:GL_RGB, // format
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
440 GL_UNSIGNED_BYTE, // type
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
441 ImageData); // *pixels
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
442 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
443
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
444 // Display_Image(ImageData);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
445 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
446 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
447
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
448 static inline uint32_t
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
449 draw_frame_x11_rgb(uint8_t *src[])
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
450 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
451 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
452 uint8_t *ImageData=src[0];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
453
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
454 for(i=0;i<image_height;i++){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
455 glTexSubImage2D( GL_TEXTURE_2D, // target
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
456 0, // level
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
457 0, // x offset
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
458 // image_height-1-i, // y offset
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
459 i, // y offset
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
460 image_width, // width
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
461 1, // height
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
462 (image_bytes==4)?GL_RGBA:GL_RGB, // format
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
463 GL_UNSIGNED_BYTE, // type
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
464 ImageData+i*image_bytes*image_width ); // *pixels
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
465 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
466
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
467 // Display_Image(ImageData);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
468 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
469 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
470
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
471
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
472 static uint32_t
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
473 draw_frame(uint8_t *src[])
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
474 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
475 if(image_format==IMGFMT_YV12)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
476 return draw_frame_x11_yv12(src);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
477 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
478 if((image_format&IMGFMT_RGB_MASK)==IMGFMT_RGB)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
479 return draw_frame_x11_rgb(src);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
480 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
481 return draw_frame_x11_bgr(src);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
482 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
483
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
484 static uint32_t
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
485 query_format(uint32_t format)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
486 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
487 switch(format){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
488 case IMGFMT_YV12:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
489 case IMGFMT_RGB|24:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
490 case IMGFMT_BGR|24:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
491 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
492 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
493 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
494 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
495
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
496
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
497 static void
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
498 uninit(void)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
499 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
500 }