/** Show contents of depth buffer in middle of window */
static void
show_depth_fbo(void)
{
   GLfloat *zf;

   glViewport(1 * SIZE, 0, SIZE, SIZE); /* not really needed */

   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FBO);
   zf = read_float_z_image(0, 0);

   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo);

   glWindowPos2i(SIZE, 0);
   glDrawPixels(SIZE, SIZE, GL_LUMINANCE, GL_FLOAT, zf);
   if (!piglit_check_gl_error(GL_NO_ERROR))
	    piglit_report_result(PIGLIT_FAIL);

#if DEBUG
   {
      GLfloat min, max, center;
      find_float_min_max_center(zf, SIZE * SIZE, &min, &max, &center);
      printf("depth fbo min %f  max %f  center %f\n", min, max, center);
   }

   {
      GLuint min, max, center;
      GLuint *zi;

      glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FBO);
      zi = read_uint_z_image(0, 0);
      glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo);

      find_uint_min_max_center(zi, SIZE * SIZE, &min, &max, &center);
      printf("depth fbo min 0x%x  max 0x%x  center 0x%x\n", min, max, center);
      free(zi);
   }
#endif /* DEBUG */

   free(zf);
}
示例#2
0
void copyDepthToColor(GLenum whichColorBuffer)
{
    int		x, y;
    GLfloat	max, min;
    GLint	previousColorBuffer;

    glReadPixels(0, 0, winWidth, winHeight, GL_DEPTH_COMPONENT, GL_FLOAT,
        depthSave);

    /* I'm sure this could be done much better with OpenGL */
    max = 0;
    min = 1;
    for(y = 0; y < winHeight; y++)
	for(x = 0; x < winWidth; x++) {
	    if(depthSave[winWidth * y + x] < min)
		min = depthSave[winWidth * y + x];
	    if(depthSave[winWidth * y + x] > max && depthSave[winWidth * y + x] < .999)
		max = depthSave[winWidth * y + x];
	}

    for(y = 0; y < winHeight; y++)
	for(x = 0; x < winWidth; x++) {
	    if(depthSave[winWidth * y + x] <= max)
		depthSave[winWidth * y + x] = 1 -  (depthSave[winWidth * y + x] - min) / (max - min);
	    else
		depthSave[winWidth * y + x] = 0;
	}

    pushOrthoView(0, 1, 0, 1, 0, 1);
    glRasterPos3f(0, 0, -.5);
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_STENCIL_TEST);
    glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
    glGetIntegerv(GL_DRAW_BUFFER, &previousColorBuffer);
    glDrawBuffer(whichColorBuffer);
    glDrawPixels(winWidth, winHeight, GL_LUMINANCE , GL_FLOAT, depthSave);
    glDrawBuffer(previousColorBuffer);
    glEnable(GL_DEPTH_TEST);
    popView();
}
示例#3
0
void GLGSRender::Flip()
{
	if(m_read_buffer)
	{
		gcmBuffer* buffers = (gcmBuffer*)Memory.GetMemFromAddr(m_gcm_buffers_addr);
		u32 width = re(buffers[m_gcm_current_buffer].width);
		u32 height = re(buffers[m_gcm_current_buffer].height);
		u32 addr = GetAddress(re(buffers[m_gcm_current_buffer].offset), CELL_GCM_LOCATION_LOCAL);

		glRotated(90, 1, 0, 0);

		if(Memory.IsGoodAddr(addr))
		{
			//TODO
			//buffer rotating
			static Array<u8> pixels;
			pixels.SetCount(width * height * 4);
			u8* src = (u8*)Memory.VirtualToRealAddr(addr);

			for(u32 y=0; y<height; ++y)
			{
				memcpy(pixels + (height - y - 1) * width * 4, src + y * width * 4, width * 4);
			}

			glDrawPixels(width, height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, pixels.GetPtr());
		}
	}
	else if(m_fbo.IsCreated())
	{
		m_fbo.Bind(GL_READ_FRAMEBUFFER);
		GLfbo::Bind(GL_DRAW_FRAMEBUFFER, 0);
		GLfbo::Blit(
			m_surface_clip_x, m_surface_clip_y, m_surface_clip_x + m_surface_clip_w, m_surface_clip_y + m_surface_clip_h,
			m_surface_clip_x, m_surface_clip_y, m_surface_clip_x + m_surface_clip_w, m_surface_clip_y + m_surface_clip_h,
			GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
		m_fbo.Bind();
	}

	m_frame->Flip();
}
示例#4
0
void ocpnDC::GLDrawBlendData( wxCoord x, wxCoord y, wxCoord w, wxCoord h, int format,
        const unsigned char *data )
{
    /*  Hmmmm.... I find that the texture version below does not work on my dodgy OpenChrome gl drivers
     but the glDrawPixels works fine.*/

    glEnable( GL_BLEND );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
    glRasterPos2i( x, y );
    glPixelZoom( 1, -1 );
    glDrawPixels( w, h, format, GL_UNSIGNED_BYTE, data );
    glPixelZoom( 1, 1 );
    glDisable( GL_BLEND );

    return;

    /* I would prefer to just use glDrawPixels than need a texture,
     but sometimes it did not perform alpha blending correctly,
     this way always works */

#if 0
    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, tex);
    glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, format, w, h, 0, format,
            GL_UNSIGNED_BYTE, data);

    glEnable(GL_TEXTURE_RECTANGLE_ARB);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    glBegin(GL_QUADS);
    glTexCoord2f(0, 0); glVertex2f(x, y);
    glTexCoord2f(w, 0); glVertex2f(x+w, y);
    glTexCoord2f(w, h); glVertex2f(x+w, y+h);
    glTexCoord2f(0, h); glVertex2f(x, y+h);
    glEnd();
    glDisable(GL_BLEND);
    glDisable(GL_TEXTURE_RECTANGLE_ARB);

#endif
}
示例#5
0
/*
 * Copy the alpha channel values into the current color buffer as a
 * grayscale image.
 * Input:  winWidth, winHeight - size of the window
 */
void
ShowAlphaBuffer( GLsizei winWidth, GLsizei winHeight )
{
   GLubyte *alphaValues;

   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   glPixelStorei(GL_PACK_ALIGNMENT, 1);

   /* Read alpha values */
   alphaValues = (GLubyte *) malloc(winWidth * winHeight * sizeof(GLubyte));
   assert(alphaValues);
   glReadPixels(0, 0, winWidth, winHeight, GL_ALPHA, GL_UNSIGNED_BYTE, alphaValues);

   /* save GL state */
   glPushAttrib(GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL |
                GL_TRANSFORM_BIT | GL_VIEWPORT_BIT);

   /* setup raster pos for glDrawPixels */
   glMatrixMode(GL_PROJECTION);
   glPushMatrix();
   glLoadIdentity();

   glOrtho(0.0, (GLdouble) winWidth, 0.0, (GLdouble) winHeight, -1.0, 1.0);
   glMatrixMode(GL_MODELVIEW);
   glPushMatrix();
   glLoadIdentity();

   glDisable(GL_STENCIL_TEST);
   glDisable(GL_DEPTH_TEST);
   glRasterPos2f(0, 0);

   glDrawPixels(winWidth, winHeight, GL_LUMINANCE, GL_UNSIGNED_BYTE, alphaValues);

   glPopMatrix();
   glMatrixMode(GL_PROJECTION);
   glPopMatrix();
   free(alphaValues);

   glPopAttrib();
}
示例#6
0
static void
Display( void )
{
   GLubyte *buffer = malloc(Width * Height * 4);
   GLenum status;

   /* draw to user framebuffer */
   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB);
   glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
   glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);

   status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
   if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
      printf("Framebuffer incomplete!!!\n");
   }

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

   glBegin(GL_POLYGON);
   glColor3f(1, 0, 0);
   glVertex2f(-1, -1);
   glColor3f(0, 1, 0);
   glVertex2f(1, -1);
   glColor3f(0, 0, 1);
   glVertex2f(0, 1);
   glEnd();

   /* read from user framebuffer */
   glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);

   /* draw to window */
   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
   glWindowPos2iARB(0, 0);
   glDrawPixels(Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);

   free(buffer);
   glutSwapBuffers();
   CheckError(__LINE__);
}
示例#7
0
enum piglit_result
piglit_display(void)
{
	GLubyte stencil_rect[20 * 20];
	int i;
	GLboolean pass = GL_TRUE;
	static float red[] = {1.0, 0.0, 0,0, 0.0};
	static float black[] = {0.0, 0.0, 0,0, 0.0};

	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);

	glClearStencil(0);
	glClearDepth(1.0);
	glClearColor(0.0, 0.0, 0.0, 0.0);
	glDisable(GL_DITHER);
	glPixelStorei(GL_UNPACK_ROW_LENGTH, 20);

	for (i=0; i<20*20; i++)
		if (i < 20*20/2)
			stencil_rect[i] = 1;
		else
			stencil_rect[i] = 0;


	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
	glEnable(GL_STENCIL_TEST);
	glStencilFunc(GL_LESS, 0, (GLuint)~0);
	glRasterPos2i(50, 50);
	glDrawPixels(20, 20, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, stencil_rect);
	glColor3f(1.0, 0.0, 0.0);
	glRectf(50, 50, 50+20, 50+20);
	glDisable(GL_STENCIL_TEST);

	pass &= piglit_probe_rect_rgb(50, 50, 20, 10, red);
	pass &= piglit_probe_rect_rgb(50, 60, 20, 10, black);

	piglit_present_results();

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
示例#8
0
static bool
check_rendering(void)
{
   const GLfloat x0 = 0.0, x1 = piglit_width - 10.0, dx = 20.0;
   const GLint iy = piglit_height / 2;
   bool draw = true;
   GLfloat x;

   if (!piglit_probe_pixel_rgb(0, 0, black)) {
      return false;
   }

   for (x = x0 + 0.5 * dx; x < x1; x += dx) {
      bool pass;
      const int ix = (int) x;

      if (draw) {
         /* there should be triangle drawing here */
         pass = piglit_probe_pixel_rgb(ix, iy, green);
      }
      else {
         /* there should not be triangle drawing here */
         pass = piglit_probe_pixel_rgb(ix, iy, black);
      }

      /* debug */
      if (0) {
         glWindowPos2i(ix, iy);
         glDrawPixels(1, 1, GL_RGBA, GL_FLOAT, red);
      }

      if (!pass) {
         return false;
      }

      draw = !draw;
   }

   return true;
}
示例#9
0
  void displayFunc(void) 
  {
    AffineSpace3fa pixel2world = g_camera.pixel2world(g_width,g_height);

    /* render image using ISPC */
    double t0 = getSeconds();
    render(g_time0-t0,
           pixel2world.l.vx,
           -pixel2world.l.vy,
           pixel2world.l.vz+g_height*pixel2world.l.vy,
           pixel2world.p);

    double dt0 = getSeconds()-t0;

    if (g_display) 
    {
      /* draw pixels to screen */
      int* pixels = map();
      //glRasterPos2i(-1, 1);
      //glPixelZoom(1.0f, -1.0f);
      glDrawPixels(g_width,g_height,GL_RGBA,GL_UNSIGNED_BYTE,pixels);
      glutSwapBuffers();
      unmap();
    }
    double dt1 = getSeconds()-t0;

    /* print frame rate */
    std::ostringstream stream;
    stream.setf(std::ios::fixed, std::ios::floatfield);
    stream.precision(2);
    stream << "render: ";
    stream << 1.0f/dt0 << " fps, ";
    stream << dt0*1000.0f << " ms, ";
    stream << "display: ";
    stream << 1.0f/dt1 << " fps, ";
    stream << dt1*1000.0f << " ms, ";
    stream << g_width << "x" << g_height << " pixels";
    std::cout << stream.str() << std::endl;
  }
示例#10
0
void displayFunc(void) {

	const float *pixels = film->GetScreenBuffer();

	glRasterPos2i(0, 0);

	glDrawPixels(film->GetWidth(), film->GetHeight(), GL_RGB, GL_FLOAT, pixels);

//	PrintCaptions();

	if (printHelp) {
		glPushMatrix();
		glLoadIdentity();
		glOrtho(-0.5, 639.5, -0.5, 479.5, -1.0, 1.0);



		glPopMatrix();
	}

	glutSwapBuffers();
}
示例#11
0
void
renderSplat(SplatInfo *splat)
{
    glRasterPos2i(splat->x, splat->y);
    if(splat->yScale >= 0)
      glBitmap(0, 0, 0, 0, 0, -logo_height * splat->yScale, 0);
    if(splat->xScale < 0)
      glBitmap(0, 0, 0, 0, logo_width * -splat->xScale, 0, 0);
    glPixelZoom(splat->xScale, splat->yScale);
    glPixelTransferf(GL_RED_SCALE, splat->scale[0]);
    glPixelTransferf(GL_GREEN_SCALE, splat->scale[1]);
    glPixelTransferf(GL_BLUE_SCALE, splat->scale[2]);
    glPixelTransferf(GL_RED_BIAS, splat->bias[0]);
    glPixelTransferf(GL_GREEN_BIAS, splat->bias[1]);
    glPixelTransferf(GL_BLUE_BIAS, splat->bias[2]);
    if (splat->alphaTest) 
      glEnable(GL_ALPHA_TEST);
    else
      glDisable(GL_ALPHA_TEST);
    glDrawPixels(logo_width, logo_height, GL_RGBA,
      GL_UNSIGNED_BYTE, logo_image);
}
示例#12
0
文件: LuaGL10.cpp 项目: jaquadro/XLua
	/* void glDrawPixels (GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* data)
	 *
	 * DrawPixels (width, height, format, type, data) -> None
	 */
	int gl_draw_pixels (lua_State* L) {
		
		if (!(	lua_isnumber(L, 1) &&				// width
				lua_isnumber(L, 2) &&				// height
				lua_isnumber(L, 3) &&				// format
				lua_isnumber(L, 4) &&				// type
				(lua_istable(L, 5) || lua_isuserdata(L, 5) || lua_isnumber(L, 5))	// data
			)) {
			luaL_error(L, "Incorrect argument to function gl.DrawPixels");
		}

		GLsizei width = lua_tointeger(L, 1);
		GLsizei height = lua_tointeger(L, 2);
		GLint format = lua_tointeger(L, 3);
		GLint type = lua_tointeger(L, 4);
		const void* data = 0;

		if (lua_isuserdata(L, 5)) {
			data = GLCommon::get2DPixelsFromSA(L, 5, width, height, format, type, "gl.DrawPixels");
		}
		else if (lua_istable(L, 5)) {
			data = GLCommon::get2DPixelsFromTable(L, 5, width, height, format, type, "gl.DrawPixels");
		}
		else {
			GLint pixbuf = 0;
			glGetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING, &pixbuf);
			if (pixbuf)
				data = (const void*)lua_tointeger(L, 5);
			else
				luaL_error(L, "Buffer offset used with unbound buffer in gl.DrawPixels");
		}

		glDrawPixels(width, height, format, type, data);

		if (lua_istable(L, 8))
			delete[] data;

		return 0;
	}
//--------------------------------------------------------------------------------
void ofxCvImage::draw( float x, float y, float w, float h ) {
    if( bUseTexture ) {
    	updateTexture();
        tex.draw(x,y, w,h);
    } else {
        #ifdef TARGET_OPENGLES
            ofLog(OF_LOG_ERROR, "texture-less drawing not supported in OpenGL ES");
        #else
            // this is slower than the typical draw method based on textures
            // but useful when dealing with threads GL textures often don't work
            ofLog(OF_LOG_NOTICE, "in draw, using slow texture-less drawing");
            ofLog(OF_LOG_NOTICE, "texture-less drawing - be aware, unlike texture drawing, \
                              this always draws window aligned, rotation not supported");

            if( x == 0) {
                x += 0.01;
                ofLog(OF_LOG_NOTICE, "BUG: can't draw at x==0 in texture-less mode.");
            }

            if(bAnchorIsPct){
                x -= anchor.x * w;
                y -= anchor.y * h;
            }else{
                x -= anchor.x;
                y -= anchor.y;
            }

            glRasterPos2f( x, y+h );

            IplImage* tempImg;
            tempImg = cvCreateImage( cvSize((int)w, (int)h), ipldepth, iplchannels );
            cvResize( cvImage, tempImg, CV_INTER_NN );
            cvFlip( tempImg, tempImg, 0 );
            glDrawPixels( tempImg->width, tempImg->height ,
                          glchannels, gldepth, tempImg->imageData );
            cvReleaseImage( &tempImg );
        #endif
    }
}
示例#14
0
void XyzWindow::DrawXZImage()
{
	//Load data for XZ view
	LoadXZData();
	
	//draw xz view
	float offsetx , offsety;
	if(mZoom < m_OpenZoom){
		offsetx =(wx - mx)/2;
		offsety = (wz - mz)/2;
	}
	else{
		offsetx = 0;
		offsety = 0;
	}
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0,wx, 0, wz, -1,1);
	glPixelZoom(mZoom , mZoom);
	glRasterPos2f(offsetx , offsety);
	glDrawPixels(nx, nz, GL_LUMINANCE, GL_UNSIGNED_BYTE, mFdataxz);
}
示例#15
0
文件: vid.c 项目: btb/d2x
int vid_toggle_fullscreen_menu(void)
{
	unsigned char *buf=NULL;

	if (ogl_readpixels_ok){
		MALLOC(buf,unsigned char,grd_curscreen->sc_w*grd_curscreen->sc_h*3);
		glReadBuffer(GL_FRONT);
		glReadPixels(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
	}

	do_fullscreen(!ogl_fullscreen);

	if (ogl_readpixels_ok){
//		glWritePixels(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
		glRasterPos2f(0,0);
		glDrawPixels(grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
		free(buf);
	}
	//	grd_curscreen->sc_mode=0;//hack to get it to reset screen mode

	return ogl_fullscreen;
}
示例#16
0
void displayFunc(void) {
	session->film->UpdateScreenBuffer();
	const float *pixels = session->film->GetScreenBuffer();

	glRasterPos2i(0, 0);
	glDrawPixels(session->film->GetWidth(), session->film->GetHeight(), GL_RGB, GL_FLOAT, pixels);

	PrintCaptions();

	if (OSDPrintHelp) {
		glPushMatrix();
		glLoadIdentity();
		glOrtho(-0.5f, session->film->GetWidth() - 0.5f,
				-0.5f, session->film->GetHeight() - 0.5f, -1.f, 1.f);

		PrintHelpAndSettings();

		glPopMatrix();
	}

	glutSwapBuffers();
}
示例#17
0
/** Show contents of depth buffer in middle of window */
static void
show_depth_fbo(void)
{
   GLfloat *zf;

   glViewport(1 * SIZE, 0, SIZE, SIZE); /* not really needed */

   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FBO);
   zf = read_float_z_image(0, 0);

   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

   glWindowPos2i(SIZE, 0);
   glDrawPixels(SIZE, SIZE, GL_LUMINANCE, GL_FLOAT, zf);
   assert(glGetError() == 0);

#if DEBUG
   {
      GLfloat min, max, center;
      find_float_min_max_center(zf, SIZE * SIZE, &min, &max, &center);
      printf("depth fbo min %f  max %f  center %f\n", min, max, center);
   }

   {
      GLuint min, max, center;
      GLuint *zi;

      glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FBO);
      zi = read_uint_z_image(0, 0);
      glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

      find_uint_min_max_center(zi, SIZE * SIZE, &min, &max, &center);
      printf("depth fbo min 0x%x  max 0x%x  center 0x%x\n", min, max, center);
      free(zi);
   }
#endif /* DEBUG */

   free(zf);
}
void ofxPBOVideoPlayer::update(){
	player.update();
	if(player.isFrameNew()){
		if(usePBO){
			//cout << "new frame" << endl;
			//time = ofGetElapsedTimeMicros();
			//cout << "time tex" << ofGetElapsedTimeMicros() - time << endl;
			//int time = ofGetElapsedTimeMicros();
			pbo.loadData(player.getPixelsRef());
			//cout << ofGetElapsedTimeMicros() - time << endl;
			updateTex = true;
		}else{
			//int time = ofGetElapsedTimeMicros();
			fbo.begin();
			glDrawPixels(player.getWidth(),player.getHeight(),GL_RGB, GL_UNSIGNED_BYTE, player.getPixels());
			fbo.end();
			//cout << ofGetElapsedTimeMicros() - time << endl;
		}
	}else{
		//cout << "not new frame" << endl;
	}
}
示例#19
0
// display results using OpenGL (called by GLUT)
void display()
{
    sdkStartTimer(&timer);

    render();

    // display results
    glClear(GL_COLOR_BUFFER_BIT);

    // draw image from PBO
    glDisable(GL_DEPTH_TEST);
    glRasterPos2i(0, 0);
    glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
    glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_BYTE, 0);
    glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);

    glutSwapBuffers();
    glutReportErrors();

    sdkStopTimer(&timer);
    computeFPS();
}
示例#20
0
//--------------------------------------------------------------------------------
void ofxCvImage::draw( float x, float y, float w, float h ) const {
    if( bUseTexture ) {
    	ofxCvImage* mutImage = const_cast<ofxCvImage*>(this);
    	mutImage->updateTexture();
        tex.draw(x,y, w,h);
    } else {
        #ifdef TARGET_OPENGLES
            ofLogError("ofxCvImage") << "draw(): textureless drawing mode not supported in OpenGL ES";
        #else
            // this is slower than the typical draw method based on textures
            // but useful when dealing with threads GL textures often don't work
            ofLogNotice("ofxCvImage") << "draw(): using textureless drawing mode";
            ofLogNotice("ofxCvImage") << "draw(): drawing is slower, aligned to the window, & does not support rotation";

            if( x == 0) {
                ofLogNotice("ofxCvImage") << "draw(): x position cannot be 0 in textureless drawing mode, setting to 0.01";
				x += 0.01;
            }

            if(bAnchorIsPct){
                x -= anchor.x * w;
                y -= anchor.y * h;
            }else{
                x -= anchor.x;
                y -= anchor.y;
            }

            glRasterPos2f( x, y+h );

            IplImage* tempImg;
            tempImg = cvCreateImage( cvSize((int)w, (int)h), ipldepth, iplchannels );
            cvResize( cvImage, tempImg, CV_INTER_NN );
            cvFlip( tempImg, tempImg, 0 );
            glDrawPixels( tempImg->width, tempImg->height ,
                          glchannels, gldepth, tempImg->imageData );
            cvReleaseImage( &tempImg );
        #endif
    }
}
示例#21
0
文件: final.c 项目: carmi/comp356
/** Display callback; render the scene.
 */
void handle_display() {
    // The ray itself.
    ray3_t ray;
    ray.base = eye;

    color_t color;

#ifndef NDEBUG
    clock_t start_time, end_time;
    start_time = clock();
#endif
    for (int x=0; x<win_width; ++x) {
        for (int y=0; y<win_height; ++y) {
            win2world(x, y, &ray.dir);
            debug_c((x==400 && y==300),
                "view ray = {(%f, %f, %f), (%f, %f, %f)}.\n",
                eye.x, eye.y, eye.z, 
                ray.dir.x, ray.dir.y, ray.dir.z);
            //Start ray eye assuming we're not inside a transparent surface.
            color = ray_trace(ray, 1.0 + EPSILON, FLT_MAX, 5, false);
            *(fb+fb_offset(y, x, 0)) = color.red;
            *(fb+fb_offset(y, x, 1)) = color.green;
            *(fb+fb_offset(y, x, 2)) = color.blue;
        }
    }
#ifndef NDEBUG
    end_time = clock();
    debug("handle_display(): frame calculation time = %f sec.",
            ((double)(end_time-start_time))/CLOCKS_PER_SEC);
#endif

    // The following line throws a implicit declaration compiler warning: but
    // it was in hw2bp1.c solution file so I will ignore it.
    glWindowPos2s(0, 0);
    glDrawPixels(win_width, win_height, GL_RGB, GL_FLOAT, fb);
    glFlush();
    glutSwapBuffers();
}
示例#22
0
int DisplayBits( PBITMAP pBmp, int x, int y, int width, int height )
{
   GLenum  type;
   int     gly;


   switch ( pBmp->nsamples )
   {
    case 4:
      type = GL_RGBA;
      break;
    case 3:
      type = GL_RGB;
      break;
    case 1:
      if (pBmp->sampleformat==BITMAP_IEEE)
	 type = GL_RGBA;
      else
	 type = GL_LUMINANCE;
      break;
    default:
      return 1;
   }
   gly = pBmp->yres - (y + height);

   glPixelStorei( GL_UNPACK_ROW_LENGTH,  pBmp->xres );
   glPixelStorei( GL_UNPACK_SKIP_ROWS,   gly );
   glPixelStorei( GL_UNPACK_SKIP_PIXELS, x );
   glRasterPos2i( x, gly );
   glDrawPixels( width, height, type, GL_UNSIGNED_BYTE, pBmp->pbits );
   glFlush();
   if (switchbuffer) 
   {
      glXSwapBuffers(dspy,wnd);
   }
   
   return 0;
}
示例#23
0
// Draw the given image, either as a texture quad or glDrawPixels.
// Return true for success, false if GL error detected.
bool
PixelFormatsTest::DrawImage(int width, int height,
                            GLenum format, GLenum type, GLint intFormat,
                            const GLubyte *image) const
{
    if (intFormat) {
        glEnable(GL_TEXTURE_2D);
        glViewport(0, 0, width, height);
        glTexImage2D(GL_TEXTURE_2D, 0, intFormat, width, height, 0,
                     format, type, image);
        if (CheckError("glTexImage2D"))
            return false;
#if USE_FRAG_PROG
        glEnable(GL_FRAGMENT_PROGRAM_ARB);
#endif
        glBegin(GL_POLYGON);
        glTexCoord2f(0, 0);
        glVertex2f(-1, -1);
        glTexCoord2f(1, 0);
        glVertex2f(1, -1);
        glTexCoord2f(1, 1);
        glVertex2f(1, 1);
        glTexCoord2f(0, 1);
        glVertex2f(-1, 1);
        glEnd();
        glDisable(GL_TEXTURE_2D);
#if USE_FRAG_PROG
        glDisable(GL_FRAGMENT_PROGRAM_ARB);
#endif
    }
    else {
        // glDrawPixels
        glDrawPixels(width, height, format, type, image);
        if (CheckError("glDrawPixels"))
            return false;
    }
    return true;
}
示例#24
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);
}
示例#25
0
/**
 * 
 * @param argc
 * @param argv first is input path, second ist output path, third to disable window
 * @return 
 */
int main(int argc, char* argv[]) {
    unsigned const width = 1280;
    unsigned const height = 720;

    std::cout << "welcome to Raytracer ("<< width<<"x"<<height<<")." <<std::endl;
    Renderer* app = nullptr;
    if (argc>1)
        app = new Renderer(width, height, argv[1]);
    else
        app = new Renderer(width, height);

    std::thread thr([&app]() { app->render(); });

    bool nogui=false;
    for (int i = 0; i < argc; i++) {
        if (string(argv[i]).compare("nogui")==0)
            nogui=true;
    }

    if (!nogui){
        Window win(glm::ivec2(width,height));

        while (!win.shouldClose()) {
          if (win.isKeyPressed(GLFW_KEY_ESCAPE)) {
            win.stop();
          }

          glDrawPixels( width, height, GL_RGB, GL_FLOAT
                      , app->colorbuffer().data());

          win.update();
        }
    }
    thr.join();

    delete(app);
    return 0;
}
示例#26
0
void TransferFunctionsViewer::Redraw ()
{
  IupGLMakeCurrent (m_iup_canvas);
  
  vr::TransferFunction *tf = Viewer::Instance ()->m_transfer_function;
  if (tf)
  {
    for (int i = 0; i < 256; i++)
    {
      lqc::Vector4d c = tf->Get (i);
      for (int j = 0; j < 50; j++)
      {
        if (id < 2)
        {
          m_pixels[i * 4 + j * 258 * 4] = c.x;
          m_pixels[i * 4 + j * 258 * 4 + 1] = c.y;
          m_pixels[i * 4 + j * 258 * 4 + 2] = c.z;
          m_pixels[i * 4 + j * 258 * 4 + 3] = 1.0;
        }
        else
        {
          m_pixels[i * 4 + j * 258 * 4] = c.w;
          m_pixels[i * 4 + j * 258 * 4 + 1] = c.w;
          m_pixels[i * 4 + j * 258 * 4 + 2] = c.w;
          m_pixels[i * 4 + j * 258 * 4 + 3] = 1.0;
        }
      }
    }
  }
  
  glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glDrawPixels (258, 50, GL_RGBA, GL_FLOAT, m_pixels);
  
  id = (id + 1) % 4;


  IupGLSwapBuffers (m_iup_canvas);
}
/*******************************************************
 *  void display(void)
 *
 *  GLUT window-repainting callback. Put all code in here
 *  that you need to paint your image.  
 *******************************************************/
void display (void)
{
    //----Tell openGL that the pixels are sequential (ie 
    //----they were not aligned on certain boundaries when
    //----written to memory)
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    
    //-----Clear the background
    glClear(GL_COLOR_BUFFER_BIT);

    //----Draw the pixels to our window, startin at location
    //----(0,0). 
    glRasterPos2i(0, 0);

    /*******************************************************
    * call glDrawPixels here
    *******************************************************/
    glDrawPixels(width, height, GL_RGB, GL_FLOAT, pixels ) ;


    //----Draw any information left in the buffer
    glFlush();
}
示例#28
0
void GameMenu::DrawBackground (void)
{
	if (YSOK==png.Decode("ocean.png"))
	{
		png.Flip();
		glRasterPos2d (0.0, (double)(windowHei-1));
		glDrawPixels (png.wid, png.hei, GL_RGBA, GL_UNSIGNED_BYTE, png.rgba);
	}

	//enable transparent
	glEnable (GL_BLEND); 
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
	glColor4ub(80, 0, 0, 150);
	glBegin(GL_QUADS);

	glVertex2d (220.0,375.0);
	glVertex2d (580.0,375.0);
	glVertex2d (580.0,540.0);
	glVertex2d (220.0,540.0);

	glEnd();
	glDisable(GL_BLEND);
}
void SoViewportRegion::GLRender(SoGLRenderAction *action)
{
	
	
	SoViewportRegion::doAction(action);

	if(clearBuffer.getValue())
	{
		SbVec2s winSize;
		
		winSize=SoViewportRegionElement::get(action->getState()).getViewportSizePixels();
		
		glPixelZoom(winSize[0],winSize[1]);
		glDrawPixels(1,1,GL_RGB,GL_UNSIGNED_BYTE,color);
		glPixelZoom(1,1);

		glClear(GL_DEPTH_BUFFER_BIT);
	}		


	if(onTop.getValue())
		glClear(GL_DEPTH_BUFFER_BIT);
}
示例#30
0
void display() {
  glEnable(GL_DEPTH_TEST);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  

  // Draw Background
  int pic_w, pic_h;
  GLubyte* img = readPPMfile ("apple.ppm", &pic_w, &pic_h);
  glRasterPos3f (-40.0f, -10.0f, -40.0f);
  glDrawPixels (pic_w, pic_h, GL_RGB, GL_UNSIGNED_BYTE, img);
  

  /* See drawplant.c for the definition of this routine */
  drawPlant(_iterations, 10.0f);

    glFlush();  /* Flush all executed OpenGL ops finish */

    /*
     * Since we are using double buffers, we need to call the swap
     * function every time we are done drawing.
     */
    glutSwapBuffers();
}