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;
} |
Partager