Show Posts
|
|
Pages: [1]
|
|
2
|
Discussions / General Discussions / Re: One qestion about lwjgl's getTime()
|
on: 2012-08-08 11:10:50
|
Sor I mean that what is time in Ticks? What is Ticks?...
getTime() returns the time in ticks, which is a unit that doesn't exactly mean anything until you get a resolution
*sighs* I think princec is right, you can't even read  but what you get about “getTime() returns the time in ticks, which is a unit that doesn't exactly mean anything until you get a resolution”? tell me getTime() return a long which that doesn't mean anything? but I ask that “you say if getTime = 100 and getTimerResolution = 100 then 1 second pass why?” 100*100=1second? it's crazy!!!:o
|
|
|
|
|
4
|
Discussions / General Discussions / Re: A problem for Java NIO FileChannel.map(....) don't work..why?
|
on: 2012-08-07 15:24:49
|
the .position() of the buffer is no indication of whether any data was loaded. When reading bytes from a mapped bytebuffer, the data is automatically loaded from disk - .position() is there for whatever you want to use it for. The data is there. sorry I had make a big mistake  You are trying to feed PNG encoded data into a method that expects pixels. so I can't direct use the png file because it had not decode right?
|
|
|
|
|
5
|
Discussions / General Discussions / Re: Why I draw an png image using glDrawPixels() can't work well?
|
on: 2012-08-07 15: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 
|
|
|
|
|
6
|
Discussions / General Discussions / A problem for Java NIO FileChannel.map(....) don't work..why?
|
on: 2012-08-07 13:00:51
|
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 65 66 67 68 69 70
| import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.channels.FileChannel.MapMode;
import org.lwjgl.LWJGLException; import org.lwjgl.opengl.Display; import org.lwjgl.opengl.DisplayMode; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL14;
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 { File f = new File("src/img/logo.png"); FileInputStream fileIn = new FileInputStream(f); FileChannel fc = fileIn.getChannel(); this.byteBuffer = fc.map(MapMode.READ_ONLY, 0, fc.size()); System.out.println(this.byteBuffer.position()); } 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); } } |
Q1:the System.out.println(this.byteBuffer.position()); is still return 0,which means that no byte map into byteBuffer.. Q2:when I use FileChannel.read() to read byte to byteBuffer it's ok,but when I render use glDrawPixels it always return : Number of remaining buffer elements is 4332, must be at least 60492. Because at most 60492 elements can be returned, a buffer with at least 60492 elements is required, regardless of actual returned element countI don't know what It means...
|
|
|
|
|
7
|
Discussions / General Discussions / Re: Why I draw an png image using glDrawPixels() can't work well?
|
on: 2012-08-07 12: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?)
|
|
|
|
|
10
|
Discussions / General Discussions / Re: Why I draw an png image using glDrawPixels() can't work well?
|
on: 2012-08-07 07: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....
|
|
|
|
|
11
|
Discussions / General Discussions / Re: One qestion about lwjgl's getTime()
|
on: 2012-08-07 05:52:05
|
you say if getTime = 100 and getTimerResolution = 100 then 1 second pass why? how you know ? I can't understand there are what connect between 100 and 100
getTime() returns the time in ticks
getTimerResolution() returns how many ticks there are in 1 second
Sor I mean that what is time in Ticks? What is Ticks?...
|
|
|
|
|
14
|
Discussions / General Discussions / Re: One qestion about lwjgl's getTime()
|
on: 2012-08-06 10:43:20
|
|
oh I must make an large mistake.... but I still can't understanding what is getTime() return you say if getTime = 100 and getTimerResolution = 100 then 1 second pass why? how you know ? I can't understand there are what connect between 100 and 100 .... end why I call getTime return values like these 21555184 21555201 21555217 21555234 and my getTimerResolution() return 1000 it means how many time pass? sorry for my stupid...
|
|
|
|
|
16
|
Discussions / General Discussions / Re: One qestion about lwjgl's getTime()
|
on: 2012-08-06 06:24:00
|
|
I'm sorry but I think you may miss my question now I will explain it more:(please read it Thx) 1.I know getTime() will return the time in ticks,for e.g when I call getTime() 1000 times perSecond on a machine which getTimerResolution() will return 1000 , it will return a long which interval is 1; 2.if now there is a machine which getTimerResolution() will return 100, so I call getTime() it's interval will be 10(= 1000/100)right? then for e.g when i call getTime() in two continuous ticks will return 6000 and 6010 so now calc them to millisecond(in fact, I don't understand what millisecond here?) 6000*1000/100(getTimerResolution())= 60000 6010*1000/100=60100 now I calc the delta time : 60100-60000=100(what is the unit?millisecond?why?I can't understand!!) thx for read it for so my ugly English grammer... wait for your help..
|
|
|
|
|
20
|
Discussions / General Discussions / Why I draw an png image using glDrawPixels() can't work well?
|
on: 2012-08-05 17: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^_^
|
|
|
|
|
21
|
Discussions / General Discussions / Re: One qestion about lwjgl's getTime()
|
on: 2012-08-04 12:35:47
|
|
thx for explain I'm sorry I was really stupid ... for example when I call Sys.getTime() it return 6034252 then I multi it with 1000 it became 6034252000 finally I divide it with Sys.getTimerResolution() which return 1000 then the result is 6034252 so I don't know why we need multi 1000...
|
|
|
|
|
23
|
Discussions / General Discussions / One qestion about lwjgl's getTime()
|
on: 2012-08-04 07:16:47
|
now there is a method in lwjgl's base tutorial Timing 1 2 3
| public long getTime() { return (Sys.getTime() * 1000) / Sys.getTimerResolution(); } |
what I want to know is that why Sys.getTime() need multi with 1000 and then div with Sys.getTimerResolution()?what does it mean? please explain it to me step by step!! thx!!
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|