Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  Java Game APIs & Engines / OpenGL Development / Re: UV mapping a mesh on: 2012-10-27 22:18:34
Thanks so much, that worked like a charm. Now that you mention it I do remember reading that somewhere.
Thanks again.
2  Java Game APIs & Engines / OpenGL Development / UV mapping a mesh on: 2012-10-27 17:50:47
Hello Everyone, a while back I did TheCodingUniverse's tutorial #24 and #25 to load in a .obj file and render the mesh and then later add lighting to it. After completing these tutorials I really wanted to figure out how to texture the mesh that I was rendering. So I went looking for tutorials with little luck. I eventually just tinkered with the .obj file and then modified the code for tutorial #24 to handle the Texture Coordinates and the UV Indices(not sure if thats correct name). Now that I have it somewhat working, I am still having an issue with rendering.

Here is a video of what I have so far, the video shows rendering the object as a mesh and then with the texture mapped onto it.
http://www.youtube.com/watch?v=A0R48j1HZp8

Here is the code
http://pastebin.java-gaming.org/9c0d20f922c

Just looking for some help on how to fix this issue.
-Zerali
3  Java Game APIs & Engines / OpenGL Development / Re: Opengl application stops responding on: 2012-07-20 22:13:22
Well the idea was to have a menu and then create the game object which would then in turn start the two threads once the person has chosen to play the game. Then the code should wait until the two threads complete and join back in with the main thread.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
public void play () {
      render.start();
      update.start();
     
      try {
         render.join();
         update.join();
      }
      catch(InterruptedException e) { }
     
   }


So I was releasing the opengl context from the main thread and then making it current to the render loop thread.

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  
public void run(){

      try {
         Display.makeCurrent();
      } catch (LWJGLException e) {
         e.printStackTrace();
      }
     
      lastFPS = getTime(); // call before loop to initialise fps timer
     startTime = lastFPS;
     
      while (!Display.isCloseRequested()) {
         int delta = getDelta();
         
         System.out.println("Render Loop");
               
         // Clear The Screen Buffer
        glClear(GL_COLOR_BUFFER_BIT);
         
         glColor3f(0.5f, 0.5f, 0.5f);
         glRectf(0, 0, windowWidth, windowHeight);
     
         
         Display.update();
         Display.sync(60); // cap fps to 60fps
        //updateFPS();
     }
   }
4  Java Game APIs & Engines / OpenGL Development / Opengl application stops responding on: 2012-07-20 20:55:24
Hey, I was trying to split up the game loop into an update loop and render loop. I finished but for some reason the application stops responding and can't figure out why. Wondering if anyone might have an idea as to why and how to fix it. I put all the code and put it into pastebin http://pastebin.java-gaming.org/f6427305b13
-Thanks
Zerali
5  Java Game APIs & Engines / OpenGL Development / Re: Green overlay when drawing textures on Quads [Solved] on: 2012-04-25 00:46:18
That was exactly what I was looking for!!!  Smiley

Thanks.
6  Java Game APIs & Engines / OpenGL Development / Re: Green overlay when drawing textures on Quads on: 2012-04-25 00:00:32
Thanks for the response. I messed with the two ways of scaling and I understand both ways. But this causes the texture on the quad to scale up and become "blurry", I would like the image to retain the same low resolution as the image gets larger. Thanks for all your help.
7  Java Game APIs & Engines / OpenGL Development / Re: Green overlay when drawing textures on Quads on: 2012-04-24 14:46:22
Solved the issue !!!! Grin

I added this line in the drawLevel function right before I draw the Quads with the textures on them.
1  
glColor3f(1.0f, 1.0f ,1.0f);


Also do you know If I can scale the textures?
8  Java Game APIs & Engines / OpenGL Development / Re: Green overlay when drawing textures on Quads on: 2012-04-24 14:38:52
Thanks for comments! I know that the image is rotated 180 degrees but for some reason it was loaded in rotated, so I rotated it back...

Here is my Main.java its what calls the drawLevel from my Level entity class.
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  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.lwjgl.LWJGLException;

import org.lwjgl.Sys;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;

import static org.lwjgl.opengl.GL11.*;
 
public class Main {
 
   /** time at last frame */
   private long lastFrame;
   /** frames per second */
   private int fps;
   /** last fps time */
   private long lastFPS;
   /** state of the game */
   private State state = State.INTRO;
   /** Level we are trying to load */
   private Level1 level;
   /** how far zoomed in we are*/
   private int zoom = 2;
   
   private static enum State {
      INTRO,MAIN_MENU,GAME;
   }
 
   public void start() {
      try {
         Display.setDisplayMode(new DisplayMode(800, 500));
         Display.create();
      } catch (LWJGLException e) {
         e.printStackTrace();
         System.exit(0);
      }
 
      initGL(); // init OpenGL
     getDelta(); // call once before loop to initialise lastFrame
     lastFPS = getTime(); // call before loop to initialise fps timer
     level = new Level1("temp",8);
 
      while (!Display.isCloseRequested()) {
         int delta = getDelta();
 
         update(delta);
         renderGL();
 
         Display.update();
         Display.sync(60); // cap fps to 60fps
     }
 
      Display.destroy();
   }
 
   public void update(int delta) {
             
      switch(state) {
         case INTRO:
            if (Keyboard.isKeyDown(Keyboard.KEY_S)) {
               state = State.MAIN_MENU;
               System.out.println("Go to Main menu");
            }
            break;
         case MAIN_MENU:
            if (Keyboard.isKeyDown(Keyboard.KEY_RETURN)) {
               state = State.GAME;
               System.out.println("Go to Game");
            }
            break;
         case GAME:
            if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
               state = State.MAIN_MENU;
               System.out.println("Go to Main menu");
            }
            if(Keyboard.isKeyDown(Keyboard.KEY_ADD)) {
               zoom++;
            }
            if(Keyboard.isKeyDown(Keyboard.KEY_SUBTRACT)) {
               zoom--;
            }
            break;
      }
           
      updateFPS(); // update FPS Counter
  }
   
   
   /**
    * Calculate how many milliseconds have passed
    * since last frame.
    *
    * @return milliseconds passed since last frame
    */

   public int getDelta() {
       long time = getTime();
       int delta = (int) (time - lastFrame);
       lastFrame = time;
 
       return delta;
   }
 
   /**
    * Get the accurate system time
    *
    * @return The system time in milliseconds
    */

   public long getTime() {
       return (Sys.getTime() * 1000) / Sys.getTimerResolution();
   }
 
   /**
    * Calculate the FPS and set it in the title bar
    */

   public void updateFPS() {
      if (getTime() - lastFPS > 1000) {
         Display.setTitle("FPS: " + fps);
         fps = 0;
         lastFPS += 1000;
      }
      fps++;
   }
 
   public void initGL() {
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      glOrtho(0, 800, 0, 500, 1, -1);
      glMatrixMode(GL_MODELVIEW);
      glEnable(GL_TEXTURE_2D);
   }
 
   public void renderGL() {
      // Clear The Screen And The Depth Buffer
     glClear(GL_COLOR_BUFFER_BIT);
       
      switch(state) {
         case INTRO:
            glColor3f(1.0f, 0.0f, 0.0f);
            glRectf(0, 0, 800, 500);
            break;
         case MAIN_MENU:
            glColor3f(0.0f, 1.0f, 0.0f);
            glRectf(0, 0, 800, 500);
            break;
         case GAME:
            level.drawLevel(zoom);            
            break;
      }
   }
 
   public static void main(String[] argv) {
      Main Game = new Main();
      Game.start();
   }
}


And I can't figure out how to add an image to a post, please let me know how to.
9  Java Game APIs & Engines / OpenGL Development / Green overlay when drawing textures on Quads [Solved] on: 2012-04-24 06:26:24
Hello everyone, this is my first post so bear with me. I have been teaching my self Java and Game development for the past few months. I messed with Java Awt library a bit but I have now started to learn LWJGL  Grin. However I am having some trouble with the code below. It does what I want, which is drawing the texture onto the Quad but it has a weird green overlay. I noticed that this was caused when I added the following statement to the initialization code. I am using Slick2Ds Texture and TextureLoader class, here is my code below...

Line that adds the green Overlay
1  
glEnable(GL_TEXTURE_2D);


Initialization code which is called in Main.java
1  
2  
3  
4  
5  
6  
7  
public void initGL() {
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      glOrtho(0, 800, 0, 500, 1, -1);
      glMatrixMode(GL_MODELVIEW);
      glEnable(GL_TEXTURE_2D);
   }


Testing drawing textures on Quads, called in my Level Entity class
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  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
public void drawLevel(int zoom) {
      int w = 8*zoom;
     
//      for(int x = 0; x < 800; x+=w) {
//         for(int y = 0; y < 500; y+=w) {
//            
//            glColor3f(256, 256, 256);
//            glPushMatrix();
//               glBegin(GL11.GL_QUADS);
//                  glVertex2f(x-4,y-4);
//                  glVertex2f(x+4,y-4);
//                  glVertex2f(x+4,y+4);
//                  glVertex2f(x-4,y+4);
//               glEnd();
//            glPopMatrix();
//         }
//      }
     int x;
      int y;
     
      glClear(GL_COLOR_BUFFER_BIT);
     
      grass.bind();
      x = 40;
      y = 64;
      glPushMatrix();
         glBegin(GL11.GL_QUADS);
            glTexCoord2f(1,1);
            glVertex2f(x-32,y-32);
            glTexCoord2f(0,1);
            glVertex2f(x+32,y-32);
            glTexCoord2f(0,0);
            glVertex2f(x+32,y+32);
            glTexCoord2f(1,0);
            glVertex2f(x-32,y+32);
         glEnd();
      glPopMatrix();
     
      dirt.bind();
      x += 64;
      glBegin(GL_QUADS);
         glTexCoord2f(1,1);
         glVertex2f(x-32,y-32);
         glTexCoord2f(0,1);
         glVertex2f(x+32,y-32);
         glTexCoord2f(0,0);
         glVertex2f(x+32,y+32);
         glTexCoord2f(1,0);
         glVertex2f(x-32,y+32);
      glEnd();
     
      dirt2.bind();
      x += 64;
      glBegin(GL_QUADS);
         glTexCoord2f(1,1);
         glVertex2f(x-32,y-32);
         glTexCoord2f(0,1);
         glVertex2f(x+32,y-32);
         glTexCoord2f(0,0);
         glVertex2f(x+32,y+32);
         glTexCoord2f(1,0);
         glVertex2f(x-32,y+32);
      glEnd();
     
      brick.bind();
      x += 64;
      glBegin(GL_QUADS);
         glTexCoord2f(1,1);
         glVertex2f(x-32,y-32);
         glTexCoord2f(0,1);
         glVertex2f(x+32,y-32);
         glTexCoord2f(0,0);
         glVertex2f(x+32,y+32);
         glTexCoord2f(1,0);
         glVertex2f(x-32,y+32);
      glEnd();
     
      cement.bind();
      x += 64;
      glBegin(GL_QUADS);
         glTexCoord2f(1,1);
         glVertex2f(x-32,y-32);
         glTexCoord2f(0,1);
         glVertex2f(x+32,y-32);
         glTexCoord2f(0,0);
         glVertex2f(x+32,y+32);
         glTexCoord2f(1,0);
         glVertex2f(x-32,y+32);
      glEnd();
   }
}


Would like to add an Image but I am unsure how.

I am also interested in a way to scale the textures I am using up to different sizes, if any one knows, which I am sure someone does  Wink....
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.

Dwinin (22 views)
2014-09-12 09:08:26

Norakomi (55 views)
2014-09-10 13:57:51

TehJavaDev (66 views)
2014-09-10 06:39:09

Tekkerue (33 views)
2014-09-09 02:24:56

mitcheeb (54 views)
2014-09-08 06:06:29

BurntPizza (38 views)
2014-09-07 01:13:42

Longarmx (24 views)
2014-09-07 01:12:14

Longarmx (30 views)
2014-09-07 01:11:22

Longarmx (28 views)
2014-09-07 01:10:19

mitcheeb (37 views)
2014-09-04 23:08:59
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!