void render_quad(float x, float y, float width, float height) { GLfloat vertices[] = {x + width, y + height, x, y + height, x, y, x + width, y }; GLfloat texCoords[] = {1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0 }; GLubyte indices[] = {0, 1, 2, 0, 2, 3}; //Set color variable before rendering quad set_uniform_vec4(colorUni, colorRed, colorGreen, colorBlue, colorAlpha); set_uniform_float(diffuseSamplerUni, 0); if (currentTexture != NULL) bind_texture(currentTexture, 0); else bind_texture(whiteTexture, 0); glEnableVertexAttribArray(vertPosAttrib->handle); glEnableVertexAttribArray(texCoordAttrib->handle); glVertexAttribPointer(vertPosAttrib->handle, 2, GL_FLOAT, GL_FALSE, 0, vertices); glVertexAttribPointer(texCoordAttrib->handle, 2, GL_FLOAT, GL_FALSE, 0, texCoords); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, indices); glDisableVertexAttribArray(vertPosAttrib->handle); glDisableVertexAttribArray(texCoordAttrib->handle); unbind_texture(0); }
static void draw_frame_text_buffer(struct Renderer *renderer, struct RenderBuffer *render_buffer) { bind_program(renderer->text_program); bind_texture_unit(0); set_uniform_int32("u_Texture", renderer->text_program, 0); bind_texture(renderer->debug_font.texture); draw_text_buffer(&renderer->sprite_batch, &renderer->debug_font, &render_buffer->text); bind_texture(0); bind_program(0); }
void init(void) { glEnable(GL_DEPTH_TEST); /* Setup texturing */ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); /* generate texture object IDs */ glGenTextures(2, TexObj); bind_texture(TexObj[0], 0); bind_texture(TexObj[1], 1); }
void idle(void) { Angle += 2.0; if (++cnt==25) { cnt=0; v=!v; } bind_texture(TexObj[0],0); bind_texture(TexObj[1],1); draw(); }
void render_texture_update(struct render *R, RID id, int width, int height, const void *pixels, int slice, int miplevel) { struct texture * tex = (struct texture *)array_ref(&R->texture, id); if (tex == NULL) return; GLenum type; int target; bind_texture(R, tex, slice, &type, &target); if (tex->mipmap) { glTexParameteri( type, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); } else { glTexParameteri( type, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); } glTexParameteri( type, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); glTexParameteri( type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); glPixelStorei(GL_UNPACK_ALIGNMENT,1); GLint format = 0; GLenum itype = 0; int compressed = texture_format(tex, &format, &itype); if (compressed) { glCompressedTexImage2D(target, miplevel, format, (GLsizei)tex->width, (GLsizei)tex->height, 0, calc_texture_size(tex->format, width, height), pixels); } else { glTexImage2D(target, miplevel, format, (GLsizei)width, (GLsizei)height, 0, format, itype, pixels); } CHECK_GL_ERROR }
void init() { allegro_init(); set_color_depth(32); if(set_gfx_mode(GFX_AUTODETECT_WINDOWED, GFX_W, GFX_H, 0, 0)) { allegro_message("Error: %s.", allegro_error); exit(1); } install_keyboard(); install_mouse(); buffer = create_bitmap(SCREEN_W, SCREEN_H); zbuffer = create_bitmap_ex(32, SCREEN_W, SCREEN_H); texture = load_bitmap("data/wall.bmp", NULL); skin = load_bitmap("data/babe_skin.bmp", NULL); texture2 = load_bitmap("data/color.bmp", NULL); setup_projection(90.0, -1.333, 1.333, -1.0, 1.0, -1.0, 200.0); init_renderer(GFX_H); bind_color_buffer(buffer); bind_zbuffer(zbuffer); bind_texture(texture); }
void draw_background_tiled_ext(int back,double x,double y,double xscale,double yscale,int color,double alpha) { get_background(bck2d,back); bind_texture(bck2d->texture); glPushAttrib(GL_CURRENT_BIT); glColor4ub(__GETR(color),__GETG(color),__GETB(color),char(alpha*255)); const float tbx=bck2d->texbordx,tby=bck2d->texbordy, w=bck2d->width*xscale, h=bck2d->height*yscale; const int hortil= int (ceil(room_width/(bck2d->width*tbx))), vertil= int (ceil(room_height/(bck2d->height*tby))); x=w-fmod(x,w); y=h-fmod(y,h); glBegin(GL_QUADS); for (int i=0; i<hortil; i++) { for (int c=0; c<vertil; c++) { glTexCoord2f(0,0); glVertex2f(i*w-x,c*h-y); glTexCoord2f(tbx,0); glVertex2f((i+1)*w-x,c*h-y); glTexCoord2f(tbx,tby); glVertex2f((i+1)*w-x,(c+1)*h-y); glTexCoord2f(0,tby); glVertex2f(i*w-x,(c+1)*h-y); } } glEnd(); glPopAttrib(); }
void x3ds_instance::set_material(Lib3dsMaterial* mat) { if (mat) { // if (mat->two_sided) // { // glDisable(GL_CULL_FACE); // } // else // { // glEnable(GL_CULL_FACE); // } glDisable(GL_CULL_FACE); glMaterialfv(GL_FRONT, GL_AMBIENT, mat->ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat->diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, mat->specular); glMaterialf(GL_FRONT, GL_SHININESS, pow(2.0f, 10.0f * mat->shininess)); bind_texture(mat->texture1_map.name); } else { // no material, assume the default static const Lib3dsRgba a = {0.2f, 0.2f, 0.2f, 1.0f}; static const Lib3dsRgba d = {0.8f, 0.8f, 0.8f, 1.0f}; static const Lib3dsRgba s = {0.0f, 0.0f, 0.0f, 1.0f}; glMaterialfv(GL_FRONT, GL_AMBIENT, a); glMaterialfv(GL_FRONT, GL_DIFFUSE, d); glMaterialfv(GL_FRONT, GL_SPECULAR, s); glMaterialf(GL_FRONT, GL_SHININESS, pow(2.0f, 10.0f * 0.5f)); } }
void draw_background_ext(int back,double x,double y,double xscale,double yscale,double rot,int color,double alpha) { get_background(bck2d,back); bind_texture(bck2d->texture); glPushAttrib(GL_CURRENT_BIT); glColor4ub(__GETR(color),__GETG(color),__GETB(color),char(alpha*255)); const float tbx=bck2d->texbordx,tby=bck2d->texbordy, w=bck2d->width*xscale, h=bck2d->height*yscale; rot *= M_PI/180; float ulcx = x + xscale * cos(M_PI+rot) + yscale * cos(M_PI/2+rot), ulcy = y - yscale * sin(M_PI+rot) - yscale * sin(M_PI/2+rot); glBegin(GL_QUADS); glTexCoord2f(0,0); glVertex2f(ulcx,ulcy); glTexCoord2f(tbx,0); glVertex2f(ulcx + w*cos(rot), ulcy - w*sin(rot)); glTexCoord2f(tbx,tby); ulcx += h * cos(3*M_PI/2 + rot); ulcy -= h * sin(3*M_PI/2 + rot); glVertex2f(ulcx + w*cos(rot), ulcy - w*sin(rot)); glTexCoord2f(0,tby); glVertex2f(ulcx,ulcy); glEnd(); glPopAttrib(); }
void draw_background_part_ext(int back,double left,double top,double width,double height,double x,double y,double xscale,double yscale,int color,double alpha) { get_background(bck2d,back); bind_texture(bck2d->texture); glPushAttrib(GL_CURRENT_BIT); glColor4ub(__GETR(color),__GETG(color),__GETB(color),char(alpha*255)); const float tbx = bck2d->texbordx, tby = bck2d->texbordy, tbw = bck2d->width/tbx, tbh = bck2d->height/tby; glBegin(GL_QUADS); glTexCoord2f(left/tbw,top/tbh); glVertex2f(x,y); glTexCoord2f((left+width)/tbw,top/tbh); glVertex2f(x+width*xscale,y); glTexCoord2f((left+width)/tbw,(top+height)/tbh); glVertex2f(x+width*xscale,y+height*yscale); glTexCoord2f(left/tbw,(top+height)/tbh); glVertex2f(x,y+height*yscale); glEnd(); glPopAttrib(); }
NE_API void draw_text(font_text* text) { if (current_font_asset && text->text[0] != '\0') { font_asset* font = get_font(current_font_asset); SDL_Color color = { 255, 255, 255, 255 }; SDL_Surface* surface = nullptr; TTF_Font* ttf = (TTF_Font*) font->resource_handle; if (text->wrap_length == 0) { surface = TTF_RenderUTF8_Blended(ttf, text->text.c_str(), color); } else { surface = TTF_RenderUTF8_Blended_Wrapped(ttf, text->text.c_str(), color, text->wrap_length); } if (text->texture.resource_handle == 0) { text->texture.resource_handle = create_texture(); } load_texture_from_pixels(&text->texture, (uint32*) surface->pixels, surface->w, surface->h); text->old_text = text->text; text->text[0] = '\0'; text->transform.scale = { (float) surface->w, (float) surface->h, 0.0f }; SDL_FreeSurface(surface); } if (text->texture.resource_handle != 0 && text->old_text[0] != '\0' && text->text[0] == '\0') { set_model_matrix(&text->transform); bind_texture(&text->texture); draw_vertex_array(&shapes[current_shape].vertex_array); } }
void draw_background_tiled(int back,double x,double y) { get_background(bck2d,back); bind_texture(bck2d->texture); glPushAttrib(GL_CURRENT_BIT); glColor4f(1,1,1,1); x=bck2d->width-fmod(x,bck2d->width); y=bck2d->height-fmod(y,bck2d->height); const float tbx=bck2d->texbordx,tby=bck2d->texbordy; const int hortil= int (ceil(room_width/(bck2d->width*tbx))), vertil= int (ceil(room_height/(bck2d->height*tby))); glBegin(GL_QUADS); for (int i=0; i<hortil; i++) { for (int c=0; c<vertil; c++) { glTexCoord2f(0,0); glVertex2f(i*bck2d->width-x,c*bck2d->height-y); glTexCoord2f(tbx,0); glVertex2f((i+1)*bck2d->width-x,c*bck2d->height-y); glTexCoord2f(tbx,tby); glVertex2f((i+1)*bck2d->width-x,(c+1)*bck2d->height-y); glTexCoord2f(0,tby); glVertex2f(i*bck2d->width-x,(c+1)*bck2d->height-y); } } glEnd(); glPopAttrib(); }
// Draw the icons into the window // void Container::draw_icons(void) { Busy dummy; for (size_t i=0; i<icon_list.size(); ++i) icon_list[i]->update_highlight(); if ((mouse_over_icon >= 0) && ((size_t)mouse_over_icon < icon_list.size())) icon_list[mouse_over_icon]->set_highlight(true); float uoffset = 31.0/256.0, voffset = 31.0/256.0; #ifdef NEW_TEXTURES bind_texture(icons_text); #else /* NEW_TEXTURES */ get_and_set_texture_id(icons_text); voffset *= -1; #endif /* NEW_TEXTURES */ glColor3f(1.0f,1.0f,1.0f); glBegin(GL_QUADS); for (size_t i=0; i<icon_list.size(); ++i) { std::pair<float, float> uv = icon_list[i]->get_uv(); draw_2d_thing( uv.first, uv.second, uv.first+uoffset, uv.second+voffset, i*get_icon_size(), 0, i*get_icon_size()+(get_icon_size()-1), get_icon_size() ); } glEnd(); if (show_help_text && (mouse_over_icon >= 0) && ((size_t)mouse_over_icon < icon_list.size())) show_help(icon_list[mouse_over_icon]->get_help_message(), get_icon_size()*(mouse_over_icon+1)+2, 10); mouse_over_icon = -1; }
void get_and_set_particle_texture_id (int i) { #ifdef NEW_TEXTURES bind_texture(particle_textures[i]); #else /* NEW_TEXTURES */ get_and_set_texture_id(particle_textures[i]); #endif /* NEW_TEXTURES */ }
static void load_texture_from_screen(texture_asset* texture, int32 bottom_y, int32 x, int32 y, int32 width, int32 height) { texture->size = { width, height }; bind_texture(texture); set_texture_parameters(texture); CHECK_GL_ERROR(); glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, bottom_y - y - height, width, height, 0); CHECK_GL_ERROR(); }
int draw_string_zoomed_width (int x, int y, const unsigned char * our_string, int max_width, int max_lines, float text_zoom) { float displayed_font_x_size= DEFAULT_FONT_X_LEN*text_zoom; float displayed_font_y_size= DEFAULT_FONT_Y_LEN*text_zoom; unsigned char cur_char; int i; int cur_x,cur_y; int current_lines= 1; #ifdef OPENGL_TRACE CHECK_GL_ERRORS(); #endif //OPENGL_TRACE glEnable(GL_ALPHA_TEST);//enable alpha filtering, so we have some alpha key glAlphaFunc(GL_GREATER,0.1f); bind_texture(font_text); i=0; cur_x=x; cur_y=y; glBegin(GL_QUADS); while(1) { cur_char=our_string[i]; // watch for special characters if(!cur_char) // end of line { break; } else if (cur_char == '\n' || cur_char == '\r') // newline { cur_y+=displayed_font_y_size; cur_x=x; i++; current_lines++; if(current_lines>max_lines)break; continue; } else if (cur_x+displayed_font_x_size-x>=max_width){ cur_y+=displayed_font_y_size; cur_x=x; current_lines++; if(current_lines>max_lines)break; } cur_x+=draw_char_scaled(cur_char, cur_x, cur_y, displayed_font_x_size, displayed_font_y_size); i++; } glEnd(); glDisable(GL_ALPHA_TEST); #ifdef OPENGL_TRACE CHECK_GL_ERRORS(); #endif //OPENGL_TRACE return current_lines; }
void D3DUnitMap::set_texture(D3DGraphicContextProvider *gc, int index, const Texture &texture) { if (texture_units.size() < index + 1) texture_units.resize(index + 1); texture_units[index].object = texture; bind_texture(gc, index); set_sampler(gc, index, texture); }
void draw_string_small(int x, int y,const unsigned char * our_string,int max_lines) { //int displayed_font_x_size=SMALL_FONT_X_LEN; //int displayed_font_y_size=SMALL_FONT_Y_LEN; unsigned char cur_char; int i; int cur_x,cur_y; int current_lines=0; #ifdef OPENGL_TRACE CHECK_GL_ERRORS(); #endif //OPENGL_TRACE glEnable(GL_ALPHA_TEST);//enable alpha filtering, so we have some alpha key glAlphaFunc(GL_GREATER,0.1f); #ifdef NEW_TEXTURES bind_texture(font_text); #else /* NEW_TEXTURES */ get_and_set_texture_id(font_text); #endif /* NEW_TEXTURES */ i=0; cur_x=x; cur_y=y; glBegin(GL_QUADS); while(1) { cur_char=our_string[i]; if(!cur_char) { break; } else if(cur_char=='\n') { cur_y+=SMALL_FONT_Y_LEN; cur_x=x; i++; current_lines++; if(current_lines>=max_lines)break; continue; } cur_x+=draw_char_scaled(cur_char, cur_x, cur_y, SMALL_FONT_X_LEN, SMALL_FONT_Y_LEN); i++; } glEnd(); glDisable(GL_ALPHA_TEST); #ifdef OPENGL_TRACE CHECK_GL_ERRORS(); #endif //OPENGL_TRACE }
static void load_texture_from_pixels(texture_asset* texture, uint32* pixels, int32 width, int32 height) { Assert(pixels && width > 0 && height > 0); bind_texture(texture); set_texture_parameters(texture); texture->size = { width, height }; glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, pixels); CHECK_GL_ERROR(); if (texture->is_mipmapped) { glGenerateMipmap(GL_TEXTURE_2D); CHECK_GL_ERROR(); } }
//Retrieve image data from a texture, in unsigned char, RGBA format. unsigned char* graphics_get_texture_rgba(unsigned texture) { bind_texture(texture); int w,h; glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_WIDTH, &w); glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_HEIGHT,&h); unsigned char* ret = new unsigned char[(w*h) << 2]; glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, ret); return ret; }
void D3DUnitMap::bind_program(D3DGraphicContextProvider *gc, D3DProgramObjectProvider *program) { for (size_t i = 0; i < program->uniforms.size(); i++) { switch (program->uniforms[i].type) { case D3DUniform::type_sampler: if (sampler_units.size() < program->uniforms[i].value + 1) sampler_units.resize(program->uniforms[i].value + 1); for (int j = 0; j < shadertype_num_types; j++) sampler_units[program->uniforms[i].value].shader_index[j] = program->uniforms[i].shader_index[j]; bind_sampler(gc, program->uniforms[i].value); break; case D3DUniform::type_texture: if (texture_units.size() < program->uniforms[i].value + 1) texture_units.resize(program->uniforms[i].value + 1); for (int j = 0; j < shadertype_num_types; j++) texture_units[program->uniforms[i].value].shader_index[j] = program->uniforms[i].shader_index[j]; bind_texture(gc, program->uniforms[i].value); break; case D3DUniform::type_image: if (image_units.size() < program->uniforms[i].value + 1) image_units.resize(program->uniforms[i].value + 1); for (int j = 0; j < shadertype_num_types; j++) image_units[program->uniforms[i].value].shader_index[j] = program->uniforms[i].shader_index[j]; bind_image(gc, program->uniforms[i].value); break; } } for (size_t i = 0; i < program->uniform_blocks.size(); i++) { if (uniform_units.size() < program->uniform_blocks[i].value + 1) uniform_units.resize(program->uniform_blocks[i].value + 1); for (int j = 0; j < shadertype_num_types; j++) uniform_units[program->uniform_blocks[i].value].shader_index[j] = program->uniform_blocks[i].shader_index[j]; bind_uniform_buffer(gc, program->uniform_blocks[i].value); } for (size_t i = 0; i < program->storage_blocks.size(); i++) { if (storage_units.size() < program->storage_blocks[i].value + 1) storage_units.resize(program->storage_blocks[i].value + 1); for (int j = 0; j < shadertype_num_types; j++) { storage_units[program->storage_blocks[i].value].shader_srv_index[j] = program->storage_blocks[i].shader_srv_index[j]; storage_units[program->storage_blocks[i].value].shader_uav_index[j] = program->storage_blocks[i].shader_uav_index[j]; } bind_storage_buffer(gc, program->storage_blocks[i].value); } }
extern "C" void bind_appleseed_python_classes() { boost::python::scope().attr("APPLESEED_VERSION") = APPLESEED_VERSION; boost::python::scope().attr("APPLESEED_VERSION_MAJOR") = APPLESEED_VERSION_MAJOR; boost::python::scope().attr("APPLESEED_VERSION_MINOR") = APPLESEED_VERSION_MINOR; boost::python::scope().attr("APPLESEED_VERSION_PATCH") = APPLESEED_VERSION_PATCH; boost::python::scope().attr("APPLESEED_VERSION_MATURITY") = APPLESEED_VERSION_MATURITY; boost::python::scope().attr("APPLESEED_VERSION_STRING") = APPLESEED_VERSION_STRING; bind_utility(); bind_murmurhash(); bind_logger(); bind_vector(); bind_basis(); bind_quaternion(); bind_bbox(); bind_matrix(); bind_transform(); bind_entity(); bind_color(); bind_texture(); bind_bsdf(); bind_bssrdf(); bind_edf(); bind_shader_group(); bind_surface_shader(); bind_material(); bind_light(); bind_object(); bind_mesh_object(); bind_assembly(); bind_camera(); bind_environment(); bind_scene(); bind_image(); bind_aov(); bind_frame(); bind_fresnel(); bind_display(); bind_project(); bind_renderer_controller(); bind_tile_callback(); bind_master_renderer(); }
void draw_background_tiled_area_ext(int back,double x,double y,double x1,double y1,double x2,double y2, double xscale, double yscale, int color, double alpha) { get_background(bck2d,back); bind_texture(bck2d->texture); glPushAttrib(GL_CURRENT_BIT); glColor4ub(__GETR(color),__GETG(color),__GETB(color),char(alpha*255)); const float tbx=bck2d->texbordx,tby=bck2d->texbordy; float sw,sh,i,j,jj,left,top,width,height,X,Y; sw = bck2d->width*xscale; sh = bck2d->height*yscale; i = x1-(fmod(x1,sw) - fmod(x,sw)) - sw*(fmod(x1,sw)<fmod(x,sw)); j = y1-(fmod(y1,sh) - fmod(y,sh)) - sh*(fmod(y1,sh)<fmod(y,sh)); jj = j; glBegin(GL_QUADS); for(i=i; i<=x2; i+=sw) { for(j=j; j<=y2; j+=sh) { if(i <= x1) left = x1-i; else left = 0; X = i+left; if(j <= y1) top = y1-j; else top = 0; Y = j+top; if(x2 <= i+sw) width = ((sw)-(i+sw-x2)+1)-left; else width = sw-left; if(y2 <= j+sh) height = ((sh)-(j+sh-y2)+1)-top; else height = sh-top; glTexCoord2f(left/sw*tbx,top/sh*tby); glVertex2f(X,Y); glTexCoord2f((left+width)/sw*tbx,top/sh*tby); glVertex2f(X+width,Y); glTexCoord2f((left+width)/sw*tbx,(top+height)/sh*tby); glVertex2f(X+width,Y+height); glTexCoord2f(left/sw*tbx,(top+height)/sh*tby); glVertex2f(X,Y+height); } j = jj; } glEnd(); glPopAttrib(); }
void init_atlas_texture(FontAtlas* fa) { glActiveTexture(GL_TEXTURE0); glGenTextures(1, &fa->t.id); bind_texture(&fa->t); glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, fa->w, fa->h, 0, GL_RED, GL_UNSIGNED_BYTE, 0); /* We require 1 byte alignment when uploading texture data */ glPixelStorei(GL_UNPACK_ALIGNMENT, 1); /* Clamping to edges is important to prevent artifacts when scaling */ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); /* Linear filtering usually looks best for text */ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); }
void draw_console_pic(int which_texture) { #ifdef NEW_TEXTURES bind_texture(which_texture); glColor3f(1.0f,1.0f,1.0f); glBegin(GL_QUADS); //draw the texture glTexCoord2f(0.0f, 0.0f); glVertex3i(0,0,0); glTexCoord2f(0.0f, 1.0f); glVertex3i(0,window_height,0); glTexCoord2f(1.0f, 1.0f); glVertex3i(window_width,window_height,0); glTexCoord2f(1.0f, 0.0f); glVertex3i(window_width,0,0); glEnd(); #else /* NEW_TEXTURES */ get_and_set_texture_id(which_texture); glColor3f(1.0f,1.0f,1.0f); glBegin(GL_QUADS); //draw the texture glTexCoord2f(0.0f,1.0f); glVertex3i(0,0,0); glTexCoord2f(0.0f,0.0f); glVertex3i(0,window_height,0); glTexCoord2f(1.0f,0.0f); glVertex3i(window_width,window_height,0); glTexCoord2f(1.0f,1.0f); glVertex3i(window_width,0,0); glEnd(); #endif /* NEW_TEXTURES */ #ifdef OPENGL_TRACE CHECK_GL_ERRORS(); #endif //OPENGL_TRACE }
void draw_string_zoomed(int x, int y,const unsigned char * our_string,int max_lines, float text_zoom) { float displayed_font_x_size=11.0*text_zoom; float displayed_font_y_size=18.0*text_zoom; unsigned char cur_char; int i; int cur_x,cur_y; int current_lines=0; glEnable(GL_ALPHA_TEST);//enable alpha filtering, so we have some alpha key glAlphaFunc(GL_GREATER,0.1f); bind_texture(font_text); i=0; cur_x=x; cur_y=y; glBegin(GL_QUADS); while(1) { cur_char=our_string[i]; // watch for special characters if(!cur_char) // end of line { break; } else if (cur_char == '\n') // newline { cur_y+=displayed_font_y_size; cur_x=x; i++; current_lines++; if(current_lines>=max_lines)break; continue; } cur_x+=draw_char_scaled(cur_char, cur_x, cur_y, displayed_font_x_size, displayed_font_y_size); i++; } glEnd(); glDisable(GL_ALPHA_TEST); }
GLFluids::GLFluids(QWidget *parent) : QGLWidget(parent), QGLFunctions() { vbo = 0; wWidth = qMax(512, DIM); wHeight = qMax(512, DIM); hvfield = (float2 *)malloc(sizeof(float2) * DS); memset(hvfield, 0, sizeof(float2) * DS); // Allocate and initialize device data cudaMallocPitch((void **)&dvfield, &tPitch, sizeof(float2)*DIM, DIM); cudaMemcpy(dvfield, hvfield, sizeof(float2) * DS, cudaMemcpyHostToDevice); // Temporary complex velocity field data cudaMalloc((void **)&vxfield, sizeof(float2) * PDS); cudaMalloc((void **)&vyfield, sizeof(float2) * PDS); setup_texture(DIM, DIM); bind_texture(); // Create particle array particles = (float2 *)malloc(sizeof(float2) * DS); memset(particles, 0, sizeof(float2) * DS); initParticles(particles, DIM, DIM); // Create CUFFT transform plan configuration cufftPlan2d(&planr2c, DIM, DIM, CUFFT_R2C); cufftPlan2d(&planc2r, DIM, DIM, CUFFT_C2R); // TODO: update kernels to use the new unpadded memory layout for perf // rather than the old FFTW-compatible layout cufftSetCompatibilityMode(planr2c, CUFFT_COMPATIBILITY_FFTW_PADDING); cufftSetCompatibilityMode(planc2r, CUFFT_COMPATIBILITY_FFTW_PADDING); QTimer *timer = new QTimer(this); connect(timer, &QTimer::timeout, [&](){ simulateFluids(); updateGL(); }); timer->start(0); }
static __inline__ void draw_compass() { glPushMatrix(); glColor3f(1.0f,1.0f,1.0f); glTranslatef(float_minimap_size/2, float_minimap_size/2, 0.0f); if(rotate_minimap) glRotatef(-rz - 90, 0.0f,0.0f,1.0f ); else glRotatef(-90, 0.0f,0.0f,1.0f ); glRotatef(180, 1.0f,0.0f,0.0f ); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); #ifdef NEW_TEXTURES bind_texture(compass_tex); glBegin(GL_QUADS); glTexCoord2f(0.0f, 1.0f); glVertex2f(-float_minimap_size/2, float_minimap_size/2); glTexCoord2f(0.0f, 0.0f); glVertex2f(float_minimap_size/2, float_minimap_size/2); glTexCoord2f(1.0f, 0.0f); glVertex2f(float_minimap_size/2, -float_minimap_size/2); glTexCoord2f(1.0f, 1.0f); glVertex2f(-float_minimap_size/2, -float_minimap_size/2); glEnd(); #else /* NEW_TEXTURES */ bind_texture_id(compass_tex); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex2f(-float_minimap_size/2, float_minimap_size/2); glTexCoord2f(0.0f, 1.0f); glVertex2f(float_minimap_size/2, float_minimap_size/2); glTexCoord2f(1.0f, 1.0f); glVertex2f(float_minimap_size/2, -float_minimap_size/2); glTexCoord2f(1.0f, 0.0f); glVertex2f(-float_minimap_size/2, -float_minimap_size/2); glEnd(); #endif /* NEW_TEXTURES */ glDisable(GL_ALPHA_TEST); glDisable( GL_BLEND ); glPopMatrix(); }
static int bind_texture_cb ( ClientData cd, Tcl_Interp *ip, int argc, char *argv[]) { if ( argc != 3 ) { Tcl_AppendResult(ip, argv[0], ": invalid number of arguments\n", "Usage: ", argv[0], "<object name> <texture name>", (char *)0 ); return TCL_ERROR; } if (!bind_texture(argv[1], argv[2])) { Tcl_AppendResult(ip, argv[0], ": Could not bind texture ", argv[2], (char*)0); return TCL_ERROR; } return TCL_OK; }
void draw_string_small(int x, int y,const unsigned char * our_string,int max_lines) { int displayed_font_x_size=8; int displayed_font_y_size=15; unsigned char cur_char; int i; int cur_x,cur_y; int current_lines=0; glEnable(GL_ALPHA_TEST);//enable alpha filtering, so we have some alpha key glAlphaFunc(GL_GREATER,0.1f); bind_texture(font_text); i=0; cur_x=x; cur_y=y; glBegin(GL_QUADS); while(1) { cur_char=our_string[i]; if(!cur_char) { break; } else if(cur_char=='\n') { cur_y+=displayed_font_y_size; cur_x=x; i++; current_lines++; if(current_lines>=max_lines)break; continue; } cur_x+=draw_char_scaled(cur_char, cur_x, cur_y, displayed_font_x_size, displayed_font_y_size); i++; } glEnd(); glDisable(GL_ALPHA_TEST); }