c++ - Texture isn't mapped to quad -
i'm using next draw text in opengl (using sdl)
void rendertext(const ttf_font *font, const sdl_color color, const double& x, const double& y, const double& z, const std::string& text) { bool textured = glisenabled(gl_texture_2d); glenable(gl_texture_2d); //test color: black glcolor3f(0,0,0); sdl_surface *message = ttf_rendertext_blended(const_cast<ttf_font*>(font), text.c_str(), color); gluint texture = 0; //generate opengl 2d texture sdl_surface glgentextures(1, &texture); glbindtexture(gl_texture_2d, texture); gltexparameterf(gl_texture_2d, gl_texture_min_filter, gl_linear); gltexparameterf(gl_texture_2d, gl_texture_mag_filter, gl_linear); glteximage2d(gl_texture_2d, 0, gl_rgba, message->w, message->h, 0, gl_bgra, gl_unsigned_byte, message->pixels); //draw texture on quad given xyz coordinates. glbegin(gl_quads); gltexcoord2d(0, 0); glvertex3d(x, y, z); gltexcoord2d(1, 0); glvertex3d(x+message->w, y, z); gltexcoord2d(1, 1); glvertex3d(x+message->w, y+message->h, z); gltexcoord2d(0, 1); glvertex3d(x, y+message->h, z); glend(); //clean gldeletetextures(1, &texture); sdl_freesurface(message); if (!textured) gldisable(gl_texture_2d); } however, thing shown rectangle @ (x,y) (in case (10,10)) background color set glcolor3f (black in case). texture created sdl_surface isn't shown on quad. arguments passed function valid:
font: loaded ttf_font != null color: sdl_color {255,255,255} (white) x = 10 y = 10 z = 0 text = "test" what's wrong here?
glortho(0.0, screen_width, screen_height, 0.0, -1.0, 10.0); opengl v2.2 sdl v1.2.15 kubuntu raring x64 update: when using ..._solid instead of ..._blended, calling glcolor3f(1,1,1) , passing sdl_color {255,255,255} results in unusual stuff:
the quad appears should appear, , shows unusual content. what's wrong?
the problem didn't phone call glblendfunc before calling above method. opengl had wrong blending mode set. after using glblendfunc(gl_src_alpha, gl_one_minus_src_alpha);it looks fine.
c++ opengl sdl
No comments:
Post a Comment