{lwjgl} help on understanding openGl initialization

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 :stuck_out_tongue: )
anyway,
i tried to render a text in a simple pong game, and the result was this (the white rectangle is the text) :

http://s20.postimg.org/ti3pflj5p/image.png

that result happens when i use this openGl initialization :


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 )


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 :

http://s20.postimg.org/4q438d1z1/image.png

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

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

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.

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

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

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.

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 :-\ 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

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