java - Why doesn't this want to draw more than once? -


i'm learning opengl , want draw 50 texture(from 1 variable) do: in update method:

public void update(){ while(!display.iscloserequested()){ input(); for(int x = 0; x< 100; x++){ block = new grassblock(x*32,10); block.draw(); } display.update(); display.sync(60); } } 

this how init opengl:

 private void initgl(){ glenable(gl_texture_2d); glclearcolor(0.0f, 0.0f, 0.0f, 0.0f); glenable(gl_blend); glblendfunc(gl_src_alpha, gl_one_minus_src_alpha); glviewport(0, 0,640 , 480); glmatrixmode(gl_modelview); glmatrixmode(gl_projection); glloadidentity(); glortho(0,640 , 480, 0, 1, -1); glmatrixmode(gl_modelview); } 

this grassblock draw method:

@override public void draw() { grass.bind(); glbegin(gl_quads); gltexcoord2f(0, 0); glvertex2f(100, 100); gltexcoord2f(1, 0); glvertex2f(100+grass.gettexturewidth(),100); gltexcoord2f(1,1); glvertex2f(100+grass.gettexturewidth(),100+grass.gettextureheight()); gltexcoord2f(0,1); glvertex2f(100,100+grass.gettextureheight()); glend(); } 

also, know cannot put block creation in update method because loops, how solve can draw multiple texture's 1 variable?

now 1 , flickering.

you forgot clear depth buffer

glclear(gl_color_buffer_bit | gl_depth_buffer_bit); ^^^^^^^^^^^^^^^^^^^^^ 

also of code in initgl belongt @ beginning of redraw function. dimensions of viewport should taken requesting window's size graphics system.

glviewport(0, 0,640 , 480); glmatrixmode(gl_modelview); <<<<<<<< glmatrixmode(gl_projection); glloadidentity(); 

the switch modelview matrix there nothing, switch projection after.

it's practice reset matrices identity @ beginning of drawing function, start of known state.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -