Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (600)
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} help on understanding openGl initialization  (Read 1241 times)
0 Members and 1 Guest are viewing this topic.
Offline alaslipknot
« Posted 2013-05-16 16:04:50 »

Hello,
i've been trying to solve the problem am facing with rendering Font using SlickUtile in Lwjgl, and it appears that the issue is due because of the OpenGL initialization (the low FPS was because i initialize variable inside the game loop  Tongue )
anyway,
i tried to render a text in a simple pong game, and the result was this (the white rectangle is the text) :

that result happens when i use this openGl initialization :
1  
2  
3  
4  
5  
6  
7  
8  
private void initGL() {
      GL11.glMatrixMode(GL11.GL_PROJECTION);
      GL11.glLoadIdentity();
      GL11.glOrtho(0, 800, 0, 600, 1, -1);
      GL11.glMatrixMode(GL11.GL_MODELVIEW);
      GL11.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

   }


and if i use this initialization (from the FontExample of the lwjgl wiki )
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
GL11.glEnable(GL11.GL_TEXTURE_2D);
      GL11.glShadeModel(GL11.GL_SMOOTH);        
      GL11.glDisable(GL11.GL_DEPTH_TEST);
      GL11.glDisable(GL11.GL_LIGHTING);                    
 
      GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);                
        GL11.glClearDepth(1);                                      
 
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
 
        GL11.glViewport(0,0,width,height);
      GL11.glMatrixMode(GL11.GL_MODELVIEW);
 
      GL11.glMatrixMode(GL11.GL_PROJECTION);
      GL11.glLoadIdentity();
      GL11.glOrtho(0, width, height, 0, 1, -1);
      GL11.glMatrixMode(GL11.GL_MODELVIEW);

i get this result :


PS :
sorry if you are reading this post and there isn't enough information in it, i hit the post button by mistake



thank you

"It's not at all important to get it right the first time. It's vitally important to get it right the last time."
Offline Simn
« Reply #1 - Posted 2013-05-16 16:08:45 »

This tutorial breaks it down quite nice.

- Simn
Offline alaslipknot
« Reply #2 - Posted 2013-05-16 16:36:05 »

This tutorial breaks it down quite nice.
thank you, i know that channel he make the examples from the wiki into a videos,
ps :
i can render Font only, what i can't do is font and other graphics 

"It's not at all important to get it right the first time. It's vitally important to get it right the last time."
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline opiop65

JGO Kernel


Medals: 160
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #3 - Posted 2013-05-16 18:49:18 »

I think its kind of obvious what you need to do here... when you want to render text, you use the init code you found on the wiki and when you want to render the game, you use the first init method. However, I think you should notice that the only big changes between the two is that the second approach disables lighting and enables blending.

Offline alaslipknot
« Reply #4 - Posted 2013-05-16 19:19:35 »

I think its kind of obvious what you need to do here... when you want to render text, you use the init code you found on the wiki and when you want to render the game, you use the first init method.

Is this possible ?? the openGL init is done before the game loop once it's called it will never be updated so how can i do such thing ?
thank you

"It's not at all important to get it right the first time. It's vitally important to get it right the last time."
Offline alaslipknot
« Reply #5 - Posted 2013-05-16 19:23:44 »

Guys here is a full working example of this pong game,
http://pastebin.java-gaming.org/57da6698f5c
can you please try to test it and tell me how can i render the text and the game graphics together ?
thank you very much

"It's not at all important to get it right the first time. It's vitally important to get it right the last time."
Offline Simn
« Reply #6 - Posted 2013-05-16 19:32:39 »

I'm not sure, but I think you'll have to call the initGL (from LWJGL's wiki) before the font.drawString() method, and then call your own initGL after that.

- Simn
Offline opiop65

JGO Kernel


Medals: 160
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #7 - Posted 2013-05-16 19:33:17 »

I think its kind of obvious what you need to do here... when you want to render text, you use the init code you found on the wiki and when you want to render the game, you use the first init method.

Is this possible ?? the openGL init is done before the game loop once it's called it will never be updated so how can i do such thing ?
thank you

You do know how OpenGL works don't you? OpenGL is a state based machine so when you do something like enable blending for example, it will have blending turned on until you then disable it. So now tell me, how would you solve your problem?

Offline alaslipknot
« Reply #8 - Posted 2013-05-17 23:24:37 »

I think its kind of obvious what you need to do here... when you want to render text, you use the init code you found on the wiki and when you want to render the game, you use the first init method.

Is this possible ?? the openGL init is done before the game loop once it's called it will never be updated so how can i do such thing ?
thank you

You do know how OpenGL works don't you? OpenGL is a state based machine so when you do something like enable blending for example, it will have blending turned on until you then disable it. So now tell me, how would you solve your problem?

am really stacked  Undecided  i tried to use the init from the example before rendering the text, then using my init before rendering the graphics and the result was a black screen
am now trying to create a method to manually draw text (using GL_POINTS to draw each letter individually)
any help please

"It's not at all important to get it right the first time. It's vitally important to get it right the last time."
Offline Longarmx
« Reply #9 - Posted 2013-05-18 03:30:03 »

The only thing you needed to do I think is enable blending on your original initialization. The text was rendering, it just had a non-transparent background.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline alaslipknot
« Reply #10 - Posted 2013-05-21 09:06:38 »

The only thing you needed to do I think is enable blending on your original initialization. The text was rendering, it just had a non-transparent background.
i tried it also doesn't work  Huh

"It's not at all important to get it right the first time. It's vitally important to get it right the last time."
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.

rwatson462 (28 views)
2014-12-15 09:26:44

Mr.CodeIt (19 views)
2014-12-14 19:50:38

BurntPizza (37 views)
2014-12-09 22:41:13

BurntPizza (73 views)
2014-12-08 04:46:31

JscottyBieshaar (34 views)
2014-12-05 12:39:02

SHC (47 views)
2014-12-03 16:27:13

CopyableCougar4 (42 views)
2014-11-29 21:32:03

toopeicgaming1999 (110 views)
2014-11-26 15:22:04

toopeicgaming1999 (96 views)
2014-11-26 15:20:36

toopeicgaming1999 (29 views)
2014-11-26 15:20:08
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!