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   
Pages: [1]
  ignore  |  Print  
  LWJGL - 0, 0 at Top Left, FBO issue  (Read 378 times)
0 Members and 1 Guest are viewing this topic.
Offline pwnedary

Senior Newbie





« Posted 2013-12-15 10:32:28 »

I've been making my own sort of 2D game engine matching my code style for fun. As a personal challenge I tried to give it the ability to swap LWJGL with Java2D by changing one line.
I am really new to LWJGL, so upon implementing off-screen rendering with FBOs I noticed they weren't working when I had 0, 0 being the top left corner of the screen as in Java2D.

EDIT: basically I can't get this to work: https://gist.github.com/pwnedary/8012530

Here it is working and drawing a blue square over the firefox logo:

but here it isn't:


I enter ortho with this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      glOrtho(0, width, height, 0, 1, -1); // 0,0 : top-left
     // glOrtho(0, width, 0, height, 1, -1); // 0,0 : bottom-left
     glMatrixMode(GL_MODELVIEW);

      glEnable(GL_TEXTURE_2D);
      glShadeModel(GL_SMOOTH);
      glDisable(GL_DEPTH_TEST);
      glDisable(GL_LIGHTING);
      glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
      glClearDepth(1);
      glEnable(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      glViewport(0, 0, width, height);


and construct FBO:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
      if (!GLContext.getCapabilities().GL_EXT_framebuffer_object) throw new Error("FBOs not supported");

      // Initialize frame buffer
     IntBuffer buffer = BufferUtils.createIntBuffer(1); // ByteBuffer.allocateDirect(1*4).order(ByteOrder.nativeOrder()).asIntBuffer(); // allocate a 1 int byte buffer
     EXTFramebufferObject.glGenFramebuffersEXT(buffer); // generate
     frameBufferID = buffer.get(0);

      image.bind();

      // Attach a texture
     bind();
      EXTFramebufferObject.glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, image.target, image.getTextureID(), 0);

      check(); // Check (from LWJGL's tutorial on FBOs)

      image.unbind();
      unbind();


and FBO.bind:
1  
2  
3  
      EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, frameBufferID);
      GL11.glPushAttrib(GL_VIEWPORT_BIT);
      GL11.glViewport(0, 0, image.getWidth(), image.getHeight());


Thanks in advance. I'm really desperate for posting this as I have had this problem for weeks.
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #1 - Posted 2013-12-15 12:48:48 »

Your glOrtho call is setting the origin in the top left. You had it right in the commented out call.

Offline pwnedary

Senior Newbie





« Reply #2 - Posted 2013-12-15 13:08:22 »

Yes I know and that is the problem, as I want the coordinate system to be the same as in normal Java2D/AWT.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline pwnedary

Senior Newbie





« Reply #3 - Posted 2013-12-17 21:00:11 »

To sum up, it's this I can't get to work: https://gist.github.com/pwnedary/8012530.
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 (16 views)
2014-08-31 22:59:12

TehJavaDev (23 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!