wdl7770016
Senior Newbie 
|
 |
«
Posted
2012-08-05 15:26:28 » |
|
now I first use the Slick-Util which lwjgl recommand to load my game data(now just some image^_^) the code like these: 1 2 3 4 5 6 7 8
| png = new PNGImageData(); try { png.loadImage(ResourceLoader.getResourceAsStream("src/img/logo.png")); System.out.println(png.isRGB()); } catch (IOException e) { e.getStackTrace(); } |
then I draw image like these: 1 2 3
| GL14.glWindowPos2d(20, 20); GL11.glDrawPixels(142, 142, GL11.GL_RGB, GL11.GL_BYTE, png.getImageBufferData()); |
but the result is let me sad !! image can't display correct !! I don't know why? how about you to load image and draw it in openGL? (what I sad about is 2d Image not Texture, but I can't find any tutorial for 2D openGL) Thx for help^_^
|
|
|
|
wdl7770016
Senior Newbie 
|
 |
«
Reply #1 - Posted
2012-08-06 02:53:57 » |
|
is there anyone can help me? I ???really need help!!
|
|
|
|
ra4king
|
 |
«
Reply #2 - Posted
2012-08-06 03:29:06 » |
|
Try changing it to GL_RGBA and GL_UNSIGNED_BYTE
|
|
|
|
Games published by our own members! Check 'em out!
|
|
wdl7770016
Senior Newbie 
|
 |
«
Reply #3 - Posted
2012-08-06 04:03:32 » |
|
Sorry I just try it but the image is still error display... how do you to draw an 2d img in onpenGL? use Texture's bind? or GL11.glDrawPixels()?.... I want to make a 2d game using OpenGL but I just an Newer for it so I need your help.. Thx
|
|
|
|
ra4king
|
 |
«
Reply #4 - Posted
2012-08-06 06:16:25 » |
|
Images are drawn using textures. Bind the texture and draw a quad where you want the texture to show up. Don't forget to set the right texture coordinates (glTexCoords)
|
|
|
|
wdl7770016
Senior Newbie 
|
 |
«
Reply #5 - Posted
2012-08-06 08:18:10 » |
|
uh Thx but can we use use glDrawPixels() to direct draw image on screen? I want to know why glDrawPixels doesn't work well
|
|
|
|
wdl7770016
Senior Newbie 
|
 |
«
Reply #6 - Posted
2012-08-06 13:30:50 » |
|
If u use drawPixels please tell me why I can't render image rightly。。。
|
|
|
|
Riven
|
 |
«
Reply #7 - Posted
2012-08-06 13:34:44 » |
|
Merged topics. 
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings!
|
|
|
gimbal
|
 |
«
Reply #8 - Posted
2012-08-06 14:12:34 » |
|
uh Thx but can we use use glDrawPixels() to direct draw image on screen? I want to know why glDrawPixels doesn't work well
Might be worth mentioning what exactly is going wrong. Nothing appears? Crash? You see something but the pixels are garbage?
|
|
|
|
davedes
|
 |
«
Reply #9 - Posted
2012-08-06 14:16:07 » |
|
glDrawPixels requires passing around byte data from CPU to GPU, which may be potentially very huge and could potentially stall the pipeline. glTexImage2D will "store" the byte data in a texture on the GPU, allowing you to reuse it very quickly. If you're trying to draw a sprite, load it with SlickUtil's TextureLoader (which allows for more formats than just PNG). Then set the projection matrix to orthographic and render a quad. If that doesn't make sense, start with Google, the LWJGL wiki, and a modern OpenGL book. 
|
|
|
|
Games published by our own members! Check 'em out!
|
|
wdl7770016
Senior Newbie 
|
 |
«
Reply #10 - Posted
2012-08-07 05:18:58 » |
|
uh Thx but can we use use glDrawPixels() to direct draw image on screen? I want to know why glDrawPixels doesn't work well
Might be worth mentioning what exactly is going wrong. Nothing appears? Crash? You see something but the pixels are garbage? I have see something but pixels are garbage.... It's my code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| import java.io.IOException; import java.nio.ByteBuffer; import org.lwjgl.LWJGLException; import org.lwjgl.opengl.Display; import org.lwjgl.opengl.DisplayMode; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL14; import org.newdawn.slick.opengl.PNGImageData; import org.newdawn.slick.util.ResourceLoader;
public class GameMain2 { private ByteBuffer byteBuffer; public static void main(String[] args) { new GameMain2().launch(); }
public void launch() { try { Display.setDisplayMode(new DisplayMode(800, 600)); Display.setTitle("YourGame"); Display.create(); this.initGL(); } catch (LWJGLException e) { e.getStackTrace(); }
while (!Display.isCloseRequested()) { this.render(); Display.update(); Display.sync(60); } Display.destroy(); }
private void initGL() { GL11.glClearColor(0, 0, 0, 0); GL11.glOrtho(0, 800, 0, 600, -1, 1);
try { PNGImageData png = new PNGImageData(); png.loadImage(ResourceLoader.getResourceAsStream("src/img/logo.png")); this.byteBuffer = png.getImageBufferData(); } catch (IOException e) { e.getStackTrace(); } } private void render() { GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); GL14.glWindowPos2d(20, 20); GL11.glDrawPixels(142, 142, GL11.GL_RGB, GL11.GL_BYTE, this.byteBuffer); } } |
this is the image what I want to display(I don't know why img can't display, you can click it to display) :  and this is the garbage pixels what display:  Did you know where has wrong? I feel so anxious now....
|
|
|
|
gimbal
|
 |
«
Reply #11 - Posted
2012-08-07 07:43:20 » |
|
Weird. I would expect something like this when you have manual loading code, but you're just using standard Slick/LWJGL stuff.
I've managed to garbage up many an image in my day and it was usually because I fudged up the bit-order of the color components. The only thing I can come up with is to use GL_RGBA in stead of GL_RGB since its going to be 32 bits data with an alpha channel.
|
|
|
|
wdl7770016
Senior Newbie 
|
 |
«
Reply #12 - Posted
2012-08-07 08:27:03 » |
|
so is this error display cause by sllick-util’s internal mechanism? I just abuse the class and the methods in slick-util?
|
|
|
|
gimbal
|
 |
«
Reply #13 - Posted
2012-08-07 08:30:45 » |
|
So my suggestion didn't change anything?
I'm not too familiar with Slick but I like to believe that you are not the first person to use that code so you're not going to be the one that discovers that it is in fact broken. Simple reasoning.
|
|
|
|
wdl7770016
Senior Newbie 
|
 |
«
Reply #14 - Posted
2012-08-07 10:18:51 » |
|
So my suggestion didn't change anything?
I'm not too familiar with Slick but I like to believe that you are not the first person to use that code so you're not going to be the one that discovers that it is in fact broken. Simple reasoning.
sor my English is not good so may always miss what you say... but now just thought that there are glDrawPixels method in opengl but I had to use the Texture bind to make a 2D game it's feel so shit。。(may because I just a newer for opengl and I always think that use Texture may more waste performance because we should draw a rec and bind texture, but drawPixels just need draw it, right?)
|
|
|
|
davedes
|
 |
«
Reply #15 - Posted
2012-08-07 11:20:10 » |
|
Any issues with the image is likely because of the format you are specifying -- it should be an unsigned byte in either RGB, RGBA, LUMINANCE, or LUMINANCE_ALPHA depending on the output of the PNG decoder.
Read my earlier post.
|
|
|
|
theagentd
|
 |
«
Reply #16 - Posted
2012-08-07 11:40:30 » |
|
The images aren't loading, but I think I know what you're missing: alignment. OpenGL works with pixel alignments of 4 by default. Your image resolution is not dividable by 4. (142 / 4 = 35.5). Add this in initGL(): 1 2 3
| GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1); |
Textures are faster than glDrawPixels()! They are more difficult than glDrawPixels(), but they are faster because GPUs are made for drawing triangles with textures (in 3D games) and the texture is stored on the GPU's VRAM, so it does not have to be uploaded every frame.
|
Myomyomyo.
|
|
|
wdl7770016
Senior Newbie 
|
 |
«
Reply #17 - Posted
2012-08-07 13:14:33 » |
|
The images aren't loading, but I think I know what you're missing: alignment. OpenGL works with pixel alignments of 4 by default. Your image resolution is not dividable by 4. (142 / 4 = 35.5). Add this in initGL(): 1 2 3
| GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1); |
Textures are faster than glDrawPixels()! They are more difficult than glDrawPixels(), but they are faster because GPUs are made for drawing triangles with textures (in 3D games) and the texture is stored on the GPU's VRAM, so it does not have to be uploaded every frame. thanks for your help but it's still no work even if I add these code So now I don't want to think it until one day I know the cause 
|
|
|
|
davedes
|
 |
«
Reply #18 - Posted
2012-08-07 13:20:28 » |
|
... If you had taken my advice ... LWJGL Wiki - Loading Images with Slick-UtilMaybe you should start smaller -- learn the core concepts of programming, objects, etc. and try to make a simple Pong clone in LibGDX, Slick2D or another simple library. 
|
|
|
|
wdl7770016
Senior Newbie 
|
 |
«
Reply #19 - Posted
2012-08-07 13:27:34 » |
|
... If you had taken my advice ... LWJGL Wiki - Loading Images with Slick-UtilMaybe you should start smaller -- learn the core concepts of programming, objects, etc. and try to make a simple Pong clone in LibGDX, Slick2D or another simple library.  Thx for your advice I will try 
|
|
|
|
|