glue_static void glueShowzbuffer(Texture *tex, float scale) { //float *imgf=malloc(sizeof(float)*eftexture_xsize*eftexture_ysize); unsigned char *img=malloc(eftexture_xsize*eftexture_ysize*4); int x; glPixelTransferf(GL_DEPTH_SCALE, scale); glPixelTransferf(GL_DEPTH_BIAS, -(scale-1)); // glPixelTransferf(GL_DEPTH_SCALE, 1); // glPixelTransferf(GL_DEPTH_BIAS, 0); glReadPixels(0, 0, glueXres, glueYres, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, img); // glReadPixels(0, 0, effect_xsize, effect_ysize, GL_DEPTH_COMPONENT, GL_FLOAT, imgf); /* for (x=0; x<effect_xsize*effect_ysize; x++) { unsigned char joo=pow(1.0-imgf[x], ramp)*255; img[x*4+0]=img[x*4+1]=img[x*4+2]=img[x*4+3]=joo; } */ //for (x=effect_xsize*effect_ysize*4-1; x>=0; x--) img[x]=pow(1.0-img[x>>2]/255.0, ramp)*255; for (x=glueXres*glueYres*4-1; x>=0; x--) img[x]=img[x>>2]; glueReloadtexture(tex, img); gluePrepareflags(black); glueOverlay(tex, 1.0, GLUE_NO_CULL|GLUE_NO_DEPTH); free(img); //free(imgf); }
inline FTPoint FTPixmapFontImpl::RenderI(const T* string, const int len, FTPoint position, FTPoint spacing, int renderMode) { // Protect GL_TEXTURE_2D and GL_BLEND, glPixelTransferf(), and blending // functions. glPushAttrib(GL_ENABLE_BIT | GL_PIXEL_MODE_BIT | GL_COLOR_BUFFER_BIT); // Protect glPixelStorei() calls (made by FTPixmapGlyphImpl::RenderImpl). glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_TEXTURE_2D); GLfloat ftglColour[4]; glGetFloatv(GL_CURRENT_RASTER_COLOR, ftglColour); glPixelTransferf(GL_RED_SCALE, ftglColour[0]); glPixelTransferf(GL_GREEN_SCALE, ftglColour[1]); glPixelTransferf(GL_BLUE_SCALE, ftglColour[2]); glPixelTransferf(GL_ALPHA_SCALE, ftglColour[3]); FTPoint tmp = FTFontImpl::Render(string, len, position, spacing, renderMode); glPopClientAttrib(); glPopAttrib(); return tmp; }
void Painter::renderDepthBuffer() { context.stencilTest = GL_FALSE; context.depthTest = GL_FALSE; context.program = 0; context.colorMask = { GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE }; #ifndef GL_ES_VERSION_2_0 context.pixelZoom = { 1, 1 }; context.rasterPos = {{ -1, -1, 0, 0 }}; // Read the stencil buffer const auto& fbSize = frame.framebufferSize; auto pixels = std::make_unique<GLubyte[]>(fbSize[0] * fbSize[1]); const double base = 1.0 / (1.0 - depthRangeSize); glPixelTransferf(GL_DEPTH_SCALE, base); glPixelTransferf(GL_DEPTH_BIAS, 1.0 - base); MBGL_CHECK_ERROR(glReadPixels( 0, // GLint x 0, // GLint y fbSize[0], // GLsizei width fbSize[1], // GLsizei height GL_DEPTH_COMPONENT, // GLenum format GL_UNSIGNED_BYTE, // GLenum type pixels.get() // GLvoid * data )); MBGL_CHECK_ERROR(glWindowPos2i(0, 0)); MBGL_CHECK_ERROR(glDrawPixels(fbSize[0], fbSize[1], GL_LUMINANCE, GL_UNSIGNED_BYTE, pixels.get())); #endif // GL_ES_VERSION_2_0 }
///Much like Nehe's glPrint function, but modified to work ///with freetype fonts. ///For this hack, I've taken out the newline processing, though it's easy to ///see how you could use the move_raster() functions to put newline processing back ///in. void print(const font_data &ft_font, const char *fmt, ...) { // float h=ft_font.h/.63f; //We make the height about 1.5* that of char text[256]; // Holds Our String va_list ap; // Pointer To List Of Arguments if (fmt == NULL) // If There's No Text *text=0; // Do Nothing else { va_start(ap, fmt); // Parses The String For Variables vsprintf(text, fmt, ap); // And Converts Symbols To Actual Numbers va_end(ap); // Results Are Stored In Text } glPushAttrib(GL_CURRENT_BIT | GL_PIXEL_MODE_BIT | GL_ENABLE_BIT); glDisable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glDisable(GL_LIGHTING); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //we'll be nice people and save the old pixel unpack alignment- //while setting the unpack allignment to one couldn't possibly //hurt anyone else's pixel drawing, it might slow it down. GLint old_unpack; glGetIntegerv(GL_UNPACK_ALIGNMENT,&old_unpack); glPixelStorei(GL_UNPACK_ALIGNMENT ,1); float color[4]; glGetFloatv(GL_CURRENT_COLOR,color); glPixelTransferf(GL_RED_SCALE,color[0]); glPixelTransferf(GL_GREEN_SCALE,color[1]); glPixelTransferf(GL_BLUE_SCALE,color[2]); glPixelTransferf(GL_ALPHA_SCALE,color[3]); for(int i=0;text[i];i++) { const char_data &cdata=*ft_font.chars[text[i]]; move_raster_x(cdata.left); move_raster_y(cdata.move_up); glDrawPixels(cdata.w,cdata.h,GL_LUMINANCE_ALPHA,GL_UNSIGNED_BYTE,cdata.data); move_raster_y(-cdata.move_up); move_raster_x(cdata.advance- cdata.left); } glPixelStorei(GL_UNPACK_ALIGNMENT ,old_unpack); glPopAttrib(); }
/////////////////////////////////////////////////////////////////////////////// // runOne: Run a single test case /////////////////////////////////////////////////////////////////////////////// void ReadPixSanityTest::runOne(ReadPixSanityResult& r, GLEAN::Window& w) { // Many (if not most) other tests need to read the contents of // the framebuffer to determine if the correct image has been // drawn. Obviously this is a waste of time if the basic // functionality of glReadPixels isn't working. // // This test does a "sanity" check of glReadPixels. Using as // little of the GL as practicable, it writes a random value // in the framebuffer, reads it, and compares the value read // with the value written. glPixelStorei(GL_PACK_SWAP_BYTES, GL_FALSE); glPixelStorei(GL_PACK_LSB_FIRST, GL_FALSE); glPixelStorei(GL_PACK_ROW_LENGTH, 0); glPixelStorei(GL_PACK_SKIP_ROWS, 0); glPixelStorei(GL_PACK_SKIP_PIXELS, 0); glPixelStorei(GL_PACK_ALIGNMENT, 1); glPixelTransferi(GL_MAP_COLOR, GL_FALSE); glPixelTransferi(GL_MAP_STENCIL, GL_FALSE); glPixelTransferi(GL_INDEX_SHIFT, 0); glPixelTransferi(GL_INDEX_OFFSET, 0); glPixelTransferf(GL_RED_SCALE, 1.0); glPixelTransferf(GL_GREEN_SCALE, 1.0); glPixelTransferf(GL_BLUE_SCALE, 1.0); glPixelTransferf(GL_ALPHA_SCALE, 1.0); glPixelTransferf(GL_DEPTH_SCALE, 1.0); glPixelTransferf(GL_RED_BIAS, 0.0); glPixelTransferf(GL_GREEN_BIAS, 0.0); glPixelTransferf(GL_BLUE_BIAS, 0.0); glPixelTransferf(GL_ALPHA_BIAS, 0.0); glPixelTransferf(GL_DEPTH_BIAS, 0.0); glDisable(GL_SCISSOR_TEST); glDisable(GL_DITHER); glIndexMask(~0); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glDepthMask(GL_TRUE); glStencilMask(~0); if (r.config->canRGBA) checkRGBA(r, w); if (r.config->z) checkDepth(r, w); if (r.config->s) checkStencil(r, w); r.pass = r.passRGBA & r.passDepth & r.passStencil & r.passIndex; } // ReadPixSanityTest::runOne
void __glXDisp_PixelTransferf(GLbyte *pc) { glPixelTransferf( *(GLenum *)(pc + 0), *(GLfloat *)(pc + 4) ); }
static void debug_on(int l) { static const GLfloat color[][3] = { { 1.0f, 0.0f, 0.0f }, { 1.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 1.0f }, { 0.0f, 0.0f, 1.0f }, { 1.0f, 0.0f, 1.0f }, { 1.0f, 1.0f, 1.0f }, { 1.0f, 1.0f, 1.0f }, }; glPixelTransferf(GL_RED_SCALE, color[l][0]); glPixelTransferf(GL_GREEN_SCALE, color[l][1]); glPixelTransferf(GL_BLUE_SCALE, color[l][2]); }
void draw(int x, int y, int width, int height) { glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pixel_buffer_objects[grid.which_buf]); glPixelTransferf(GL_GREEN_SCALE, 255.0f); glDrawPixels(width, height, GL_GREEN, GL_UNSIGNED_BYTE, (GLvoid*)0); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); check_gl_error(); }
static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect), int rw, int rh, unsigned int *rect, float alpha, const float rgb[3], const bool is_preview) { ImBuf *ima = NULL; /* sanity check */ if (w <= 0 || h <= 0 || w > 2000 || h > 2000) { printf("%s: icons are %i x %i pixels?\n", __func__, w, h); BLI_assert(!"invalid icon size"); return; } /* modulate color */ if (alpha != 1.0f) glPixelTransferf(GL_ALPHA_SCALE, alpha); if (rgb) { glPixelTransferf(GL_RED_SCALE, rgb[0]); glPixelTransferf(GL_GREEN_SCALE, rgb[1]); glPixelTransferf(GL_BLUE_SCALE, rgb[2]); } /* rect contains image in 'rendersize', we only scale if needed */ if (rw != w && rh != h) { /* first allocate imbuf for scaling and copy preview into it */ ima = IMB_allocImBuf(rw, rh, 32, IB_rect); memcpy(ima->rect, rect, rw * rh * sizeof(unsigned int)); IMB_scaleImBuf(ima, w, h); /* scale it */ rect = ima->rect; } /* draw */ if (is_preview) { glaDrawPixelsSafe(x, y, w, h, w, GL_RGBA, GL_UNSIGNED_BYTE, rect); } else { glRasterPos2f(x, y); glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, rect); } if (ima) IMB_freeImBuf(ima); /* restore color */ if (alpha != 0.0f) glPixelTransferf(GL_ALPHA_SCALE, 1.0f); if (rgb) { glPixelTransferf(GL_RED_SCALE, 1.0f); glPixelTransferf(GL_GREEN_SCALE, 1.0f); glPixelTransferf(GL_BLUE_SCALE, 1.0f); } }
void score_screen_render(score_screen_t* s){ //clear context glClearColor(0.0,0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //reset matrix state glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glRasterPos3f(-0.5, 0.6,-2.0); glPixelZoom(1.0, -1.0); glDrawPixels(s->image->w, s->image->h, GL_BGR, GL_UNSIGNED_BYTE, s->image->pixels); printw(0.02-floor(log10(s->score))*0.008,-0.23,-1.0,1.0,1.0,1.0,"%d",s->score); glPixelTransferf(GL_RED_SCALE, 1.0); glPixelTransferf(GL_GREEN_SCALE, 1.0); glPixelTransferf(GL_BLUE_SCALE, 1.0); glFlush(); SDL_GL_SwapBuffers(); }
void Graphics::setFontColor( color c ) { if( c.r > 0 ) c.r = -1 + c.r; else c.r = -1; if( c.g > 0 ) c.g = -1 + c.g; else c.g = -1; if( c.b > 0 ) c.b = -1 + c.b; else c.b = -1; if( c.a > 0 ) c.a = -1 + c.a; else c.a = -1; glPixelTransferf( GL_RED_BIAS, c.r ); glPixelTransferf( GL_GREEN_BIAS, c.g ); glPixelTransferf( GL_BLUE_BIAS, c.b ); glPixelTransferf( GL_ALPHA_BIAS, c.a ); }
status_t display_manager_set_frame_layer( display_manager_handle_t handle, float depth_cutoff, void* video_data, void* depth_data) { size_t index = 0; if ((NULL == handle) || (NULL == video_data) || (NULL == depth_data)) { return ERR_NULL_POINTER; } if (handle->layer_count >= TEXTURE_CAPACITY) { return ERR_EXCEED_ERROR; } index = handle->layer_count; handle->layer_count++; glUniform1f(handle->uniforms.depth_cutoffs[index], depth_cutoff); gl_pixel_buffer_set_data( handle->gl_video_buffers[index], video_data); gl_pixel_buffer_display( handle->gl_video_buffers[index], handle->uniforms.video_textures[index]); gl_pixel_buffer_set_data( handle->gl_depth_buffers[index], depth_data); /* use GL_RED_SCALE because the depth data only has 1 number * per pixel */ /* TODO */ glPixelTransferf(GL_RED_SCALE, handle->depth_scale); glPixelTransferf(GL_ALPHA_SCALE, handle->depth_scale); gl_pixel_buffer_display( handle->gl_depth_buffers[index], handle->uniforms.depth_textures[index]); glPixelTransferf(GL_RED_SCALE, 1.0f); glPixelTransferf(GL_ALPHA_SCALE, 1.0f); return NO_ERROR; }
// -------------------------------------------------------------------------------------------------------- int kDisplayXPMIcon ( const char ** xpmData, const KPosition & pos ) { glPushAttrib(GL_PIXEL_MODE_BIT); float color[4]; glGetFloatv(GL_CURRENT_COLOR, color); glPixelTransferf(GL_RED_SCALE, color[0]); glPixelTransferf(GL_GREEN_SCALE, color[1]); glPixelTransferf(GL_BLUE_SCALE, color[2]); SDL_Surface * xpmSurface = IMG_ReadXPMFromArray (const_cast<char **>(xpmData)); if (xpmSurface == NULL) { KConsole::printError("kDisplayXPMIcon: IMG_ReadXPMFromArray failed"); glPopAttrib(); return 0; } SDL_Surface * surface = SDL_ConvertSurface(xpmSurface, &KDL_PIXEL_FORMAT, SDL_SWSURFACE); if (surface == NULL) { KConsole::printError("kDisplayXPMIcon: SDL_ConvertSurface failed"); glPopAttrib(); SDL_FreeSurface(xpmSurface); return 0; } SDL_FreeSurface(xpmSurface); int width = surface->w; glRasterPos2f(pos.x-0.5, pos.y+0.5); #ifndef _WIN32 glDrawPixels(surface->w, surface->h, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, surface->pixels); #else glDrawPixels(surface->w, surface->h, GL_RGBA, GL_4_BYTES, surface->pixels); #endif SDL_FreeSurface(surface); glPopAttrib(); return width; }
void FTGLPixmapFont::Render( const wchar_t* string) { glPushAttrib( GL_ENABLE_BIT | GL_PIXEL_MODE_BIT | GL_COLOR_BUFFER_BIT); glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT); glEnable(GL_BLEND); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable( GL_TEXTURE_2D); GLfloat ftglColour[4]; glGetFloatv( GL_CURRENT_RASTER_COLOR, ftglColour); glPixelTransferf(GL_RED_SCALE, ftglColour[0]); glPixelTransferf(GL_GREEN_SCALE, ftglColour[1]); glPixelTransferf(GL_BLUE_SCALE, ftglColour[2]); glPixelTransferf(GL_ALPHA_SCALE, ftglColour[3]); FTFont::Render( string); glPopClientAttrib(); glPopAttrib(); }
void MRImage::updateTexture() { have_data = false; if (glIsTexture(texture_id)) { glDeleteTextures(1, &texture_id); } glGenTextures(1, &texture_id); RtMRIImage *img = static_cast<RtMRIImage*>(data); if (first_image) { /* contrast */ float contrast = img->getAutoContrast(); glPixelTransferf(GL_RED_SCALE, contrast); glPixelTransferf(GL_GREEN_SCALE, contrast); glPixelTransferf(GL_BLUE_SCALE, contrast); /* brightness */ float brightness = img->getAutoBrightness(); glPixelTransferf(GL_RED_BIAS, brightness); glPixelTransferf(GL_GREEN_BIAS, brightness); glPixelTransferf(GL_BLUE_BIAS, brightness); first_image = false; } /* create the image texture */ glBindTexture(TEXTURE_TYPE, texture_id); glTexParameteri(TEXTURE_TYPE, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(TEXTURE_TYPE, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(TEXTURE_TYPE, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(TEXTURE_TYPE, GL_TEXTURE_MIN_FILTER, GL_NEAREST); short *data_ptr = NULL; if(!img->isMosaic()) { data_ptr = img->getMosaicedCopy(); image_width = img->getMosaicedWidth(); image_height = img->getMosaicedHeight(); } else { data_ptr = img->getDataCopy(); image_width = img->getDim(0); image_height = img->getDim(1); } glTexImage2D(TEXTURE_TYPE, 0, 1, image_width, image_height, 0, GL_LUMINANCE, GL_SHORT, data_ptr); delete [] data_ptr; if(!glIsTexture(texture_id)) { cerr << "ERROR: could not generate a new texture" << endl; } else { have_data = true; } }
void display (void) { // FIIXME: need the scale and bias functions still. glPixelTransferf (GL_RED_BIAS, TEST_IMAGE_BIAS / TEST_IMAGE_SCALE); glPixelTransferf (GL_GREEN_BIAS, TEST_IMAGE_BIAS / TEST_IMAGE_SCALE); glPixelTransferf (GL_BLUE_BIAS, TEST_IMAGE_BIAS / TEST_IMAGE_SCALE); glPixelTransferf (GL_RED_SCALE, 1.0 / TEST_IMAGE_SCALE); glPixelTransferf (GL_GREEN_SCALE, 1.0 / TEST_IMAGE_SCALE); glPixelTransferf (GL_BLUE_SCALE, 1.0 / TEST_IMAGE_SCALE); glClear (GL_COLOR_BUFFER_BIT); // FIIXME: what the mystery 100? glRasterPos2i (0, 0); // glRasterPos2i (0, WINDOW_HEIGHT - 2 - 100); glDrawPixels (TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT, GL_LUMINANCE, GL_FLOAT, testImage); // Draw a blue 'X' near the current raster position. glColor3d (0.0, 1.0, 0.0); glBegin (GL_LINES); { glVertex2d (10, WINDOW_HEIGHT - 2 - 100 - 5); glVertex2d (20, WINDOW_HEIGHT - 2 - 100 + 5); } glEnd (); glBegin (GL_LINES); { glVertex2d (20, WINDOW_HEIGHT - 2 - 100 - 5); glVertex2d (10, WINDOW_HEIGHT - 2 - 100 + 5); } glEnd (); // Here we draw a small red 'X' onto the lower left corner of the // window, near where we expect the bottom of the raster image to // end up. glColor3d (1.0, 0.0, 0.0); glBegin (GL_LINES); { glVertex2d (10, 10); glVertex2d (20, 20); } glEnd (); glBegin (GL_LINES); { glVertex2d (10, 20); glVertex2d (20, 10); } glEnd (); glFlush(); trap_opengl_errors (); }
void draw(int x, int y, int width, int height) { glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); glPixelTransferf(GL_GREEN_SCALE, 255.0f); glDrawPixels(width, height, GL_GREEN, GL_UNSIGNED_BYTE, (GLvoid*)bufs[grid.which_buf]); /*float red[2] = {0.0f, 1.0f};*/ /*float green[2] = {0.0f, 1.0f};*/ /*float blue[2] = {0.0f, 0.0f};*/ /*float alpha[2] = {0.0f, 0.0f};*/ /*glPixelMapfv(GL_PIXEL_MAP_I_TO_R, 2, red);*/ /*glPixelMapfv(GL_PIXEL_MAP_I_TO_G, 2, green);*/ /*glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 2, blue);*/ /*glPixelMapfv(GL_PIXEL_MAP_I_TO_A, 2, alpha);*/ /*glDrawPixels(width, height, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, (GLvoid*)bufs[grid.which_buf]);*/ check_gl_error(); }
void primSolidTexture3Fade(vector *p1, real32 size, color c, trhandle tex, real32 fade) { real32 halfsize = size / 2; real32 biasRed, biasGreen, biasBlue; texreg* reg; rndTextureEnable(TRUE); trMakeCurrent(tex); reg = trStructureGet(tex); if (bitTest(reg->flags, TRF_Alpha)) { glEnable(GL_BLEND); glDisable(GL_ALPHA_TEST); rndAdditiveBlends(TRUE); } biasRed = colReal32(colRed(c)); biasGreen = colReal32(colGreen(c)); biasBlue = colReal32(colBlue(c)); if (RGL) { glPixelTransferf(GL_RED_BIAS, biasRed); glPixelTransferf(GL_GREEN_BIAS, biasGreen); glPixelTransferf(GL_BLUE_BIAS, biasBlue); } glColor4f(biasRed, biasGreen, biasBlue, fade); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(p1->x-halfsize, p1->y-halfsize, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(p1->x+halfsize, p1->y-halfsize, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(p1->x+halfsize, p1->y+halfsize, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(p1->x-halfsize, p1->y+halfsize, 0.0f); glEnd(); if (RGL) { glPixelTransferf(GL_RED_BIAS, 0.0f); glPixelTransferf(GL_GREEN_BIAS, 0.0f); glPixelTransferf(GL_BLUE_BIAS, 0.0f); } glDisable(GL_BLEND); rndAdditiveBlends(FALSE); }
/* * Copy the stencil buffer values into the current color buffer as a * grayscale image. * Input: winWidth, winHeight - size of the window * scale, bias - scale and bias to apply to stencil values for display */ void ShowStencilBuffer( GLsizei winWidth, GLsizei winHeight, GLfloat scale, GLfloat bias ) { GLubyte *stencilValues; glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_PACK_ALIGNMENT, 1); /* Read stencil values */ stencilValues = (GLubyte *) malloc(winWidth * winHeight * sizeof(GLubyte)); assert(stencilValues); glReadPixels(0, 0, winWidth, winHeight, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, stencilValues); /* save GL state */ glPushAttrib(GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_PIXEL_MODE_BIT | 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); glPixelTransferf(GL_RED_SCALE, scale); glPixelTransferf(GL_RED_BIAS, bias); glPixelTransferf(GL_GREEN_SCALE, scale); glPixelTransferf(GL_GREEN_BIAS, bias); glPixelTransferf(GL_BLUE_SCALE, scale); glPixelTransferf(GL_BLUE_BIAS, bias); glDrawPixels(winWidth, winHeight, GL_LUMINANCE, GL_UNSIGNED_BYTE, stencilValues); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); free(stencilValues); glPopAttrib(); }
void ShaderProgram::init_shaders_supported() { glewExperimental = GL_TRUE; if (!init_ && glewInit()==GLEW_OK) { //get gl version glGetIntegerv(GL_MAJOR_VERSION, &v_major_); glGetIntegerv(GL_MINOR_VERSION, &v_minor_); std::ostringstream oss; oss << "#version " << v_major_ << v_minor_ << 0 << "\n"; glsl_version_ = oss.str(); supported_ = glTexImage3D; //check max texture size GLint texSize; glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, &texSize); max_texture_size_ = texSize; #ifdef _WIN32 const GLubyte* strRenderer=0; if ((strRenderer=glGetString(GL_RENDERER))) { string str = (char*)strRenderer; if (str.find("FirePro") != string::npos) glPixelTransferf(GL_RED_BIAS, FLT_MIN);//for AMD FirePro cards } #endif // Check for non-power-of-two texture support. non_2_textures_ = true;//GLEW_ARB_texture_non_power_of_two!=0; //random numbers srand((unsigned int)TIME(NULL)); init_ = true; } }
void Projector::_capture_little (char* image) { //capture buffer to little picture glPixelTransferf(GL_RED_BIAS, 0.0f); glPixelTransferf(GL_GREEN_BIAS, 0.0f); glPixelTransferf(GL_BLUE_BIAS, 0.0f); glPixelStorei(GL_PACK_ALIGNMENT, 1); bool accumulating=(!in_color)&&(!high_quality); float scale=(!in_color)&&high_quality?0.33333333f:1.0f; glPixelTransferf(GL_RED_SCALE,scale); glPixelTransferf(GL_GREEN_SCALE,scale); glPixelTransferf(GL_BLUE_SCALE,scale); if(accumulating) { glAccum(GL_LOAD, 1.0f); glAccum(GL_RETURN, 0.3333333f); }; glFinish(); glReadPixels(0,0,w,h, in_color?GL_RGB:GL_LUMINANCE, GL_UNSIGNED_BYTE, image); if(accumulating) glAccum(GL_RETURN, 1.0f); }
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); }
// Draw a particular sample map void pmap_draw_sample_map(pmap_t *self, double scale, int sample_index) { #ifdef GLUT_FOUND int i, j; pmap_sample_t *sample; sample = PMAP_GET_SAMPLE(self, sample_index); glPixelZoom(self->grid_res / scale / 2, self->grid_res / scale / 2); // Invert colors glPixelTransferf(GL_RED_SCALE, -1); glPixelTransferf(GL_GREEN_SCALE, -1); glPixelTransferf(GL_BLUE_SCALE, -1); glPixelTransferf(GL_RED_BIAS, 0.5); glPixelTransferf(GL_GREEN_BIAS, 0.5); glPixelTransferf(GL_BLUE_BIAS, 0.5); // Draw the image in tiles to prevent the whole thing from being // clipped glPixelStorei(GL_UNPACK_ROW_LENGTH, self->grid_sx); for (j = 0; j < self->grid_sy / 16; j++) { for (i = 0; i < self->grid_sx / 16; i++) { glRasterPos2f(-self->grid_sx / 2 * self->grid_res + i * 16 * self->grid_res, -self->grid_sy / 2 * self->grid_res + j * 16 * self->grid_res); glDrawPixels(16, 16, GL_LUMINANCE, GL_BYTE, sample->cells + i * 16 + j * 16 * self->grid_sx); } } return; #endif }
void VolumeGL::generateTexture(const VolumeRAM* volume) throw (tgt::Exception, std::bad_alloc) { if (!GpuCaps.is3DTexturingSupported()) { std::string message = "3D textures apparently not supported by the OpenGL driver"; LERROR(message); throw Exception(message); } if (!GpuCaps.isNpotSupported() && !glm::all(glm::isPowerOfTwo(getDimensions()))) { std::string message = "Non-power-of-two textures apparently not supported by the OpenGL driver"; LERROR(message); throw Exception(message); } // // Determine GL format // GLint format = 0; ///< The format of textures which will are created. GLint internalFormat = 0; ///< The internal format of the textures which are created. GLenum dataType = 0; ///< The data type of the textures which are created. float scale = 1.f; ///< rescale data from normalized interger to interger. // scalar if (dynamic_cast<const VolumeAtomic<uint8_t>*>(volume)) { format = GL_RED; internalFormat = GL_R8; dataType = GL_UNSIGNED_BYTE; scale = (float)std::numeric_limits<uint8_t>::max(); } else if (dynamic_cast<const VolumeAtomic<int8_t>*>(volume)) { format = GL_RED; internalFormat = GL_R8; dataType = GL_BYTE; scale = (float)std::numeric_limits<int8_t>::max(); } else if (dynamic_cast<const VolumeAtomic<uint16_t>*>(volume)) { format = GL_RED; internalFormat = GL_R16; dataType = GL_UNSIGNED_SHORT; scale = (float)std::numeric_limits<uint16_t>::max(); } else if (dynamic_cast<const VolumeAtomic<int16_t>*>(volume)) { format = GL_RED; internalFormat = GL_R16; dataType = GL_SHORT; scale = (float)std::numeric_limits<int16_t>::max(); } else if (dynamic_cast<const VolumeAtomic<uint32_t>*>(volume)) { format = GL_RED; internalFormat = GL_R; dataType = GL_UNSIGNED_INT; scale = (float)std::numeric_limits<uint32_t>::max(); } else if (dynamic_cast<const VolumeAtomic<int32_t>*>(volume)) { format = GL_RED; internalFormat = GL_R; dataType = GL_INT; scale = (float)std::numeric_limits<int32_t>::max(); } else if (dynamic_cast<const VolumeAtomic<uint64_t>*>(volume)) { std::string message = "VolumeRAM_UInt64 not supported as OpenGL volume."; LERROR(message); throw tgt::Exception(message); } else if (dynamic_cast<const VolumeAtomic<int64_t>*>(volume)) { std::string message = "VolumeRAM_Int64 not supported as OpenGL volume."; LERROR(message); throw tgt::Exception(message); } else if (dynamic_cast<const VolumeAtomic<float>*>(volume)) { format = GL_RED; internalFormat = GL_R32F; dataType = GL_FLOAT; scale = (float)std::numeric_limits<float>::max(); } else if (dynamic_cast<const VolumeAtomic<double>*>(volume)) { std::string message = "VolumeRAM_Double not supported as OpenGL volume."; LERROR(message); throw tgt::Exception(message); } else { LERROR("unknown or unsupported volume type"); } // // Create texture // glPixelStorei(GL_UNPACK_ALIGNMENT, 1); VolumeTexture* vTex = 0; char* tempVolumeData = 0; if (volume->getDimensions().z > 1) { // multi-slice volume => just create OGL texture from it vTex = new VolumeTexture(static_cast<const GLubyte*>(volume->getData()), volume->getDimensions(), format, internalFormat, dataType, Texture::LINEAR); } else { // single-slice volume (not allowed as OGL texture) => double slice LWARNING("OpenGL does not allow 3D textures consisting of only one slice: cloning slice"); try { tempVolumeData = new char[2 * volume->getNumBytes()]; memcpy(tempVolumeData, volume->getData(), volume->getNumBytes()); memcpy(tempVolumeData + volume->getNumBytes(), volume->getData(), volume->getNumBytes()); vTex = new VolumeTexture(reinterpret_cast<const GLubyte*>(tempVolumeData), glm::ivec3(volume->getDimensions().x, volume->getDimensions().y, volume->getDimensions().z * 2), format, internalFormat, dataType, Texture::LINEAR); } catch (std::bad_alloc&) { LERROR("bad allocation while creating OpenGL texture"); throw tgt::Exception("bad allocation while creating OpenGL texture"); } } assert(vTex); LGL_ERROR; vTex->bind(); // map signed integer types from [-MIN_INT:MAX_INT] to [0.0:1.0] in order to avoid clamping of negative values if (volume->isInteger() && volume->isSigned()) { glPushAttrib(GL_ALL_ATTRIB_BITS); glPixelTransferf(GL_RED_SCALE, 0.5f); glPixelTransferf(GL_GREEN_SCALE, 0.5f); glPixelTransferf(GL_BLUE_SCALE, 0.5f); glPixelTransferf(GL_ALPHA_SCALE, 0.5f); glPixelTransferf(GL_RED_BIAS, 0.5f); glPixelTransferf(GL_GREEN_BIAS, 0.5f); glPixelTransferf(GL_BLUE_BIAS, 0.5f); glPixelTransferf(GL_ALPHA_BIAS, 0.5f); pixelTransferMapping_ = ValueMapping(1/scale * 0.5f, 0.5f, ""); } else pixelTransferMapping_ = ValueMapping(1 / scale, 0.f, ""); if (volume->getData()) vTex->uploadTexture(); // reset pixel transfer if (volume->isInteger() && volume->isSigned()) { glPopAttrib(); } // set texture wrap to clamp vTex->setWrapping(Texture::CLAMP); LGL_ERROR; // prevent deleting twice vTex->setPixelData(0); delete[] tempVolumeData; tempVolumeData = 0; // append to internal data structure texture_ = vTex; LGL_ERROR; }
static void SetupPixelTransfer(GLboolean invert) { if (invert) { glPixelTransferf(GL_RED_SCALE, -1.0); glPixelTransferf(GL_RED_BIAS, 1.0); glPixelTransferf(GL_GREEN_SCALE, -1.0); glPixelTransferf(GL_GREEN_BIAS, 1.0); glPixelTransferf(GL_BLUE_SCALE, -1.0); glPixelTransferf(GL_BLUE_BIAS, 1.0); } else { glPixelTransferf(GL_RED_SCALE, 1.0); glPixelTransferf(GL_RED_BIAS, 0.0); glPixelTransferf(GL_GREEN_SCALE, 1.0); glPixelTransferf(GL_GREEN_BIAS, 0.0); glPixelTransferf(GL_BLUE_SCALE, 1.0); glPixelTransferf(GL_BLUE_BIAS, 0.0); } }
void DisplayScene(void) { static GLboolean pixelsFlipped = GL_FALSE; static GLfloat saturation = 1.0; GLfloat colorMap[256]; GLint i; glClear(GL_COLOR_BUFFER_BIT); /* * Let OpenGL know that when it reads our pixel data from memory it's * TIGHTLY packed. Not packed to it's default of 4 bytes. */ glPixelStorei(GL_UNPACK_ALIGNMENT, 1); switch(renderMode) { case 1: if(pixelsFlipped != GL_TRUE) { glPixelZoom(-1.0, -1.0); glRasterPos2i(img->width, img->height); pixelsFlipped = GL_TRUE; } else { glPixelZoom(1.0, 1.0); glRasterPos2i(0, 0); pixelsFlipped = GL_FALSE; } break; case 2: glPixelTransferf(GL_RED_SCALE, 1.0); glPixelTransferf(GL_GREEN_SCALE, 1.0); glPixelTransferf(GL_BLUE_SCALE, 1.0); break; case 3: glPixelTransferf(GL_RED_SCALE, 1.0); glPixelTransferf(GL_GREEN_SCALE, 0.0); glPixelTransferf(GL_BLUE_SCALE, 0.0); break; case 4: glPixelTransferf(GL_RED_SCALE, 0.0); glPixelTransferf(GL_GREEN_SCALE, 1.0); glPixelTransferf(GL_BLUE_SCALE, 0.0); break; case 5: glPixelTransferf(GL_RED_SCALE, 0.0); glPixelTransferf(GL_GREEN_SCALE, 0.0); glPixelTransferf(GL_BLUE_SCALE, 1.0); break; case 6: saturation -= 0.5; glPixelTransferf(GL_RED_SCALE, saturation); glPixelTransferf(GL_GREEN_SCALE, saturation); glPixelTransferf(GL_BLUE_SCALE, saturation); break; case 7: saturation += 0.5; glPixelTransferf(GL_RED_SCALE, saturation); glPixelTransferf(GL_GREEN_SCALE, saturation); glPixelTransferf(GL_BLUE_SCALE, saturation); break; case 8: colorMap[0] = 1.0f; for(i = 1; i < 256; i++) colorMap[i] = 1.0f - (1.0f / 255.0f * (GLfloat)i); glPixelMapfv(GL_PIXEL_MAP_R_TO_R, 255, colorMap); glPixelMapfv(GL_PIXEL_MAP_G_TO_G, 255, colorMap); glPixelMapfv(GL_PIXEL_MAP_B_TO_B, 255, colorMap); glPixelTransferi(GL_MAP_COLOR, GL_TRUE); break; default: break; } glDrawPixels(img->width, img->height, img->format, GL_UNSIGNED_BYTE, img->image); glPixelTransferi(GL_MAP_COLOR, GL_FALSE); glFlush(); }
void glPopAttrib() { //printf("glPopAttrib()\n"); noerrorShim(); if ((state.list.compiling || state.gl_batch) && state.list.active) { NewStage(state.list.active, STAGE_POP); state.list.active->popattribute = true; return; } if (stack == NULL || stack->len == 0) { errorShim(GL_STACK_UNDERFLOW); return; } glstack_t *cur = stack + stack->len-1; if (cur->mask & GL_COLOR_BUFFER_BIT) { enable_disable(GL_ALPHA_TEST, cur->alpha_test); glAlphaFunc(cur->alpha_test_func, cur->alpha_test_ref); enable_disable(GL_BLEND, cur->blend); glBlendFunc(cur->blend_src_func, cur->blend_dst_func); enable_disable(GL_DITHER, cur->dither); enable_disable(GL_COLOR_LOGIC_OP, cur->color_logic_op); glLogicOp(cur->logic_op); GLfloat *c; glClearColor(v4(cur->clear_color)); glColorMask(v4(cur->color_mask)); } if (cur->mask & GL_CURRENT_BIT) { glColor4f(v4(cur->color)); glNormal3f(v3(cur->normal)); glTexCoord2f(v2(cur->tex)); } if (cur->mask & GL_DEPTH_BUFFER_BIT) { enable_disable(GL_DEPTH_TEST, cur->depth_test); glDepthFunc(cur->depth_func); glClearDepth(cur->clear_depth); glDepthMask(cur->depth_mask); } if (cur->mask & GL_ENABLE_BIT) { int i; enable_disable(GL_ALPHA_TEST, cur->alpha_test); enable_disable(GL_AUTO_NORMAL, cur->autonormal); enable_disable(GL_BLEND, cur->blend); GLint max_clip_planes; glGetIntegerv(GL_MAX_CLIP_PLANES, &max_clip_planes); for (i = 0; i < max_clip_planes; i++) { enable_disable(GL_CLIP_PLANE0 + i, *(cur->clip_planes_enabled + i)); } enable_disable(GL_COLOR_MATERIAL, cur->colormaterial); enable_disable(GL_CULL_FACE, cur->cull_face); enable_disable(GL_DEPTH_TEST, cur->depth_test); enable_disable(GL_DITHER, cur->dither); enable_disable(GL_FOG, cur->fog); GLint max_lights; glGetIntegerv(GL_MAX_LIGHTS, &max_lights); for (i = 0; i < max_lights; i++) { enable_disable(GL_LIGHT0 + i, *(cur->lights_enabled + i)); } enable_disable(GL_LIGHTING, cur->lighting); enable_disable(GL_LINE_SMOOTH, cur->line_smooth); enable_disable(GL_LINE_STIPPLE, cur->line_stipple); enable_disable(GL_COLOR_LOGIC_OP, cur->color_logic_op); //TODO: GL_INDEX_LOGIC_OP //TODO: GL_MAP1_x //TODO: GL_MAP2_x enable_disable(GL_MULTISAMPLE, cur->multisample); enable_disable(GL_NORMALIZE, cur->normalize); enable_disable(GL_POINT_SMOOTH, cur->point_smooth); //TODO: GL_POLYGON_OFFSET_LINE enable_disable(GL_POLYGON_OFFSET_FILL, cur->polygon_offset_fill); //TODO: GL_POLYGON_OFFSET_POINT //TODO: GL_POLYGON_SMOOTH //TODO: GL_POLYGON_STIPPLE enable_disable(GL_SAMPLE_ALPHA_TO_COVERAGE, cur->sample_alpha_to_coverage); enable_disable(GL_SAMPLE_ALPHA_TO_ONE, cur->sample_alpha_to_one); enable_disable(GL_SAMPLE_COVERAGE, cur->sample_coverage); enable_disable(GL_SCISSOR_TEST, cur->scissor_test); enable_disable(GL_STENCIL_TEST, cur->stencil_test); int a; int old_tex = state.texture.active; for (a=0; a<MAX_TEX; a++) { if (state.enable.texture_1d[a] != cur->texture_1d[a]) { glActiveTexture(GL_TEXTURE0+a); enable_disable(GL_TEXTURE_1D, cur->texture_1d[a]); } if (state.enable.texture_2d[a] != cur->texture_2d[a]) { glActiveTexture(GL_TEXTURE0+a); enable_disable(GL_TEXTURE_2D, cur->texture_2d[a]); } if (state.enable.texture_3d[a] != cur->texture_3d[a]) { glActiveTexture(GL_TEXTURE0+a); enable_disable(GL_TEXTURE_3D, cur->texture_3d[a]); } state.enable.texgen_r[a] = cur->texgen_r[a]; state.enable.texgen_s[a] = cur->texgen_s[a]; state.enable.texgen_t[a] = cur->texgen_t[a]; } if (state.texture.active != old_tex) glActiveTexture(GL_TEXTURE0+old_tex); } if (cur->mask & GL_FOG_BIT) { enable_disable(GL_FOG, cur->fog); glFogfv(GL_FOG_COLOR, cur->fog_color); glFogf(GL_FOG_DENSITY, cur->fog_density); glFogf(GL_FOG_START, cur->fog_start); glFogf(GL_FOG_END, cur->fog_end); glFogf(GL_FOG_MODE, cur->fog_mode); } if (cur->mask & GL_HINT_BIT) { enable_disable(GL_PERSPECTIVE_CORRECTION_HINT, cur->perspective_hint); enable_disable(GL_POINT_SMOOTH_HINT, cur->point_smooth_hint); enable_disable(GL_LINE_SMOOTH_HINT, cur->line_smooth_hint); enable_disable(GL_FOG_HINT, cur->fog_hint); enable_disable(GL_GENERATE_MIPMAP_HINT, cur->mipmap_hint); } // GL_LIST_BIT if (cur->mask & GL_LIST_BIT) { glListBase(cur->list_base); } if (cur->mask & GL_LINE_BIT) { enable_disable(GL_LINE_SMOOTH, cur->line_smooth); // TODO: stipple stuff here glLineWidth(cur->line_width); } if (cur->mask & GL_MULTISAMPLE_BIT) { enable_disable(GL_MULTISAMPLE, cur->multisample); enable_disable(GL_SAMPLE_ALPHA_TO_COVERAGE, cur->sample_alpha_to_coverage); enable_disable(GL_SAMPLE_ALPHA_TO_ONE, cur->sample_alpha_to_one); enable_disable(GL_SAMPLE_COVERAGE, cur->sample_coverage); } if (cur->mask & GL_POINT_BIT) { enable_disable(GL_POINT_SMOOTH, cur->point_smooth); glPointSize(cur->point_size); } if (cur->mask & GL_SCISSOR_BIT) { enable_disable(GL_SCISSOR_TEST, cur->scissor_test); glScissor(v4(cur->scissor_box)); } if (cur->mask & GL_STENCIL_BUFFER_BIT) { enable_disable(GL_STENCIL_TEST, cur->stencil_test); glStencilFunc(cur->stencil_func, cur->stencil_ref, cur->stencil_mask); //TODO: Stencil value mask glStencilOp(cur->stencil_sfail, cur->stencil_dpfail, cur->stencil_dppass); glClearStencil(cur->stencil_clearvalue); //TODO: Stencil buffer writemask } if (cur->mask & GL_TEXTURE_BIT) { int a; //TODO: Enable bit for the 4 texture coordinates for (a=0; a<MAX_TEX; a++) { state.enable.texgen_r[a] = cur->texgen_r[a]; state.enable.texgen_s[a] = cur->texgen_s[a]; state.enable.texgen_t[a] = cur->texgen_t[a]; state.texgen[a] = cur->texgen[a]; // all mode and planes per texture in 1 line if ((cur->texture[a]==0 && state.texture.bound[a] != 0) || (cur->texture[a]!=0 && state.texture.bound[a]==0)) { glActiveTexture(GL_TEXTURE0+a); glBindTexture(GL_TEXTURE_2D, cur->texture[a]); } } if (state.texture.active!= cur->active) glActiveTexture(GL_TEXTURE0+cur->active); } if (cur->mask & GL_PIXEL_MODE_BIT) { GLenum pixel_name[] = {GL_RED_BIAS, GL_RED_SCALE, GL_GREEN_BIAS, GL_GREEN_SCALE, GL_BLUE_BIAS, GL_BLUE_SCALE, GL_ALPHA_BIAS, GL_ALPHA_SCALE}; int i; for (i=0; i<8; i++) glPixelTransferf(pixel_name[i], cur->pixel_scale_bias[i]); //TODO: GL_DEPTH_BIAS & GL_DEPTH_SCALE (probably difficult) //TODO: GL_INDEX_OFFEST & GL_INDEX_SHIFT //TODO: GL_MAP_COLOR & GL_MAP_STENCIL (probably difficult too) glPixelZoom(cur->pixel_zoomx, cur->pixel_zoomy); } if (cur->mask & GL_TRANSFORM_BIT) { if (!(cur->mask & GL_ENABLE_BIT)) { int i; GLint max_clip_planes; glGetIntegerv(GL_MAX_CLIP_PLANES, &max_clip_planes); for (i = 0; i < max_clip_planes; i++) { enable_disable(GL_CLIP_PLANE0 + i, *(cur->clip_planes_enabled + i)); } } glMatrixMode(cur->matrix_mode); enable_disable(GL_NORMALIZE, cur->normalize_flag); enable_disable(GL_RESCALE_NORMAL, cur->rescale_normal_flag); } if (cur->mask & GL_VIEWPORT_BIT) { glViewport(cur->viewport_size[0], cur->viewport_size[1], cur->viewport_size[2], cur->viewport_size[3]); glDepthRangef(cur->depth_range[0], cur->depth_range[1]); } maybe_free(cur->clip_planes_enabled); maybe_free(cur->clip_planes); maybe_free(cur->lights_enabled); maybe_free(cur->lights); stack->len--; }
/** * Renders a string of text using this face * Returns the width of the rendered text in pixels (at subpixel accuracy) */ float STFont::DrawString(const std::string& str, const STColor4f& color) { if (str.length() == 0 || mImpl->ftFace == NULL) return 0.0f; // // Set up OpenGL state for rendering text, and push // attributes so that we can restore when done. // glPushAttrib( GL_ENABLE_BIT | GL_PIXEL_MODE_BIT | GL_COLOR_BUFFER_BIT); glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_TEXTURE_2D); glPixelTransferf(GL_RED_SCALE, color.r); glPixelTransferf(GL_GREEN_SCALE, color.g); glPixelTransferf(GL_BLUE_SCALE, color.b); glPixelTransferf(GL_ALPHA_SCALE, color.a); glRasterPos2f(0.0f, 0.0f); // // Draw each character in order. // float totalAdvance = 0.0f; unsigned int useKerning = FT_HAS_KERNING(mImpl->ftFace); // Render glyph for each character in the string int strLength = (int)str.length(); for (int i=0; i<strLength; i++) { unsigned int ch = str[i]; int bitmapIndex = GetBitmapIndex( ch ); // Pixmap for this character hasn't been generated. Do that now. if (bitmapIndex == -1) { if (ch == ' ') { glBitmap( 0, 0, 0.0f, 0.0f, (float) mImpl->size / 4.0f, 0.0f, (const GLubyte*)0 ); totalAdvance += (float) mImpl->size / 4.0f; continue; } else { bitmapIndex = GenerateBitmap( ch ); } } STBitmapGlyph& bitmapGlyph = mImpl->glyphBitmaps[bitmapIndex]; // Move the raster position by (offsetX, offsetY) glBitmap(0, 0, 0.0f, 0.0f, (float) bitmapGlyph.offsetX, (float) bitmapGlyph.offsetY, NULL); // Render the glyph to the framebuffer glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); glPixelStorei(GL_UNPACK_ALIGNMENT, 2); glDrawPixels(bitmapGlyph.width, bitmapGlyph.height, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, (const GLvoid*) bitmapGlyph.data); // Restore raster position glBitmap(0, 0, 0.0f, 0.0f, (float) -bitmapGlyph.offsetX, (float) -bitmapGlyph.offsetY, NULL); // Get the kerning offset for the next character. FT_Vector kerning = {0,0}; if( useKerning && (i < strLength-1) ) { FT_Get_Kerning(mImpl->ftFace, FT_Get_Char_Index(mImpl->ftFace, str[i] ), FT_Get_Char_Index(mImpl->ftFace, str[i+1] ), 0, &kerning ); } // Move the raster position to where it should be for the next character. glBitmap(0, 0, 0.0f, 0.0f, (float) (bitmapGlyph.advanceX + kerning.x/64.0f), 0.0f, NULL); totalAdvance += bitmapGlyph.advanceX + kerning.x/64.0f; } // // Restore OpenGL state. // glPopClientAttrib(); glPopAttrib(); return totalAdvance; }
/* /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */ static void mat_livedb_draw_tree_element(bContext *C, uiBlock *block, ARegion *ar, SpaceLDB *slivedb, LiveDbTreeElement *te, int startx, int *starty, int *row_num) { LiveDbTreeElement *ten; float ufac = UI_UNIT_X / 20.0f; int offsx = 0, active = 0; int CUR_UNIT_Y; if(TE_GET_TYPE(te->item->type) == MAT_LDB_TREE_ITEM_TYPE_CATEGORY) CUR_UNIT_Y = UI_UNIT_Y; else CUR_UNIT_Y = MAT_LIVEDB_UI_UNIT_Y; *starty -= CUR_UNIT_Y; ++ *row_num; if (*starty + 2 * CUR_UNIT_Y >= ar->v2d.cur.ymin && *starty <= ar->v2d.cur.ymax) { int xmax = ar->v2d.cur.xmax; unsigned char alpha = 128; /* icons can be ui buts, we don't want it to overlap with material previews */ if(TE_GET_TYPE(te->item->type) == MAT_LDB_TREE_ITEM_TYPE_MATERIAL) xmax -= MAT_LIVEDB_UI_UNIT_Y; glEnable(GL_BLEND); if(*row_num % 2) { UI_ThemeColorShade(TH_BACK, 6); glRecti(0, *starty + 1, ar->v2d.cur.xmax, *starty + CUR_UNIT_Y - 1); } if (*te->flag & TE_SELECTED) { float col[4]; unsigned char col_circle[4]; UI_GetThemeColor3fv(TH_SELECT_HIGHLIGHT, col); glColor3fv(col); glRecti(0, *starty + 1, (int)ar->v2d.cur.xmax, *starty + CUR_UNIT_Y - 1); /* active circle */ UI_GetThemeColorType4ubv(TH_ACTIVE, SPACE_VIEW3D, col_circle); col_circle[3] = alpha; glColor4ubv((GLubyte *)col_circle); UI_draw_roundbox_corner_set(UI_CNR_ALL); UI_draw_roundbox((float)startx + UI_UNIT_X - ufac, (float)*starty + (TE_GET_TYPE(te->item->type) == MAT_LDB_TREE_ITEM_TYPE_CATEGORY ? 1.0f : UI_UNIT_Y * 3), (float)startx + 2.0f * UI_UNIT_X - 2.0f * ufac, (float)*starty + CUR_UNIT_Y - 1.0f * ufac, UI_UNIT_Y / 2.0f - 1.0f * ufac); glEnable(GL_BLEND); /* roundbox disables it */ } /* start by highlighting search matches */ if (SEARCHING_MAT_LIVEDB(slivedb) && (*te->flag & TE_SEARCHMATCH)) { char col[4]; UI_GetThemeColorType4ubv(TH_MATCH, SPACE_MAT_LIVEDB, col); col[3] = alpha; glColor4ubv((GLubyte *)col); glRecti(startx, *starty + 1, ar->v2d.cur.xmax, *starty + CUR_UNIT_Y - 1); } /* open/close icon, only when sublevels */ if (te->subtree.first || (*te->flag & TE_LAZY_CLOSED)) { int icon_x; if (TE_GET_TYPE(te->item->type) == MAT_LDB_TREE_ITEM_TYPE_CATEGORY) icon_x = startx; else icon_x = startx + 5 * ufac; if (MAT_LIVEDB_ELEM_OPEN(te, slivedb)) UI_icon_draw((float)icon_x, (float)*starty + 2 * ufac, ICON_DISCLOSURE_TRI_DOWN); else UI_icon_draw((float)icon_x, (float)*starty + 2 * ufac, ICON_DISCLOSURE_TRI_RIGHT); } offsx += UI_UNIT_X; /* Element type icon */ if(TE_GET_TYPE(te->item->type) == MAT_LDB_TREE_ITEM_TYPE_CATEGORY) mat_livedb_elem_draw_icon((float)startx + offsx, (float)*starty, te); else mat_livedb_elem_draw_icon((float)startx + offsx, (float)*starty + UI_UNIT_X * 3, te); offsx += UI_UNIT_X; glDisable(GL_BLEND); /* name */ if (active == 1) UI_ThemeColor(TH_TEXT_HI); else UI_ThemeColor(TH_TEXT); if(TE_GET_TYPE(te->item->type) == MAT_LDB_TREE_ITEM_TYPE_CATEGORY) UI_fontstyle_draw_simple(UI_FSTYLE_WIDGET, startx + offsx, *starty + 5 * ufac, te->name); else { uiBut *bt; UI_fontstyle_draw_simple(UI_FSTYLE_WIDGET, startx + offsx, *starty + UI_UNIT_X * 3 + 5 * ufac, te->name); UI_fontstyle_draw_simple(UI_FSTYLE_WIDGET, startx + offsx, *starty + UI_UNIT_X * 2 + 5 * ufac, te->nick_name); UI_fontstyle_draw_simple(UI_FSTYLE_WIDGET, startx + offsx, *starty + UI_UNIT_X + 5 * ufac, te->copyright); bt = uiDefIconBut(block, UI_BTYPE_ICON_TOGGLE, 0, ICON_WORLD, xmax - UI_UNIT_X - 3, *starty + 1 * ufac, UI_UNIT_X, UI_UNIT_Y, NULL, 0.0, 0.0, 1.0, 0.5f, "Get item"); UI_but_func_set(bt, get_material_cb, (void*)slivedb->server_address, (void*)te->item->mat_item.id); UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK); } offsx += (int)(UI_UNIT_X + UI_fontstyle_string_width(UI_FSTYLE_WIDGET, te->name)); /* Closed item, we draw the category-info icons */ if (TE_GET_TYPE(te->item->type) == MAT_LDB_TREE_ITEM_TYPE_CATEGORY && !MAT_LIVEDB_ELEM_OPEN(te, slivedb)) { if (te->subtree.first) { int tempx = startx + offsx; /* divider */ UI_ThemeColorShade(TH_BACK, -40); glRecti(tempx - 10.0f * ufac, *starty + 4.0f * ufac, tempx - 8.0f * ufac, *starty + CUR_UNIT_Y - 4.0f * ufac); glEnable(GL_BLEND); glPixelTransferf(GL_ALPHA_SCALE, 0.5); mat_livedb_draw_content_count_icons(&te->subtree, xmax, &tempx, *starty); glPixelTransferf(GL_ALPHA_SCALE, 1.0); glDisable(GL_BLEND); } } } /* store coord and continue, we need coordinates for elements outside view too */ te->xs = (float)startx; te->ys = (float)*starty; te->xend = startx + offsx; if (MAT_LIVEDB_ELEM_OPEN(te, slivedb)) { for (ten = te->subtree.first; ten; ten = ten->next) mat_livedb_draw_tree_element(C, block, ar, slivedb, ten, startx + UI_UNIT_X, starty, row_num); } else { for (ten = te->subtree.first; ten; ten = ten->next) mat_livedb_set_coord_tree_element(slivedb, te, startx, starty); } } /* mat_livedb_draw_tree_element() */
///////////////////////////////////////////////////////// // Render // void GEMglPixelTransferf :: render(GemState *state) { glPixelTransferf (pname, param); }