Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (489)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (555)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [SOLVED] Gap Between Edge of Window and Viewport [LWJGL]  (Read 617 times)
0 Members and 1 Guest are viewing this topic.
Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Posted 2013-11-28 17:01:51 »

So this is my problem.


I'm not sure why I'm getting the black gap and it's really bugging me. It disappears when I resize the window. This is my code:

Setting up the window:
1  
Display.setDisplayMode(new DisplayMode(800, 600));


Initializing the camera:
1  
glOrtho(0, 800, 0, 600, 1, -1);


Rendering:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
@Override
public void render() {
   glClearColor(1f, 0f, 0f, 0f);
   glClear(GL_COLOR_BUFFER_BIT);

   glPushMatrix();
   glTranslatef(x, y, 0);

   glBegin(GL_QUADS);
   glVertex2f(0, 0);
   glVertex2f(100, 0);
   glVertex2f(100, 100);
   glVertex2f(0, 100);
   glEnd();
   glPopMatrix();
}


Am I missing something or am I doing something wrong?

Why are all OpenGL tutorials written in Brainf**k?
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #1 - Posted 2013-11-28 22:37:46 »

Did you set the viewport? Can I see where you initialize your matrices?

Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Reply #2 - Posted 2013-11-28 22:40:57 »

Only correcting when you resize? Try looking in your resize method and see if there's anything there that's not there when you create the window.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Reply #3 - Posted 2013-11-29 13:31:07 »

Oh my resize method is simply
1  
2  
3  
4  
@Override
public void resize() {
   glViewport(0, 0, Display.getWidth(), Display.getHeight());
}


I tried calling resize after I set up the camera but nothing happens.

Can I see where you initialize your matrices?

Do you mean this?
1  
2  
3  
4  
5  
6  
7  
8  
@Override
public void initialize() {
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();

   glMatrixMode(GL_MODELVIEW);
   glOrtho(0, 800, 0, 600, 1, -1);
}


Should I be replacing the projection matrix with the identity matrix?

Why are all OpenGL tutorials written in Brainf**k?
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #4 - Posted 2013-11-29 19:44:21 »

And you call resize straight away after initializing the game? Throw in a resize call after your modelview matrix call.

Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Reply #5 - Posted 2013-11-30 10:55:31 »

And you call resize straight away after initializing the game? Throw in a resize call after your modelview matrix call.

I've already tried that and it doesn't work. I'm really confused. :/
This is my game loop:

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  
@Override
public void gameLoop() {
   long currentFrame;
   long lastFrame = getCurrentTime();
   initialize();

   while (!Display.isCloseRequested()) {
      currentFrame = getCurrentTime();
      update(currentFrame - lastFrame);

      if (Display.wasResized()) {
         resize();
      }

      if (Display.isVisible() || Display.isDirty()) {
         render();
         if (Display.isActive()) {
            Display.sync(60);
         } else {
            try {
               Thread.sleep(100);
            } catch (InterruptedException e) {
               System.out.println(NAME + ": Error sleeping.");
            }
         }
      }

      Display.update();
      lastFrame = currentFrame;
   }

   dispose();
}

Why are all OpenGL tutorials written in Brainf**k?
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #6 - Posted 2013-11-30 11:19:15 »

Huh, that's odd! I've had it happen to me before, but I just ignored it and eventually I must have changed some code around and it went away... Hold on I'll go look for some code for you to try.

Edit:
In your render method you clear the color before clearing the screen, switch those two, I don't think it will make much of a difference, but I think they should be switched anyway.

This code is straight from my NEngine library, and I know it works. Here's how I create a new window:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public static void createWindow(int width, int height, String title, boolean mouseCaptured) {
      try {
         Display.setDisplayMode(new DisplayMode(width, height));
         Display.setTitle(title);
         Mouse.setGrabbed(mouseCaptured);
         Display.create();
      } catch (LWJGLException e) {
         e.printStackTrace();
      }
   }

Here's how I set up my viewport and ortho projection:
1  
2  
3  
4  
5  
6  
7  
8  
public static void renderOrtho(double left, double right, double bottom, double top){
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
     
      glMatrixMode(GL_MODELVIEW);
      glOrtho(left, right, bottom, top, 1, -1);
      glViewport(0, 0, Display.getWidth(), Display.getHeight());
   }

Generally, I call that method with these parameters:
1  
ScreenTools.renderOrtho(0, WIDTH, 0, HEIGHT);

Obviously, this would put the origin in the bottom left corner.

Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Reply #7 - Posted 2013-11-30 11:30:06 »

In your render method you clear the color before clearing the screen, switch those two, I don't think it will make much of a difference, but I think they should be switched anyway.

Aren't I clearing the screen by clearing the colour?  Undecided

Why are all OpenGL tutorials written in Brainf**k?
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #8 - Posted 2013-11-30 11:31:59 »

In your render method you clear the color before clearing the screen, switch those two, I don't think it will make much of a difference, but I think they should be switched anyway.

Aren't I clearing the screen by clearing the colour?  Undecided
Well, glClear(GL_COLOR_BUFFER_BIT) is clearing the color buffer, which with the glClearColor call you just added color I believe? I don't know, I haven't looked too much into it, but I've never seen any code where someone clears the color and then the buffer.

Edit:
Try making a new project and just create a window and update it, no game loop or anything. Then clear the color and add in the matrix calls and see if the problem still persists.

Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Reply #9 - Posted 2013-11-30 11:39:11 »

Oh I fixed it by changing this:
1  
2  
3  
4  
5  
6  
7  
public Application() throws LWJGLException {
   Display.setDisplayMode(new DisplayMode(800, 600));
   Display.setVSyncEnabled(true);
   Display.setTitle("A game using the LWJGL");
   Display.create();
   Display.setResizable(true);
}


to this:
1  
2  
3  
4  
5  
6  
7  
public Application() throws LWJGLException {
   Display.setDisplayMode(new DisplayMode(800, 600));
   Display.setVSyncEnabled(true);
   Display.setTitle("A game using the LWJGL");
   Display.setResizable(true);
   Display.create();
}


I was thinking the problem was with the viewport.  Angry

Well, glClear(GL_COLOR_BUFFER_BIT) is clearing the color buffer, which with the glClearColor call you just added color I believe? I don't know, I haven't looked too much into it, but I've never seen any code where someone clears the color and then the buffer.

I thought the glClearColor(...) call set the colour of the color buffer and glClear(GL_COLOR_BUFFER_BIT) actually cleared the colour buffer. Please correct me if I'm wrong.

Why are all OpenGL tutorials written in Brainf**k?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #10 - Posted 2013-11-30 11:44:47 »

Ah yes, that resizable call would do it, good job! Also, vSync is only useful in a full screen context, and it would just hog your resources in a non full screen window, so I wouldn't recommend enabling it!

About the glClear and stuff, this is straight from the docs:

glClearColor - glClearColor specifies the red, green, blue, and alpha values used by glClear to clear the color buffers. Values specified by glClearColor are clamped to the range 0 1 .

glClear - glClear sets the bitplane area of the window to values previously selected by glClearColor, glClearDepth, and glClearStencil.

Huh, I guess I was wrong! Apparently you're right, glClear clears the buffer to the color specified by glClearColor. Well, thanks for telling me that Smiley

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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 (13 views)
2014-08-31 22:59:12

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

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

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

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

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

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

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

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

BurntPizza (47 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!