java - Drawn Image In OpenGL Comes Out Wrong Size And With Black Boxes In It -
im trying work on java project includes lwjgl. have come far "game" im drawing image screen.
the problem im getting drawn image gets drawn black boxes in , not correct size. here image of how looks visually.
here how actualy red square image should like:
here code use rendering opengl, cannot figure out im doing wrong.
public class renderer { //integers used player cordinates, taken player class using static variables int playerx; int playery; spritesheetloader spriteloader; texture player; public renderer(){ } public void initrenderer(){ //initialize opengl gl11.glmatrixmode(gl11.gl_projection); gl11.glloadidentity(); // resets previous projection matrices gl11.glortho(0, 800, 600, 0, 1, -1); gl11.glmatrixmode(gl11.gl_modelview); try { player = textureloader.gettexture("png",resourceloader.getresourceasstream("res/paddletemp.png")); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } } public void update(){ gl11.glclear( gl11.gl_color_buffer_bit | gl11.gl_depth_buffer_bit ); playerx = player.playerx; //gets player x , y player class using static variables playery = player.playery; player.bind(); gl11.glbegin(gl11.gl_quads); gl11.gltexcoord2f(0, 0); //top left gl11.glvertex2f(playerx, playery); gl11.gltexcoord2f(1,0); //top right gl11.glvertex2f(playerx + 50, playery); gl11.gltexcoord2f(1, 1); //bottom right gl11.glvertex2f(playerx + 50, playery + 150); gl11.gltexcoord2f(0, 1); //bottom left gl11.glvertex2f(playerx, playery + 150); gl11.glend(); }
sorry, i'm not absolutely sure problem is. can't seem reproduce afterwards, unfortunately. yet figured should solved 1 of following:
- unsupported image size
opengl relies heavily on images, resolution's width , height powers of 2 (when width/height=n*2). if images files aren't specification, lwjgl might act oddly. also, don't worry image files being squished. that's dependent on vertex input, not on texture input.
- unsupported image extension
try saving image files non-interlaced png files. slick_util, or whatever use loading image files, might not support images you're giving it.
- correction hints
as last resort, add following lines of code initialization code:
glhint(gl_perspective_correction_hint, gl_nicest); glhint(gl_line_smooth_hint, gl_nicest);
hopefully 1 of these tips helps you.
Comments
Post a Comment