package hu.qgears.opengl.commons.example;

import hu.qgears.opengl.commons.Camera;
import hu.qgears.opengl.commons.TargetRectangle;
import hu.qgears.opengl.commons.UtilGl;
import hu.qgears.opengl.commons.context.RGlContext;
import hu.qgears.opengl.glut.Glut;
import hu.qgears.opengl.glut.GlutInstance;
import lwjgl.standalone.BaseAccessor;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GLContext;
import org.lwjgl.util.vector.Vector2f;
import org.lwjgl.util.vector.Vector3f;
import org.lwjgl.util.vector.Vector4f;

public class GlutExample02 {
	static Camera camera=new Camera();
	private static int width=1024;
	private static int height=768;
	public static void main(String[] args) throws LWJGLException {
		GlutInstance.getInstance();
		BaseAccessor.initLwjglNatives();
		Glut glut=new Glut();
		glut.init();
		glut.openWindow(false, width, height, "example 2");
		GLContext.useContext(glut);
		doBunchOfLoop(glut);
		glut.setFullScreen(true, width, height);
		int w=glut.getScreenWidth();
		int h=glut.getScreenHeight();
		doBunchOfLoop(glut);
		glut.setFullScreen(false, width, height);
		doBunchOfLoop(glut);
		System.out.println("Fullscreen width and height: ["+w+", "+h+"]");
	}

	private static void doBunchOfLoop(Glut glut) {
		int ctr=0;
		while(ctr<200)
		{
			glut.mainLoopEvent();
			drawScene();
			glut.swapBuffers();
			ctr++;
		}
	}

	private static void drawScene() {
		// A kép rajzolásának elkezdését jelezzük ezzel a paranccsal
		GL11.glRenderMode(GL11.GL_RENDER);
		// Beállítjuk a kamera pozícióját.
		// Innentől mindent úgy rajzol az OpenGL, hogy a megadott
		// Pozícióba képzeli a kamerát
		UtilGl.init3D(width, height, 30.0f, 1.0f);
		camera.setCamera();
		// háttér törlése
		GL11.glClearColor(0,0,1,1);
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
		// fehér háromszög rajzolása
		renderVideo();
	}
	private static void renderVideo() {
		RGlContext glContext=new RGlContext();
		// háttér törlése
		GL11.glClearColor(0,1,0,.3f);
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
		
		int sizeX=1024;
		int sizeY=768;
		float scale=.2f;
		UtilGl.setColor(new Vector3f(1,0,0));
		UtilGl.translate(GL11.GL_MODELVIEW, new Vector3f(0,0,-10));
		TargetRectangle rect=new TargetRectangle(
				(Vector2f)new Vector2f(-sizeX/2,sizeY/2).scale(scale),
				(Vector2f)new Vector2f(sizeX-sizeX/2, -sizeY+sizeY/2).scale(scale)
		);
		UtilGl.drawRectangle(glContext, rect, new Vector4f(1,0,0,.5f));
		rect=new TargetRectangle(
				(Vector2f)new Vector2f(-sizeX/2+sizeX/2,sizeY/2).scale(scale),
				(Vector2f)new Vector2f(sizeX-sizeX/2, -sizeY+sizeY/2).scale(scale)
		);
		UtilGl.drawRectangle(glContext, rect, new Vector4f(1,0,0,1f));
	}
}

@@ -580,16 +580,24 @@
 le02 %7B%0A%09
+private 
 static C
@@ -643,17 +643,23 @@
 tic 
+f
 in
-t width
+al int WIDTH
 =102
@@ -681,18 +681,24 @@
 tic 
+f
 in
-t height
+al int HEIGHT
 =768
@@ -892,29 +892,29 @@
 (false, 
-width, height
+WIDTH, HEIGHT
 , %22examp
@@ -1005,84 +1005,21 @@
 ue, 
-width, height);%0A%09%09int w=glut.getScreenWidth();%0A%09%09int h=glut.getScreenHeight(
+WIDTH, HEIGHT
 );%0A%09
@@ -1068,29 +1068,29 @@
 (false, 
-width, height
+WIDTH, HEIGHT
 );%0A%09%09doB
@@ -1111,77 +1111,8 @@
 t);%0A
-%09%09System.out.println(%22Fullscreen width and height: %5B%22+w+%22, %22+h+%22%5D%22);%0A
 %09%7D%0A%0A
@@ -1560,21 +1560,21 @@
 t3D(
-width, height
+WIDTH, HEIGHT
 , 30
@@ -1927,18 +1927,20 @@
 );%0A%09%09%0A%09%09
-in
+floa
 t sizeX=
@@ -1947,18 +1947,20 @@
 1024;%0A%09%09
-in
+floa
 t sizeY=

Fix major and critical Sonar issues in GlutExample02.java