java - LWJGL: Creating a semi Transparent Rectangle and then adding a Rectangle with a texture over it -
im trying what's described in title, heres code far create rect texture not semi transparent 1 should appear behind it:
public static void draw(){ glpushmatrix(); game.res.pausetexture.bind(); gl11.glcolor4f(0,0, 0 , 0.5f); glbegin(gl11.gl_quads); { glvertex2f(0, 0); glvertex2f(game.winx,0 ); glvertex2f(game.winx, game.winy); glvertex2f(0, game.winy); } glend(); gl11.glcolor3f(1,1, 1); gl11.gltranslatef(game.winx/2 - 250, game.winy/2 - 350, 0); gl11.gltexparameteri(gl11.gl_texture_2d, gl11.gl_texture_mag_filter, gl11.gl_nearest); glbegin(gl11.gl_quads); { gltexcoord2f(0, 0); glvertex2f(0, 0); gltexcoord2f(game.res.pausetexture.getwidth(), 0); glvertex2f(500,0 ); gltexcoord2f(game.res.pausetexture.getwidth(), game.res.pausetexture.getheight()); glvertex2f(500, 700); gltexcoord2f(0, game.res.pausetexture.getheight()); glvertex2f(0, 700); } glend(); glpopmatrix();
}
i happy if tell me solution this.
thanks
if understand question correctly, need enable blending , tell opengl blend using alpha channels.
so need add following initialize opengl states. can of course add rendering loop itself, though less use of opengl calls better.
glenable(gl_blend); glblendfunc(gl_src_alpha, gl_one_minus_src_alpha);
if have things don't want affected transparency/opacity need disable blending, so.
gldisable(gl_blend); ... render stuff ... glenable(gl_blend); ... render stuff ...
incase don't statically import different classes here same code though classes.
gl11.glenable(gl11.gl_blend); gl11.glblendfunc(gl11.gl_src_alpha, gl11.gl_one_minus_src_alpha); ... gl11.gldisable(gl11.gl_blend);
Comments
Post a Comment