Question about center in desktop ( only cpp )


#1

Hello everyone,

I am really happy because I have goal with --width --height like any games with passing parameters

package;

import lime.graphics.opengl.*;
import openfl.display.*;
import openfl.geom.Rectangle;
import openfl.events.*;
import openfl.Lib;

class Main extends Sprite {
	
	private var view:OpenGLView;
	private var Rect:Rectangle;
	private var IsWindowed = false;

	public function new () {
		
		super ();
		
		if (OpenGLView.isSupported)
		{
			view = new OpenGLView ();
			Lib.application.window.title = "OpenGL Version: " + GL.getString(GL.VERSION);
			Lib.application.window.fullscreen = true;

			var args = Sys.args();
			for (i in 0...args.length)
			{
				switch(args[i])
				{
					// width of game
					case "--width", "-w":
						Lib.application.window.width = Std.parseInt(args[i+1]);

					// height of game
					case "--height", "-h":
						Lib.application.window.height = Std.parseInt(args[i+1]);

					// switch windowed or fullscreen
					case "-windowed":
						IsWindowed = true;
					
				}
			}

			view.render = renderView;
			addChild (view);
		}
		
	}

	private function renderView (rect:Rectangle):Void
	{
		Rect = rect;
		GL.viewport (Std.int (rect.x), Std.int (rect.y), Std.int (rect.width), Std.int (rect.height));
		if(IsWindowed)
			Lib.application.window.fullscreen = false;
		else
			Lib.application.window.fullscreen = true;

		Lib.current.stage.align = StageAlign.TOP_LEFT;
		Lib.current.stage.scaleMode = StageScaleMode.NO_SCALE;
		Lib.current.stage.addEventListener (Event.RESIZE, onResizeHandler);

		GL.clearColor(0.39, 0.58, 0.93, 1.0);
		GL.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT);
	}

	private function onResizeHandler(ev:Event):Void
	{
		Lib.application.window.resize(Std.int(Rect.width), Std.int(Rect.height));
	}

	static function Main()
	{
		new Main();
	}
}

But I have problem with common black background if I use passing width and height example haxegame --width 1200 --height 660 than it happens like this:

Why does Viewport can’t resize sketch mode via passing command line arguments?

And I see haxegame can’t open in center of desktop screen.

Where are method for native screen width and native screen height?
// EDIT It looks Capabilities of Flash but it is not in Flash Player - just “native” like Lime?

// Updated my code. you can check fullscreen and windowed like any games have same arguments :slight_smile:

Thank you for answer if you have idea.


#2

Try adding <window resizable="true" /> to your project.xml, does it help?

Also, try doing a clear without the viewport, in case the rectangle is wrong?


#3

Thanks @singmajesty <window resizable="true" /> is enabled maximize button. But I don’t want game’s window with maximize button. You know any game have not to use maximize button like example:
I use passing parameter haxegame.exe -windowed -w 1220 -h 660 than it sees commonly.


I fixed because Lib.application.window.fullscreen = true in public function new() { ... } It is wrong and I have removed line. and I want show how do I without maximize button?


#4

I believe the black-boxing is coming from here:

The easiest way to handle this without modifying sources would be to set <window resizable="true" /> in your project.xml, then to disable it at runtime using window.resizable = false;

I’d like to improve our stage scale modes in the future, but happy to discuss suggestions if you think our default behavior should be different


#5

Wow thanks my best magician @singmajesty that is nice trick!

I don’t know before window.resizable = false Thank for help! I hope you have to improve StageScaleMode with window. Nice idea. I will help If I have goal with OpenGL 4.0 from DreamCode ( C# ) into OpenFL ( haxe )

And how does window stay in center of desktop’s screen?

I explain you if my monitor is very big ( Zoll 27 )
Ops it is big picture sorry :open_mouth:

How do I fix window in center if I use passing parameters with --width and --height? I really don’t know where are methods for native desktop’s screen.

// EDIT:
Is it correct or wrong with lime.system.Display and lime.system.DisplayMode?


#6

You should be able to set window.x or window.y, the key would be knowing both your window size and the current desktop’s size. I believe you should be able to get the monitor that contains the center point of your window using window.display, so something like:

var currentMode = window.display.currentMode;
var centerX = (currentMode.width - (window.width * window.scale)) / 2;
var centerY = (currentMode.height - (window.height * window.scale)) / 2;
window.x = centerX;
window.y = centerY;

This might be a start


#7

Why do you need window.scale? If you use passing parameters example haxegame -w 1200 -h 600 -windowed than it will open with changed width and changed height of window and stays center. But I never use window.scale if I am using OpenTK for C#. Just implements simple like

window.x = (currentMode.width/2) - (window.width/2);
window.y = (currentMode.height/2) -(window.height/2);

Thanks for explanation! Now I focus and add more details.

// EDIT It fixed:

Yay :slight_smile:

	private function renderView (rect:Rectangle):Void
	{
		GL.viewport (Std.int (rect.x), Std.int (rect.y), Std.int (rect.width), Std.int (rect.height));
		if(IsWindowed)
		{
			Lib.application.window.fullscreen = false;
			var window = Lib.application.window;
			var currentMode = window.display.currentMode;
			window.x = Std.int((currentMode.width - window.width) / 2);
			window.y = Std.int((currentMode.height - window.height) / 2);
		}
		else
			Lib.application.window.fullscreen = true;

		Lib.current.stage.align = StageAlign.TOP_LEFT;
		Lib.current.stage.scaleMode = StageScaleMode.SHOW_ALL;

		GL.clearColor(0.39, 0.58, 0.93, 1.0);
		GL.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT);
	}

Now it works fine.

// Update:
I have problem with Keyboard - If I use simple like C# OpenTK:

protected override void OnUpdateFrame(FrameEventArgs e)
{
  var keyState = Keyboard.GetState();

 if (keyState.IsKeyDown(Key.Escape))
 {
  Exit();
 }
}

What is for haxe?
I found example tutorial of haxecode:
Yay I have fixed because haxecode = old coder :open_mouth: I try to invent that

	private var keys:Array<Bool>;
...
		keys = new Array<Bool>();
		stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
...
	private function onKeyDown(evt:KeyboardEvent):Void
	{
		if (keys[Keyboard.ESCAPE]) {
			window.close();
		}
	}

Than it works fine like same C# OpenTK.

But how do I use update() than I don’t need use KeyboardEvent. Is it possible?
// EDIT:
No success without KeyboardEvent because Keyboard need be accessible with KeyboardEvent. So sad… You know sometimes they don’t need to write stage.addEventListener(); But how does it work like BabylonHX has method Update ( I don’t remember that )

Where is GL.PointSize(10); for Haxe?
I can’t find API of Lime and OpenFL
PS: It looks common with GL.VERTEX_PROGRAM_POINT_SIZE?

I really don’t understand where is GL.PointSize(size:Int) for Haxe. But I can’t find any method for OpenGL. What do I miss this?

I can not resolve :frowning: Because Lime’s GL is not completed :frowning: Please add more features of same OpenGL methods - Why do we not have any more important methods?

GL.PointSize(); - Issue *****


#8

Any suggestions? What is alternative to GL.pointSize(size:Float); ?

I don’t know I see API has not method “pointSize(size:Float)”.
I think you have to forget add important method for Lime. Are you sure that it is really important method?

// EDIT No success…
I have tried any methods

Why I don’t get PointSize(size:Float)
What is bad alternative??? With GL.vertexAttribPointer()???

My head explodes like Vulcan because you force again ex-method “POINTSIZE(SIZE:FLOAT);” because It is really important method for latest version of OpenGL 4.x

package;

import lime.graphics.opengl.*;
import lime.system.*;
import lime.utils.*;
import openfl.display.*;
import openfl.geom.Rectangle;
import openfl.events.*;
import openfl.ui.*;
import openfl.Lib;

class Main extends Sprite {
	
	private var view:OpenGLView;
	private var IsWindowed = false;
	private var window = Lib.application.window;
	private var keys:Array<Bool>;
	private var program:GLProgram;

	private var vertices = [0.25, -0.25,  0.5];
	private var vertex_buffer:GLBuffer;

	public function new () {
		
		super ();
		
		keys = new Array<Bool>();
		stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
		
		if (OpenGLView.isSupported)
		{
			view = new OpenGLView ();
			window.title = "OpenGL Version: " + GL.getString(GL.VERSION);
			window.resizable = false;

			program = CompileShader();

			var args = Sys.args();
			for (i in 0...args.length)
			{
				switch(args[i])
				{
					// width of game
					case "--width", "-w":
						window.width = Std.parseInt(args[i+1]);

					// height of game
					case "--height", "-h":
						window.height = Std.parseInt(args[i+1]);

					// switch windowed or fullscreen
					case "-windowed":
						IsWindowed = true;
					
				}
			}

			view.render = renderView;
			addChild (view);
		}
		
	}

	private function renderView (rect:Rectangle):Void
	{
		if(IsWindowed)
		{
			window.fullscreen = false;
			var currentMode = window.display.currentMode;
			window.x = Std.int((currentMode.width - window.width) / 2);
			window.y = Std.int((currentMode.height - window.height) / 2);
		}
		else
			window.fullscreen = true;

		vertex_buffer = GL.createBuffer();
		GL.bindBuffer(GL.ARRAY_BUFFER, vertex_buffer);
		GL.bufferData(GL.ARRAY_BUFFER, vertices.length, GL.STATIC_DRAW, 0);
		GL.bindBuffer(GL.ARRAY_BUFFER, null);

		GL.useProgram(program);
		GL.bindBuffer(GL.ARRAY_BUFFER, vertex_buffer);
		var coord = GL.getAttribLocation(program, "coordinates");
		GL.vertexAttribPointer(coord, 3, GL.FLOAT, false, 0, 0);
		GL.enableVertexAttribArray(coord);
		GL.enable(GL.DEPTH_TEST);
		GL.clearColor(0.39, 0.58, 0.93, 1.0);
		GL.clear(GL.COLOR_BUFFER_BIT);
		GL.viewport (Std.int (rect.x), Std.int (rect.y), Std.int (rect.width), Std.int (rect.height));
		GL.drawArrays(GL.POINTS, 0, 1);
	}

	private var vertexSource:String = 
"attribute vec3 coordinates;
void main(void)
{
	gl_position = vec4(coordinates, 1.0);
	gl_PointSize = 10.0;
}";

	private var fragmentSource:String =
"void main(void)
{
	gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}";

	private function CompileShader():GLProgram
	{
		var vertexShader:GLShader = GL.createShader(GL.VERTEX_SHADER);
		GL.shaderSource(vertexShader, vertexSource);
		GL.compileShader(vertexShader);

		var fragmentShader:GLShader = GL.createShader(GL.FRAGMENT_SHADER);
		GL.shaderSource(fragmentShader, fragmentSource);
		GL.compileShader(fragmentShader);

		var glProgram:GLProgram = GL.createProgram();
		GL.attachShader(glProgram, vertexShader);
		GL.attachShader(glProgram, fragmentShader);
		GL.linkProgram(glProgram);

		GL.detachShader(glProgram, vertexShader);
		GL.detachShader(glProgram, fragmentShader);
		GL.deleteShader(vertexShader);
		GL.deleteShader(fragmentShader);
		return glProgram;
	}

	private function onKeyDown(evt:KeyboardEvent):Void
	{
		keys[evt.keyCode] = true;
		if (keys[Keyboard.ESCAPE])
		{
			GL.deleteProgram(program);
			window.close();
		}
	}

	static function Main()
	{
		new Main();
	}
}

I understand now.

Because you didn’t tell truth:

3 different versions of OpenGL Format:

1: glBegin and glEnd
2. glShader and glProgram
3 glBuffer and glBufferData

I am not successful to compile. STOP FOCRING ME - I really don’t know OpenGL Format 3. I am using OpenGL-Format 2.

I am mad now because you didn’t tell what different OpenGL with glBegin and glEnd, OpenGL with shader and program or OpenGL with glBuffer as WebGL.

But I can not see red point :frowning:

How do I fix?
// EDIT

Doesn’t work for me :frowning: I have tried SimpleOpenGLView but for me GL.POINTS

I have tried no sucess :frowning: It is really shit because you use f***ing WebGL-Like OpenGL. It is sometimes wrong !!!

PLEASE USE NORMAL OPENGL for DESKTOP VERSION.
NO WEBGL!!! I cancelled now because you are bad to me. I have always tried tried stop to take advantage my times. I hate you now. Bye now


#9

Hi!

OpenFL (and Lime) have historically focused primarily on cross-platform code. Between WebGL, GLES and desktop GL, there is a subset that works consistently for all targets. We started by making support for GLES3 features (like VAOs) but we have the architecture in place to be able to delineate between desktop and mobile GL, and what version.

This is just an unimplemented feature, that has not been done or requested. Adding GL1-style methods is possible, though some of it looks deprecated? https://stackoverflow.com/questions/14300569/opengl-glbegin-glend#14300622