Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (492)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Discussions / General Discussions / Re: One qestion about lwjgl's getTime() on: 2012-08-08 11:03:56
Sorry for my bad English to waste your free times Sad
and Thx for your enthusiastic to my stupid
Now I had really know it
good luck
2  Discussions / General Discussions / Re: One qestion about lwjgl's getTime() on: 2012-08-08 09: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 Sad

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
3  Discussions / General Discussions / Re: Why I draw an png image using glDrawPixels() can't work well? on: 2012-08-07 13:27:34
... If you had taken my advice ...

LWJGL Wiki - Loading Images with Slick-Util

Maybe 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. Smiley

Thx for your advice
 I will try Cheesy
4  Discussions / General Discussions / Re: A problem for Java NIO FileChannel.map(....) don't work..why? on: 2012-08-07 13:24:49
Quote
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 Tongue

Quote
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 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  Roll Eyes
6  Discussions / General Discussions / A problem for Java NIO FileChannel.map(....) don't work..why? on: 2012-08-07 11: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;
   /**
    *
    * @param args
    */

   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);

      //GL11.glEnable(GL11.GL_TEXTURE_2D);
     
      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());
         //fileIn.close();
        System.out.println(this.byteBuffer.position());
      }
      catch (IOException e) {
         e.getStackTrace();
      }
   }
   
   private void render() {
      GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
      //GL11.glColor3f(0, 1, 1);
     GL14.glWindowPos2d(20, 20);
      //GL11.glBitmap(142, 142, 0, 0, 0, 0, this.byteBuffer);
     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 count
I 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 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?)
8  Discussions / General Discussions / Re: One qestion about lwjgl's getTime() on: 2012-08-07 08:29:21
hehe  sor 
I admit I'm so stupid..
but I want to learn  Smiley
9  Discussions / General Discussions / Re: Why I draw an png image using glDrawPixels() can't work well? on: 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?
10  Discussions / General Discussions / Re: Why I draw an png image using glDrawPixels() can't work well? on: 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;
   /**
    *
    * @param args
    */

   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);

      //GL11.glEnable(GL11.GL_TEXTURE_2D);
     
      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);
      //GL11.glColor3f(0, 1, 1);
     GL14.glWindowPos2d(20, 20);
      //GL11.glBitmap(142, 142, 0, 0, 0, 0, this.byteBuffer);
     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 03: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?...
12  Discussions / General Discussions / Is there anyone draw 2d image in opengl using glDrawPixels()?not useTexture bind on: 2012-08-06 13:30:50
If u use drawPixels please tell me why I can't render image rightly。。。
13  Discussions / General Discussions / Re: One qestion about lwjgl's getTime() on: 2012-08-06 12:16:19
OK  I will just use it now
it's principle make me really a headache...
14  Discussions / General Discussions / Re: One qestion about lwjgl's getTime() on: 2012-08-06 08: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...
15  Discussions / General Discussions / Re: Why I draw an png image using glDrawPixels() can't work well? on: 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
16  Discussions / General Discussions / Re: One qestion about lwjgl's getTime() on: 2012-08-06 04: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..
17  Discussions / General Discussions / Re: Why I draw an png image using glDrawPixels() can't work well? on: 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
18  Discussions / General Discussions / Re: Why I draw an png image using glDrawPixels() can't work well? on: 2012-08-06 02:53:57
is there anyone can help me? I  ???really need help!!
19  Discussions / General Discussions / Re: One qestion about lwjgl's getTime() on: 2012-08-05 15:41:14
thx now I had read yours replys
so I had learn more...
but the lwjgl 's timer tutorial still don't explain why Sys.getTime() * 1000 then / Sys.getTimerResolution() will return millisecond?
then how can i calculate nanosecond?
20  Discussions / General Discussions / Why I draw an png image using glDrawPixels() can't work well? on: 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.glBitmap(142, 142, 0, 0, 0, 0, this.byteBuffer);
     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 10: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...
22  Discussions / General Discussions / Re: One qestion about lwjgl's getTime() on: 2012-08-04 09:15:56
uh  thx for help me
but I still can't understand why any number multi with 1000 it will be millisecond?
23  Discussions / General Discussions / One qestion about lwjgl's getTime() on: 2012-08-04 05: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!!
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (16 views)
2014-08-31 22:59:12

TehJavaDev (24 views)
2014-08-28 18:26:30

CopyableCougar4 (33 views)
2014-08-22 19:31:30

atombrot (42 views)
2014-08-19 09:29:53

Tekkerue (41 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (26 views)
2014-08-16 06:20:21

Tekkerue (37 views)
2014-08-16 06:12:11

Rayexar (73 views)
2014-08-11 02:49:23

BurntPizza (49 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!