Beispiel #1
0
PIGLIT_GL_TEST_CONFIG_END

enum piglit_result
piglit_display(void)
{
    bool pass = true;
    float green[4] = {0.0, 1.0, 0.0, 0.0};

    /* Clear red. */
    glClearColor(1.0, 0.0, 0.0, 0.0);
    glClear(GL_COLOR_BUFFER_BIT);

    /* Draw top half of screen green. */
    glColor4f(0.0, 1.0, 0.0, 0.0);
    piglit_draw_rect(-1, 0, 2, 1);

    /* Discard a copy over the bottom red over the top green. */
    glEnable(GL_RASTERIZER_DISCARD);
    glRasterPos2i(-1, 0);
    glCopyPixels(0, 0, piglit_width, piglit_height / 2, GL_COLOR);

    /* Don't discard a copy of the green over the remaining red. */
    glDisable(GL_RASTERIZER_DISCARD);
    glRasterPos2i(-1, -1);
    glCopyPixels(0, piglit_height / 2, piglit_width, piglit_height / 2,
                 GL_COLOR);

    pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, green);

    piglit_present_results();

    return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Beispiel #2
0
enum piglit_result
piglit_display(void)
{
	GLfloat firstPixel[4];
	bool pass = true;

	/* read from fbo, draw to window */
	glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
	glReadBuffer(GL_COLOR_ATTACHMENT0);
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
	glDrawBuffer(GL_BACK);

        /* init color buffer to red */
	glClearColor(1, 0, 0, 1);
	glClear(GL_COLOR_BUFFER_BIT);

	/* copy (undefined) fbo image to window */
	glWindowPos2i(0, 0);
	glCopyPixels(0, 0, piglit_width, piglit_height, GL_COLOR);

	glBindFramebuffer(GL_READ_FRAMEBUFFER, piglit_winsys_fbo);
	glReadBuffer(GL_BACK);

	glReadPixels(0, 0, 1, 1, GL_RGBA, GL_FLOAT, firstPixel);
	pass = piglit_probe_rect_rgb(0, 0, piglit_width, piglit_height,
				     firstPixel);

	piglit_present_results();

	return pass ? PIGLIT_PASS : PIGLIT_WARN;
}
Beispiel #3
0
static enum piglit_result test_copy(void)
{
	/* Clear stencil to 0xfe. */
	glClearStencil(0xfefe);
	glClear(GL_STENCIL_BUFFER_BIT);

	/* Initialize stencil. */
	glEnable(GL_STENCIL_TEST);
	glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);

	/* Set the upper-right corner to 0x3333 and copy the content to the lower-left one. */
	glStencilFunc(GL_ALWAYS, 0x3333 & mask, ~0);
	piglit_draw_rect(0, 0, 1, 1);
	if (test == BLIT)
		glBlitFramebufferEXT(BUF_SIZE/2+1, BUF_SIZE/2+1, BUF_SIZE, BUF_SIZE,
				     0, 0, BUF_SIZE/2, BUF_SIZE/2,
				     GL_STENCIL_BUFFER_BIT, GL_NEAREST);
	else
		glCopyPixels(BUF_SIZE/2+1, BUF_SIZE/2+1, BUF_SIZE/2, BUF_SIZE/2, GL_STENCIL);

	/* Initialize the other corners. */
	glStencilFunc(GL_ALWAYS, 0x6666 & mask, ~0);
	piglit_draw_rect(0, -1, 1, 1);

	glStencilFunc(GL_ALWAYS, 0x9999 & mask, ~0);
	piglit_draw_rect(-1, 0, 1, 1);

	glStencilFunc(GL_ALWAYS, 0xbbbb & mask, ~0);
	piglit_draw_rect(0, 0, 1, 1);

	glDisable(GL_STENCIL_TEST);

	return compare_stencil();
}
Beispiel #4
0
static void
draw_stencil_mipmap(int x, int y, int dim, GLuint tex, GLuint level)
{
	GLuint fbo;
	GLint draw_buffer, read_buffer;

	glGetIntegerv(GL_DRAW_BUFFER, &draw_buffer);
	glGetIntegerv(GL_READ_BUFFER, &read_buffer);

	glGenFramebuffers(1, &fbo);
	glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);

	glDrawBuffer(GL_NONE);
	glReadBuffer(GL_NONE);

	glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
			       GL_TEXTURE_2D, tex, level);
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
        glWindowPos2i(x, y);
        glCopyPixels(0, 0, dim, dim, GL_STENCIL);
        if (!piglit_check_gl_error(GL_NO_ERROR)) {
		/* The blit shouldn't generate an error.  If it does, report failure */
		piglit_report_result(PIGLIT_FAIL);
        }

	glBindFramebuffer(GL_FRAMEBUFFER, piglit_winsys_fbo);
	glDeleteFramebuffers(1, &fbo);

	glDrawBuffer(draw_buffer);
	glReadBuffer(read_buffer);
}
Beispiel #5
0
static void cdscrollarea (cdCtxCanvas *ctxcanvas, int xmin, int xmax, int ymin, int ymax, int dx, int dy)
{
  glRasterPos2i(xmin+dx, ymin+dy);
  glCopyPixels(xmin, ymin, xmax-xmin+1, ymax-ymin+1, GL_RGBA);

  (void)ctxcanvas;
}
Beispiel #6
0
static enum piglit_result test_copy(void)
{
	/* Clear. */
	glClearDepth(0);
	glClear(GL_DEPTH_BUFFER_BIT);

	/* Initialize buffers. */
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_ALWAYS);

	/* Set the upper-right corner to 0x3333 and copy the content to the lower-left one. */
	piglit_draw_rect_z(-0.5, 0, 0, 1, 1);
	if (test == BLIT)
		glBlitFramebufferEXT(BUF_SIZE/2+1, BUF_SIZE/2+1, BUF_SIZE, BUF_SIZE,
				     0, 0, BUF_SIZE/2, BUF_SIZE/2,
				     GL_DEPTH_BUFFER_BIT, GL_NEAREST);
	else
		glCopyPixels(BUF_SIZE/2+1, BUF_SIZE/2+1, BUF_SIZE/2, BUF_SIZE/2, GL_DEPTH);

	/* Initialize the other corners. */
	piglit_draw_rect_z(-0.25, 0, -1, 1, 1);
	piglit_draw_rect_z(0.25, -1, 0, 1, 1);
	piglit_draw_rect_z(0.5, 0, 0, 1, 1);

	glDisable(GL_DEPTH_TEST);

	return compare();
}
Beispiel #7
0
enum piglit_result
piglit_display(void)
{
	bool pass = true;
	float green[4] = {0.0, 1.0, 0.0, 0.0};
	GLuint qpass, qfail;

	glClearColor(1.0, 0.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT);

	glGenQueries(1, &qpass);
	glGenQueries(1, &qfail);

	/* Generate query pass: draw top half of screen. */
	glColor4f(0.0, 1.0, 0.0, 0.0);
	glBeginQuery(GL_SAMPLES_PASSED, qpass);
	piglit_draw_rect(-1, 0, 2, 1);
	glEndQuery(GL_SAMPLES_PASSED);

	/* Generate query fail */
	glBeginQuery(GL_SAMPLES_PASSED, qfail);
	glEndQuery(GL_SAMPLES_PASSED);

	/* Conditional render that should not copy red over the green. */
	glBeginConditionalRenderNV(qfail, GL_QUERY_WAIT_NV);
	glRasterPos2i(-1, 0);
	glCopyPixels(0, 0, piglit_width, piglit_height / 2, GL_COLOR);
	glEndConditionalRenderNV();

	/* Conditional render that should copy green over remaining red. */
	glBeginConditionalRenderNV(qpass, GL_QUERY_WAIT_NV);
	glRasterPos2i(-1, -1);
	glCopyPixels(0, piglit_height / 2, piglit_width, piglit_height / 2,
		     GL_COLOR);
	glEndConditionalRenderNV();

	pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height,
				      green);

	glutSwapBuffers();

	glDeleteQueries(1, &qfail);
	glDeleteQueries(1, &qpass);

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Beispiel #8
0
enum piglit_result
piglit_display(void)
{
	GLboolean pass = GL_TRUE;
	int dst_x = piglit_width / 2 + 10, dst_y;
	int dst_w = 10, dst_h = 10;

	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);

	/* whole window red */
	glClearColor(1.0, 0.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT);

	/* right half green */
	glColor4f(0.0, 1.0, 0.0, 0.0);
	piglit_draw_rect(piglit_width / 2, 0, piglit_width / 2, piglit_height);

	/* Copy a 10x10 square from left to right */
	glEnable(GL_SCISSOR_TEST);
	dst_y = 10;
	glScissor(dst_x, dst_y, dst_w, dst_h);
	glRasterPos2i(dst_x - 5, dst_y - 5);
	glCopyPixels(10, 10, 20, 20, GL_COLOR);

	/* Don't copy a 10x10 square from left to right */
	dst_y = 30;
	glScissor(dst_x, dst_y, 0, 0);
	glRasterPos2i(dst_x - 5, dst_y - 5);
	glCopyPixels(10, 10, 20, 20, GL_COLOR);

	/* Copy an unscissored 10x10 square from left to right */
	glDisable(GL_SCISSOR_TEST);
	dst_y = 50;
	glRasterPos2i(dst_x, dst_y);
	glCopyPixels(10, 10, dst_w, dst_h, GL_COLOR);

	pass &= check_red_box_surrounded_by_green(dst_x, 10, dst_w, dst_h);
	pass &= check_red_box_surrounded_by_green(dst_x, 30, 0, 0);
	pass &= check_red_box_surrounded_by_green(dst_x, 50, dst_w, dst_h);

	glutSwapBuffers();

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Beispiel #9
0
void motion(int x, int y) {
    static GLint screeny;

    screeny = height - (GLint)y;
    glRasterPos2i(x, screeny);
    glPixelZoom(zoomFactor, zoomFactor);
    glCopyPixels(0, 0, checkImageWidth, checkImageHeight, GL_COLOR);
    glPixelZoom(1.0, 1.0);
    glFlush();
}
Beispiel #10
0
void __glXDisp_CopyPixels(GLbyte *pc)
{
	glCopyPixels( 
		*(GLint    *)(pc + 0),
		*(GLint    *)(pc + 4),
		*(GLsizei  *)(pc + 8),
		*(GLsizei  *)(pc + 12),
		*(GLenum   *)(pc + 16)
	);
}
Beispiel #11
0
static void Display( void )
{
   const int dx = (WinWidth - ImgWidth) / 2;
   const int dy = (WinHeight - ImgHeight) / 2;

   if (DrawFront) {
      glDrawBuffer(GL_FRONT);
      glReadBuffer(GL_FRONT);
   }
   else {
      glDrawBuffer(GL_BACK);
      glReadBuffer(GL_BACK);
   }

   glClear( GL_COLOR_BUFFER_BIT );

   /* draw original image */
   glWindowPos2iARB(dx, dy);                    
   glDrawPixels(ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image);

   if (Scissor)
      glEnable(GL_SCISSOR_TEST);

   if (Invert) {
      glPixelTransferf(GL_RED_SCALE, -1.0);
      glPixelTransferf(GL_GREEN_SCALE, -1.0);
      glPixelTransferf(GL_BLUE_SCALE, -1.0);
      glPixelTransferf(GL_RED_BIAS, 1.0);
      glPixelTransferf(GL_GREEN_BIAS, 1.0);
      glPixelTransferf(GL_BLUE_BIAS, 1.0);
   }

   /* draw copy */
   glPixelZoom(Xzoom, Yzoom);
   glWindowPos2iARB(Xpos, Ypos);
   glCopyPixels(dx, dy, ImgWidth, ImgHeight, GL_COLOR);
   glPixelZoom(1, 1);

   glDisable(GL_SCISSOR_TEST);

   if (Invert) {
      glPixelTransferf(GL_RED_SCALE, 1.0);
      glPixelTransferf(GL_GREEN_SCALE, 1.0);
      glPixelTransferf(GL_BLUE_SCALE, 1.0);
      glPixelTransferf(GL_RED_BIAS, 0.0);
      glPixelTransferf(GL_GREEN_BIAS, 0.0);
      glPixelTransferf(GL_BLUE_BIAS, 0.0);
   }

   if (DrawFront)
      glFinish();
   else
      glutSwapBuffers();
}
Beispiel #12
0
static void
copy(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
     GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1)
{
	GLsizei srcW = srcX1 - srcX0, srcH = srcY1 - srcY0;
	GLsizei dstW = dstX1 - dstX0, dstH = dstY1 - dstY0;
	glPixelZoom((float) dstW / (float) srcW,
		    (float) dstH / (float) srcH);
	glWindowPos2i(dstX0, dstY0);
	glCopyPixels(srcX0, srcY0, srcW, srcH, GL_COLOR);
}
void tui::LayoutCanvas::viewshift()
{
   //@TODO screen sliding. Some rough ideas.
   int Wcl, Hcl;
   const int slide_step = 100;
   GetClientSize(&Wcl,&Hcl);
   glReadBuffer(GL_FRONT);
   glRasterPos2i (0, 0);
   glCopyPixels (slide_step, 0, Wcl-slide_step, Hcl, GL_COLOR);
   glAccum(GL_LOAD, 1.0);
/*   slide = false;*/
}
void
motion (int x, int y)
{
   static GLint screeny;
   
   screeny = height - (GLint) y;
   glRasterPos2i (x, screeny);
   glPixelZoom (zoomFactor, zoomFactor);
   glCopyPixels (0, 0, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT, GL_COLOR);
   glPixelZoom (1.0, 1.0);
   glFlush ();
}
Beispiel #15
0
void bmp_copy(void){
	glClear(GL_COLOR_BUFFER_BIT);

	glBegin(GL_TRIANGLES);
	glColor3f(1.0f,0.0f,0.0f);	glVertex2f(0.0f,0.0f);
	glColor3f(0.0f,1.0f,0.0f);	glVertex2f(1.0f,0.0f);
	glColor3f(0.0f,0.0f,1.0f);	glVertex2f(0.5f,1.0f);
	glEnd();

	glPixelZoom(-0.5f, -0.5f);
	glRasterPos2i(1,1);

	glCopyPixels(WIDTH/2, HEIGHT/2, WIDTH/2, HEIGHT/2, GL_COLOR);

	glutSwapBuffers();
}
Beispiel #16
0
void
HaloRefImage::draw_output()
{
   if (use_fbos)
      glBindFramebuffer(GL_READ_FRAMEBUFFER, _fbo);
   else
      glReadBuffer(GL_AUX0);
   glDrawBuffer(GL_BACK);
   glDisable(GL_BLEND);
   glCopyPixels(0,0,800,600,GL_COLOR);
   glEnable(GL_BLEND);
   if (use_fbos)
      glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
   else
      glReadBuffer(GL_BACK);
}
Beispiel #17
0
static void hugsprim_glCopyPixels_2(HugsStackPtr hugs_root)
{
    HsInt32 arg1;
    HsInt32 arg2;
    HsInt32 arg3;
    HsInt32 arg4;
    HsWord32 arg5;
    arg1 = hugs->getInt32();
    arg2 = hugs->getInt32();
    arg3 = hugs->getInt32();
    arg4 = hugs->getInt32();
    arg5 = hugs->getWord32();
    glCopyPixels(arg1, arg2, arg3, arg4, arg5);
    
    hugs->returnIO(hugs_root,0);
}
Beispiel #18
0
void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT);

	glBegin(GL_TRIANGLES);
		glColor3f(1.0f, 0.0f, 0.0f); glVertex2f(0.0f, 0.0f);
		glColor3f(0.0f, 1.0f, 0.0f); glVertex2f(1.0f, 0.0f);
		glColor3f(0.0f, 0.0f, 1.0f); glVertex2f(0.5f, 1.0f);
	glEnd();

	glPixelZoom(-0.5f, -0.5f);
	glRasterPos2i(1, 1);
	glCopyPixels(WindowWidth / 2, WindowHeight / 2,
		WindowWidth / 2, WindowHeight / 2, GL_COLOR);

	glutSwapBuffers();
	grab();
}
Beispiel #19
0
/* Called when window needs to be redrawn */
void redraw(void)
{
    glClear(GL_COLOR_BUFFER_BIT); 

    draw_dither();
    glRasterPos2i(0, 0);
    glPixelZoom(3.f, 3.f);
    glDrawPixels(image_w, image_h, GL_RGBA, GL_UNSIGNED_BYTE, (GLubyte *)img);
    glPixelZoom(1.f, 1.f);
    glAccum(GL_ACCUM, -1.0);
    glAccum(GL_RETURN, -1.f);
    glRasterPos2i(0, 0);
    glDrawBuffer(GL_FRONT); glReadBuffer(GL_FRONT);
    pixel_map(1);
    glCopyPixels(0, 0, 3*image_w, 3*image_h, GL_COLOR);
    pixel_map(0);

    CHECK_ERROR("redraw");
}
void
piglit_init(int argc, char **argv)
{
	GLint max_samples;
	GLuint rb, fb;
	GLenum status;
	bool pass = true;

	piglit_require_extension("GL_EXT_framebuffer_multisample");

	glGetIntegerv(GL_MAX_SAMPLES, &max_samples);

	glGenFramebuffersEXT(1, &fb);
	glBindFramebufferEXT(GL_FRAMEBUFFER, fb);

	glGenRenderbuffersEXT(1, &rb);
	glBindRenderbufferEXT(GL_RENDERBUFFER, rb);
	glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, max_samples,
					    GL_RGBA, 1, 1);

	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
				     GL_RENDERBUFFER, rb);

	glDrawBuffer(GL_COLOR_ATTACHMENT0);
	glReadBuffer(GL_COLOR_ATTACHMENT0);

	status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER);
	if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
		fprintf(stderr, "FBO incomplete\n");
		piglit_report_result(PIGLIT_FAIL);
	}

	/* Finally, the actual test! */
	glCopyPixels(0, 0, 1, 1, GL_COLOR);
	if (!piglit_check_gl_error(GL_INVALID_OPERATION))
		piglit_report_result(PIGLIT_FAIL);

	glDeleteRenderbuffersEXT(1, &rb);
	glDeleteFramebuffersEXT(1, &fb);

	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
}
Beispiel #21
0
void idle(void)
{
  int x = curX - (wbrush/2);
  int y = h - (curY + (hbrush/2));
  int msecs;
  static int last_msecs = -1;

  /* do not do this more than 60 times a second.  Otherwise it's
   * to fast for use on high-end systems */
  msecs = get_msecs();
  if (fabs(last_msecs - msecs) < 1000./60.) {
    return;
  }
  last_msecs = msecs;

  /* we draw the brush using a drawpixels command.  on systems with
   * hardware-accelerated texture mapping it would be better to use
   * that. 
   * 
   * we use the bitmap hack to set the rasterpos because we don't
   * know that the position will be within the window. 
   */
  glRasterPos2i(0, 0);
  glBitmap(0, 0, 0, 0, x, y, 0);
  glColorMask(0, 0, 0, 1);
  glDrawBuffer(GL_BACK);
  glDrawPixels(wbrush, hbrush, GL_ALPHA, GL_UNSIGNED_BYTE, brush);
  glColorMask(1, 1, 1, 1);
  
  glReadBuffer(GL_BACK);
  glDrawBuffer(GL_FRONT);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glEnable(GL_BLEND);
  glCopyPixels(x, y, wbrush, hbrush, GL_COLOR);
  glDisable(GL_BLEND);
  
  glColorMask(1, 1, 1, 1);
}
Beispiel #22
0
/*
==============
XY_Overlay
==============
*/
void XY_Overlay (void)
{
	int	w, h;
	int	r[4];
	static	vec3_t	lastz;
	static	vec3_t	lastcamera;


	glViewport(0, 0, g_qeglobals.d_xy.width, g_qeglobals.d_xy.height);

	//
	// set up viewpoint
	//
	glMatrixMode(GL_PROJECTION);
    glLoadIdentity ();

	w = g_qeglobals.d_xy.width/2 / g_qeglobals.d_xy.scale;
	h = g_qeglobals.d_xy.height/2 / g_qeglobals.d_xy.scale;
	glOrtho (g_qeglobals.d_xy.origin[0] - w, g_qeglobals.d_xy.origin[0] + w
		, g_qeglobals.d_xy.origin[1] - h, g_qeglobals.d_xy.origin[1] + h, -8000, 8000);
	//
	// erase the old camera and z checker positions
	// if the entire xy hasn't been redrawn
	//
	if (g_qeglobals.d_xy.d_dirty)
	{
		glReadBuffer (GL_BACK);
		glDrawBuffer (GL_FRONT);

		glRasterPos2f (lastz[0]-9, lastz[1]-9);
		glGetIntegerv (GL_CURRENT_RASTER_POSITION,r);
		glCopyPixels(r[0], r[1], 18,18, GL_COLOR);

		glRasterPos2f (lastcamera[0]-50, lastcamera[1]-50);
		glGetIntegerv (GL_CURRENT_RASTER_POSITION,r);
		glCopyPixels(r[0], r[1], 100,100, GL_COLOR);
	}
	g_qeglobals.d_xy.d_dirty = true;

	//
	// save off underneath where we are about to draw
	//
	VectorCopy (z.origin, lastz);
	VectorCopy (camera.origin, lastcamera);

	glReadBuffer (GL_FRONT);
	glDrawBuffer (GL_BACK);

	glRasterPos2f (lastz[0]-9, lastz[1]-9);
	glGetIntegerv (GL_CURRENT_RASTER_POSITION,r);
	glCopyPixels(r[0], r[1], 18,18, GL_COLOR);

	glRasterPos2f (lastcamera[0]-50, lastcamera[1]-50);
	glGetIntegerv (GL_CURRENT_RASTER_POSITION,r);
	glCopyPixels(r[0], r[1], 100,100, GL_COLOR);

	//
	// draw the new icons
	//
	glDrawBuffer (GL_FRONT);

    glShadeModel (GL_FLAT);
	glDisable(GL_TEXTURE_2D);
	glDisable(GL_TEXTURE_1D);
	glDisable(GL_DEPTH_TEST);
	glDisable(GL_BLEND);
	glColor3f(0, 0, 0);

	DrawCameraIcon ();
	DrawZIcon ();

	glDrawBuffer (GL_BACK);
    glFinish();
}
/*
 * PsychComposeCompressedStereoBuffer - Final compositing for compressed stereo.
 *
 * This routine copies both AUX buffers (0 and 1) back into the backbuffer, each of them
 * vertically scaled/compressed by a factor of 2. Its called by PsychPreFlipOperations().
 */
void PsychComposeCompressedStereoBuffer(PsychWindowRecordType *windowRecord)
{
  /*
    if (FALSE) {
        // Upload, setup and enable Anaglyph stereo fragment shader:
        const float redgain=1.0, greengain=0.7, bluegain=0.0;
        
        // This is the shader source code:
        const char anaglyphshader[] =
        "!!ARBfp1.0 "
        "PARAM ColorToGrayWeights = { 0.3, 0.59, 0.11, 1.0 }; "
        "TEMP luminance; "
        "TEMP incolor;"
        //"MOV incolor, fragment.color;"
        "TEX incolor, fragment.texcoord[0], texture[0], RECT;"
        "DP3 luminance, incolor, ColorToGrayWeights; "
        "MUL result.color.rgb, luminance, program.env[0]; "
        "MOV result.color.a, ColorToGrayWeights.a; "
        //"MOV result.color.a, fragment.color.a; "
        "END";
        
        // Upload and compile shader:
        PsychTestForGLErrors();
        glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(anaglyphshader), anaglyphshader);
        PsychTestForGLErrors();
        // Setup the rgb-gains as global parameters for the shader:
        glProgramEnvParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 0, redgain, greengain, bluegain, 0.0);
        // Enable the shader:
        glEnable(GL_FRAGMENT_PROGRAM_ARB);
    }
  */
    // Query screen dimension:
    int screenwidth=(int) PsychGetWidthFromRect(windowRecord->rect);
    int screenheight=(int) PsychGetHeightFromRect(windowRecord->rect);

    // When entering this routine, the modelview matrix is already set to identity and
    // the proper OpenGL context is active.
    
    // Set up zoom for vertical compression:
    glPixelZoom(1, 0.5f);
    glDrawBuffer(GL_BACK);
    glDisable(GL_BLEND);
    
    // Draw left view aka AUX0:
    glReadBuffer(GL_AUX0);
    glRasterPos2i(0, (windowRecord->stereomode==kPsychCompressedTLBRStereo) ? screenheight/2 : screenheight);
    glCopyPixels(0, 0, screenwidth, screenheight, GL_COLOR);

    // Draw right view aka AUX1:
    glReadBuffer(GL_AUX1);
    glRasterPos2i(0, (windowRecord->stereomode==kPsychCompressedTLBRStereo) ? screenheight : screenheight/2);
    glCopyPixels(0, 0, screenwidth, screenheight, GL_COLOR);
    
    // Restore settings:
    glReadBuffer(GL_BACK);
    glPixelZoom(1,1);
    glEnable(GL_BLEND);

    // Unconditionally disable fragment shaders:
    // glDisable(GL_FRAGMENT_PROGRAM_ARB);

    // Done.
    return;
}
Beispiel #24
0
static void
Display( void )
{
   glClearColor(.3, .3, .3, 1);
   glClear( GL_COLOR_BUFFER_BIT );

   CheckError(__LINE__);

   /** Unbind UNPACK pixel buffer before calling glBitmap */
   glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0);

   glRasterPos2i(5, ImgHeight+25);
   PrintString("f = toggle front/back  s = toggle scale/bias  b = benchmark");

   glRasterPos2i(5, ImgHeight+40);
   PrintString("GL_EXT_pixel_buffer_object test");

   /* draw original image */
   glRasterPos2i(APosX, 5);
   PrintString("Original");
   glRasterPos2i(APosX, APosY);
   glEnable(GL_DITHER);
   SetupPixelTransfer(GL_FALSE);
   /*** Draw from the DrawPBO */
   glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, DrawPBO);
   glDrawPixels(ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, 0);
   glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0);

   CheckError(__LINE__);

   /* do readpixels, drawpixels */
   glRasterPos2i(BPosX, 5);
   PrintString("Read/DrawPixels");
   SetupPixelTransfer(ScaleAndBias);
   /*** read into the Temp PBO */
   glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, TempPBO);
   CheckError(__LINE__);
   if (Benchmark) {
      GLint reads = 0;
      GLint endTime;
      GLint startTime = glutGet(GLUT_ELAPSED_TIME);
      GLdouble seconds, pixelsPerSecond;
      printf("Benchmarking...\n");
      do {
         glReadPixels(APosX, APosY, ImgWidth, ImgHeight,
                      ReadFormat, ReadType, 0);
         reads++;
         endTime = glutGet(GLUT_ELAPSED_TIME);
      } while (endTime - startTime < 4000);   /* 4 seconds */
      seconds = (double) (endTime - startTime) / 1000.0;
      pixelsPerSecond = reads * ImgWidth * ImgHeight / seconds;
      printf("Result:  %d reads in %f seconds = %f pixels/sec\n",
             reads, seconds, pixelsPerSecond);
      Benchmark = GL_FALSE;
   }
   else {
      glReadPixels(APosX, APosY, ImgWidth, ImgHeight,
                   ReadFormat, ReadType, 0);
   }
   CheckError(__LINE__);
   glRasterPos2i(BPosX, BPosY);
   glDisable(GL_DITHER);
   SetupPixelTransfer(GL_FALSE);

   CheckError(__LINE__);

   /*** draw from the Temp PBO */
   glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, TempPBO);
   glDrawPixels(ImgWidth, ImgHeight, ReadFormat, ReadType, 0);
   glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0);

   CheckError(__LINE__);

   /* do copypixels */
   glRasterPos2i(CPosX, 5);
   PrintString("CopyPixels");
   glRasterPos2i(CPosX, CPosY);
   glDisable(GL_DITHER);
   SetupPixelTransfer(ScaleAndBias);
   glCopyPixels(APosX, APosY, ImgWidth, ImgHeight, GL_COLOR);

   CheckError(__LINE__);

   if (!DrawFront)
      glutSwapBuffers();
   else
      glFinish();
}
Beispiel #25
0
static void
Display( void )
{
   glClearColor(.3, .3, .3, 1);
   glClear( GL_COLOR_BUFFER_BIT );

   glRasterPos2i(5, ImgHeight+25);
   PrintString("f = toggle front/back  s = toggle scale/bias  b = benchmark");

   /* draw original image */
   glRasterPos2i(APosX, 5);
   PrintString("Original");
   if (!Triangle) {
      glRasterPos2i(APosX, APosY);
      glEnable(GL_DITHER);
      SetupPixelTransfer(GL_FALSE);
      glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
      glDrawPixels(ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image);
   }
   else {
      float z = 0;

      glViewport(APosX, APosY, ImgWidth, ImgHeight);
      glMatrixMode( GL_PROJECTION );
      glLoadIdentity();
      glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
      glDisable(GL_CULL_FACE);

      /* Red should never be seen
       */
      glBegin(GL_POLYGON);
      glColor3f(1,0,0); 
      glVertex3f(-2, -2, z);
      glVertex3f(-2, 2, z);
      glVertex3f(2, 2, z);
      glVertex3f(2, -2, z);
      glEnd();

      /* Blue background
       */
      glBegin(GL_POLYGON);
      glColor3f(.5,.5,1); 
      glVertex3f(-1, -1, z);
      glVertex3f(-1, 1, z);
      glVertex3f(1, 1, z);
      glVertex3f(1, -1, z);
      glEnd();

      /* Triangle
       */
      glBegin(GL_TRIANGLES);
      glColor3f(.8,0,0); 
      glVertex3f(-0.9, -0.9, z);
      glColor3f(0,.9,0); 
      glVertex3f( 0.9, -0.9, z);
      glColor3f(0,0,.7); 
      glVertex3f( 0.0,  0.9, z);
      glEnd();
      
      glColor3f(1,1,1);

      glViewport( 0, 0, WinWidth, WinHeight );
      glMatrixMode( GL_PROJECTION );
      glLoadIdentity();
      glOrtho( 0.0, WinWidth, 0.0, WinHeight, -1.0, 1.0 );
   }

   /* might try alignment=4 here for testing */
   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   glPixelStorei(GL_PACK_ALIGNMENT, 1);

   /* do readpixels, drawpixels */
   glRasterPos2i(BPosX, 5);
   PrintString("Read/DrawPixels");
   SetupPixelTransfer(ScaleAndBias);
   if (Benchmark) {
      GLint reads = 0;
      GLint endTime;
      GLint startTime = glutGet(GLUT_ELAPSED_TIME);
      GLdouble seconds, mpixels, mpixelsPerSecond;
      printf("Benchmarking...\n");
      do {
         glReadPixels(APosX, APosY, ImgWidth, ImgHeight,
                      ReadFormat, ReadType, TempImage);
         reads++;
         endTime = glutGet(GLUT_ELAPSED_TIME);
      } while (endTime - startTime < 4000);   /* 4 seconds */
      seconds = (double) (endTime - startTime) / 1000.0;
      mpixels = reads * (ImgWidth * ImgHeight / (1000.0 * 1000.0));
      mpixelsPerSecond = mpixels / seconds;
      printf("Result:  %d reads in %f seconds = %f Mpixels/sec\n",
             reads, seconds, mpixelsPerSecond);
      Benchmark = GL_FALSE;
   }
   else {
      /* clear the temporary image to white (helpful for debugging */
      memset(TempImage, 255, ImgWidth * ImgHeight * 4);
#if 1
      glReadPixels(APosX, APosY, ImgWidth, ImgHeight,
                   ReadFormat, ReadType, TempImage);
      (void) ComplexReadPixels;
#else
      /* you might use this when debugging */
      ComplexReadPixels(APosX, APosY, ImgWidth, ImgHeight,
                        ReadFormat, ReadType, TempImage);
#endif
   }
   glRasterPos2i(BPosX, BPosY);
   glDisable(GL_DITHER);
   SetupPixelTransfer(GL_FALSE);
   glDrawPixels(ImgWidth, ImgHeight, ReadFormat, ReadType, TempImage);

   /* do copypixels */
   glRasterPos2i(CPosX, 5);
   PrintString("CopyPixels");
   glRasterPos2i(CPosX, CPosY);
   glDisable(GL_DITHER);
   SetupPixelTransfer(ScaleAndBias);
   glCopyPixels(APosX, APosY, ImgWidth, ImgHeight, GL_COLOR);

   if (!DrawFront)
      glutSwapBuffers();
   else
      glFinish();
}
void
eventLoop (void)
{
    XEvent	   event;
    struct pollfd  ufd;
    int		   timeDiff;
    struct timeval tv;
    Region	   tmpRegion;
    CompDisplay    *display = compDisplays;
    CompScreen	   *s = display->screens;
    int		   timeToNextRedraw = 0;
    CompWindow	   *move = 0;
    int		   px = 0, py = 0;
    CompTimeout    *t;

    tmpRegion = XCreateRegion ();
    if (!tmpRegion)
    {
	fprintf (stderr, "%s: Couldn't create region\n", programName);
	return;
    }

    ufd.fd = ConnectionNumber (display->display);
    ufd.events = POLLIN;

    for (;;)
    {
	if (display->dirtyPluginList)
	    updatePlugins (display);

	if (restartSignal)
	{
	     execvp (programName, programArgv);
	     exit (1);
	}

	while (XPending (display->display))
	{
	    XNextEvent (display->display, &event);

	    /* translate root window */
	    if (testMode)
	    {
		Window root, child;

		switch (event.type) {
		case ButtonPress:
		    if (!move)
		    {
			px = event.xbutton.x;
			py = event.xbutton.y;

			move = findWindowAt (display, event.xbutton.window,
					     px, py);
			if (move)
			{
			    XRaiseWindow (display->display, move->id);
			    continue;
			}
		    }
		case ButtonRelease:
		    move = 0;

		    root = translateToRootWindow (display,
						  event.xbutton.window);
		    XTranslateCoordinates (display->display,
					   event.xbutton.root, root,
					   event.xbutton.x_root,
					   event.xbutton.y_root,
					   &event.xbutton.x_root,
					   &event.xbutton.y_root,
					   &child);
		    event.xbutton.root = root;
		    break;
		case KeyPress:
		case KeyRelease:
		    root = translateToRootWindow (display, event.xkey.window);
		    XTranslateCoordinates (display->display,
					   event.xkey.root, root,
					   event.xkey.x_root,
					   event.xkey.y_root,
					   &event.xkey.x_root,
					   &event.xkey.y_root,
					   &child);
		    event.xkey.root = root;
		    break;
		case MotionNotify:
		    if (move)
		    {
			XMoveWindow (display->display, move->id,
				     move->attrib.x + event.xbutton.x - px,
				     move->attrib.y + event.xbutton.y - py);

			px = event.xbutton.x;
			py = event.xbutton.y;
			continue;
		    }

		    root = translateToRootWindow (display,
						  event.xmotion.window);
		    XTranslateCoordinates (display->display,
					   event.xmotion.root, root,
					   event.xmotion.x_root,
					   event.xmotion.y_root,
					   &event.xmotion.x_root,
					   &event.xmotion.y_root,
					   &child);
		    event.xmotion.root = root;
		default:
		    break;
		}
	    }

	    /* add virtual modifiers */
	    switch (event.type) {
	    case ButtonPress:
		event.xbutton.state |= CompPressMask;
		event.xbutton.state =
		    realToVirtualModMask (display, event.xbutton.state);
		break;
	    case ButtonRelease:
		event.xbutton.state |= CompReleaseMask;
		event.xbutton.state =
		    realToVirtualModMask (display, event.xbutton.state);
		break;
	    case KeyPress:
		event.xkey.state |= CompPressMask;
		event.xkey.state = realToVirtualModMask (display,
							 event.xkey.state);
		break;
	    case KeyRelease:
		event.xkey.state |= CompReleaseMask;
		event.xkey.state = realToVirtualModMask (display,
							 event.xkey.state);
		break;
	    case MotionNotify:
		event.xmotion.state =
		    realToVirtualModMask (display, event.xmotion.state);
		break;
	    default:
		break;
	    }

	    (*display->handleEvent) (display, &event);
	}

	if (s->allDamaged || REGION_NOT_EMPTY (s->damage))
	{
	    if (timeToNextRedraw == 0)
	    {
		/* wait for X drawing requests to finish
		   glXWaitX (); */

		gettimeofday (&tv, 0);

		timeDiff = TIMEVALDIFF (&tv, &s->lastRedraw);

		(*s->preparePaintScreen) (s, timeDiff);

		if (s->allDamaged)
		{
		    EMPTY_REGION (s->damage);
		    s->allDamaged = 0;

		    (*s->paintScreen) (s,
				       &defaultScreenPaintAttrib,
				       &defaultWindowPaintAttrib,
				       &s->region,
				       PAINT_SCREEN_REGION_MASK |
				       PAINT_SCREEN_FULL_MASK);

		    glXSwapBuffers (s->display->display, s->root);
		}
		else
		{
		    XIntersectRegion (s->damage, &s->region, tmpRegion);

		    EMPTY_REGION (s->damage);

		    if ((*s->paintScreen) (s,
					   &defaultScreenPaintAttrib,
					   &defaultWindowPaintAttrib,
					   tmpRegion,
					   PAINT_SCREEN_REGION_MASK))
		    {
			BoxPtr pBox;
			int    nBox, y;

			glEnable (GL_SCISSOR_TEST);
			glDrawBuffer (GL_FRONT);

			pBox = tmpRegion->rects;
			nBox = tmpRegion->numRects;
			while (nBox--)
			{
			    y = s->height - pBox->y2;

			    glBitmap (0, 0, 0, 0,
				      pBox->x1 - s->rasterX, y - s->rasterY,
				      NULL);

			    s->rasterX = pBox->x1;
			    s->rasterY = y;

			    glScissor (pBox->x1, y,
				       pBox->x2 - pBox->x1,
				       pBox->y2 - pBox->y1);

			    glCopyPixels (pBox->x1, y,
					  pBox->x2 - pBox->x1,
					  pBox->y2 - pBox->y1,
					  GL_COLOR);

			    pBox++;
			}

			glDrawBuffer (GL_BACK);
			glDisable (GL_SCISSOR_TEST);
			glFlush ();
		    }
		    else
		    {
			(*s->paintScreen) (s,
					   &defaultScreenPaintAttrib,
					   &defaultWindowPaintAttrib,
					   &s->region,
					   PAINT_SCREEN_FULL_MASK);

			glXSwapBuffers (s->display->display, s->root);
		    }
		}

		s->lastRedraw = tv;

		(*s->donePaintScreen) (s);

		/* remove destroyed windows */
		while (s->pendingDestroys)
		{
		    CompWindow *w;

		    for (w = s->windows; w; w = w->next)
		    {
			if (w->destroyed)
			{
			    addWindowDamage (w);
			    removeWindow (w);
			    break;
			}
		    }

		    s->pendingDestroys--;
		}
	    }

	    timeToNextRedraw = getTimeToNextRedraw (s, &s->lastRedraw);
	    if (timeToNextRedraw)
		timeToNextRedraw = poll (&ufd, 1, timeToNextRedraw);
	}
	else
	{
	    if (timeouts)
	    {
		if (timeouts->left > 0)
		    poll (&ufd, 1, timeouts->left);

		gettimeofday (&tv, 0);

		timeDiff = TIMEVALDIFF (&tv, &lastTimeout);

		for (t = timeouts; t; t = t->next)
		    t->left -= timeDiff;

		while (timeouts && timeouts->left <= 0)
		{
		    t = timeouts;
		    if ((*t->callBack) (t->closure))
		    {
			timeouts = t->next;
			addTimeout (t);
		    }
		    else
		    {
			timeouts = t->next;
			free (t);
		    }
		}

		s->lastRedraw = lastTimeout = tv;
	    }
	    else
	    {
		poll (&ufd, 1, 1000);
		gettimeofday (&s->lastRedraw, 0);
	    }

	    /* just redraw immediately */
	    timeToNextRedraw = 0;
	}
    }
}
/* Draw several things that should generate fragments, each within an
 * occlusion query. Then verify that each query returns a non-zero
 * value.
 */
enum piglit_result
piglit_display(void)
{
	/* 2x2 data: Red, Green, Blue, and White. */
	float data[16] = { 1.0, 0.0, 0.0,
			   0.0, 1.0, 0.0,
			   0.0, 0.0, 1.0,
			   1.0, 1.0, 1.0 };
	GLubyte bitmap[16] = { 0x5f, 0xff, 0xff, 0xff,
			       0xAf, 0xff, 0xff, 0xff,
			       0x5f, 0xff, 0xff, 0xff,
			       0xAf, 0xff, 0xff, 0xff };
	GLuint query;
	int test_pass = 1;

	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);

	glClearColor(0.0, 1.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glGenQueries(1, &query);

	/* Fragments for glDrawPixels
	 *
	 * Assuming one fragment per pixel based on:
	 *
	 * 	Rectangles of color, depth, and certain
	 *	other values may be converted to fragments
	 *	using the DrawPixels command. [OpenGL 3.0 § 3.7]
	 */
	glBeginQuery(GL_SAMPLES_PASSED, query);
	{
		glRasterPos2i(2, 2);
		glDrawPixels(2, 2, GL_RGB, GL_FLOAT, data);
	}
	glEndQuery(GL_SAMPLES_PASSED);
	test_pass &= verify_fragments(query, "glDrawPixels", 4);

	/* Fragments for glCopyPixels
	 *
	 * And here, CopyPixels is specified to behave
	 * identically to DrawPixels:
	 *
	 *	The groups of elements so obtained are then
	 *	written to the framebuffer just as if
	 *	DrawPixels had been given width and height,
	 *	beginning with final conversion of elements.
	 *	[OpenGL 3.0 § 4.3.3]
	 */
	glBeginQuery(GL_SAMPLES_PASSED, query);
	{
		glRasterPos2i(6, 2);
		glCopyPixels(2, 2, 2, 2, GL_COLOR);
	}
	glEndQuery(GL_SAMPLES_PASSED);
	test_pass &= verify_fragments(query, "glCopyPixels", 4);

	/* Fragments for glBitmap.
	 *
	 * The specification implies very strongly that a bitmap
	 * should generate one fragment per set bit:
	 *
	 * 	Bitmaps are rectangles of zeros and ones
	 *	specifying a particular pattern of frag-
	 *	ments to be produced. [OpenGL 3.0 § 3.8]
	 */
	glBeginQuery(GL_SAMPLES_PASSED, query);
	{
		glRasterPos2i(10, 2);
		glColor4f(0.0, 0.0, 1.0, 0.0);
		glBitmap(4, 4, 0, 0, 0, 0, bitmap);
	}
	glEndQuery(GL_SAMPLES_PASSED);
	test_pass &= verify_fragments(query, "glBitmap", 8);

	glDeleteQueries(1, &query);

	piglit_present_results();

	return test_pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Beispiel #28
0
static void
Display( void )
{
    glClearColor(.3, .3, .3, 1);
    glClear( GL_COLOR_BUFFER_BIT );

    glRasterPos2i(5, ImgHeight+25);
    PrintString("f = toggle front/back  s = toggle scale/bias  b = benchmark");

    /* draw original image */
    glRasterPos2i(APosX, 5);
    PrintString("Original");
    glRasterPos2i(APosX, APosY);
    glEnable(GL_DITHER);
    SetupPixelTransfer(GL_FALSE);
    glDrawPixels(ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image);

    /* do readpixels, drawpixels */
    glRasterPos2i(BPosX, 5);
    PrintString("Read/DrawPixels");
    SetupPixelTransfer(ScaleAndBias);
    if (Benchmark) {
        GLint reads = 0;
        GLint endTime;
        GLint startTime = glutGet(GLUT_ELAPSED_TIME);
        GLdouble seconds, pixelsPerSecond;
        printf("Benchmarking...\n");
        do {
            glReadPixels(APosX, APosY, ImgWidth, ImgHeight,
                         ReadFormat, ReadType, TempImage);
            reads++;
            endTime = glutGet(GLUT_ELAPSED_TIME);
        } while (endTime - startTime < 4000);   /* 4 seconds */
        seconds = (double) (endTime - startTime) / 1000.0;
        pixelsPerSecond = reads * ImgWidth * ImgHeight / seconds;
        printf("Result:  %d reads in %f seconds = %f pixels/sec\n",
               reads, seconds, pixelsPerSecond);
        Benchmark = GL_FALSE;
    }
    else {
        /* clear the temporary image to white (helpful for debugging */
        memset(TempImage, 255, ImgWidth * ImgHeight * 4);
        glReadPixels(APosX, APosY, ImgWidth, ImgHeight,
                     ReadFormat, ReadType, TempImage);
    }
    glRasterPos2i(BPosX, BPosY);
    glDisable(GL_DITHER);
    SetupPixelTransfer(GL_FALSE);
    glDrawPixels(ImgWidth, ImgHeight, ReadFormat, ReadType, TempImage);

    /* do copypixels */
    glRasterPos2i(CPosX, 5);
    PrintString("CopyPixels");
    glRasterPos2i(CPosX, CPosY);
    glDisable(GL_DITHER);
    SetupPixelTransfer(ScaleAndBias);
    glCopyPixels(APosX, APosY, ImgWidth, ImgHeight, GL_COLOR);

    if (!DrawFront)
        glutSwapBuffers();
    else
        glFinish();
}
Beispiel #29
0
static void
display(void)
{
  int i;

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  if (textureEnabled) {
    if (mode == MoveTexture || mode == MoveView) {
      /* Have OpenGL compute the new transformation (simple but slow). */
      for (i = 0; i < NumTextures; i++) {
        glPushMatrix();
        glLoadIdentity();
#if 0
        if (i & 1)
           glRotatef(angle, axis[0], axis[1], axis[2]);
        else
#endif
           glRotatef(angle*(i+1), axis[0], axis[1], axis[2]);

        glMultMatrixf((GLfloat *) textureXform[i]);
        glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat *) textureXform[i]);
        glPopMatrix();
      }
    }
    for (i = 0; i < NumTextures; i++) {
       loadTextureProjection(i, (GLfloat *) textureXform[i]);
    }

    if (showProjection) {
      for (i = 0; i < NumTextures; i++) {
        ActiveTexture(GL_TEXTURE0_ARB + i);
        glPushMatrix();
        glMultMatrixf((GLfloat *) textureXform[i]);
        glDisable(GL_LIGHTING);
        drawTextureProjection();
        glEnable(GL_LIGHTING);
        glPopMatrix();
      }
    }
    for (i = 0; i < NumTextures; i++) {
      ActiveTexture(GL_TEXTURE0_ARB + i);
      glEnable(GL_TEXTURE_2D);
      glEnable(GL_TEXTURE_GEN_S);
      glEnable(GL_TEXTURE_GEN_T);
      glEnable(GL_TEXTURE_GEN_R);
      glEnable(GL_TEXTURE_GEN_Q);
    }
  }
  if (mode == MoveObject || mode == MoveView) {
    /* Have OpenGL compute the new transformation (simple but slow). */
    glPushMatrix();
    glLoadIdentity();
    glRotatef(angle, axis[0], axis[1], axis[2]);
    glMultMatrixf((GLfloat *) objectXform);
    glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat *) objectXform);
    glPopMatrix();
  }
  glPushMatrix();
  glMultMatrixf((GLfloat *) objectXform);
  (*drawObject) ();
  glPopMatrix();

  for (i = 0; i < NumTextures; i++) {
    ActiveTexture(GL_TEXTURE0_ARB + i);
    glDisable(GL_TEXTURE_2D);
    glDisable(GL_TEXTURE_GEN_S);
    glDisable(GL_TEXTURE_GEN_T);
    glDisable(GL_TEXTURE_GEN_R);
    glDisable(GL_TEXTURE_GEN_Q);
  }

  if (zoomFactor > 1.0) {
    glDisable(GL_DEPTH_TEST);
    glCopyPixels(0, 0, winWidth / zoomFactor, winHeight / zoomFactor, GL_COLOR);
    glEnable(GL_DEPTH_TEST);
  }
  glFlush();
  glutSwapBuffers();
  checkErrors();
}
Beispiel #30
0
void compute_matte(void)
{
  glClear(GL_ACCUM_BUFFER_BIT);

  /* draw rectangle in (key color + 1) / 2 */
  glBegin(GL_QUADS);
  glColor3f(key[0], key[1], key[2]);
  glVertex2f(0, 0);
  glVertex2f(w, 0);
  glVertex2f(w, h);
  glVertex2f(0, h);
  glEnd();
  glFlush();

  /* negate & accumulate  */
  glAccum(GL_LOAD, -1);

  /* compute & return (image - key) */
  glRasterPos2f(0, 0);
  glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, img0);
  glAccum(GL_ACCUM, 1);
  glAccum(GL_RETURN, 1);

  /* move to right hand side of window */
  glRasterPos2f(w, 0);
  glCopyPixels(0, 0, w, h, GL_COLOR);

  /* compute & return (key - image) */
  glEnable(GL_SCISSOR_TEST);
  glScissor(0, 0, w, h);
  glAccum(GL_MULT, -1);
  glAccum(GL_RETURN, 1);
  glScissor(0, 0, 2*w, h);
  glDisable(GL_SCISSOR_TEST);

  /* assemble to get fabs(key - image) */
  glBlendFunc(GL_ONE, GL_ONE);
  glEnable(GL_BLEND);
  glRasterPos2i(0, 0);
  glCopyPixels(w, 0, w, h, GL_COLOR);
  glDisable(GL_BLEND);

  /* assemble into alpha channel */
  {
    GLfloat mat[] = {
      RW, RW, RW, RW,
      GW, GW, GW, GW,
      BW, BW, BW, BW,
      0, 0, 0, 0,
    };
    glMatrixMode(GL_COLOR);
    glLoadMatrixf(mat);

    glRasterPos2i(w, 0);
    glCopyPixels(0, 0, w, h, GL_COLOR);
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);

    /* do a second copy because sbias comes after color matrix in the
     * transfer pipeline.  could avoid this by using the post color matrix
     * scale bias... */
    if (upperfudge - lowerfudge) {
      glPixelTransferf(GL_ALPHA_SCALE, 1./(upperfudge - lowerfudge));
      glPixelTransferf(GL_ALPHA_BIAS, -lowerfudge/(upperfudge - lowerfudge)); 
    } else {
      /* move such that upper/lowerfudge maps to .5, then quantize with
       * 2-entry pixel map. */
      GLushort quantize[] = {0, 0xffff};
      glPixelTransferf(GL_ALPHA_BIAS, .5 - upperfudge);
      glPixelMapusv(GL_PIXEL_MAP_A_TO_A, 2, quantize);
      glPixelTransferi(GL_MAP_COLOR, 1);
    }
    glRasterPos2i(w, 0);
    glCopyPixels(w, 0, w, h, GL_COLOR);
    glPixelTransferf(GL_ALPHA_SCALE,  1);
    glPixelTransferf(GL_ALPHA_BIAS, 0);
    glPixelTransferi(GL_MAP_COLOR, 0);
  }


  /* copy matte to right */
  glRasterPos2i(0, 0);
  glCopyPixels(w, 0, w, h, GL_COLOR);

  /* draw the third image */
  glColorMask(1, 1, 1, 0);
  glRasterPos2i(w, 0);
  glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, img2);
  glColorMask(1, 1, 1, 1);

  glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);
  glEnable(GL_BLEND);
  glRasterPos2i(w, 0);
  glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, img1);

  /* this is for matte display... */
  glColor3f(1, 1, 1);
  glBegin(GL_QUADS);
  glVertex2f(0, 0);
  glVertex2f(w, 0);
  glVertex2f(w, h);
  glVertex2f(0, h);
  glEnd();

  glDisable(GL_BLEND);
}