Where is the code that translates pixel coordinates to OpenGL coordinates?

Hello,

I’m trying to make a new OpenFrameworks Window for a UWP application. I have everything setup and working in VisualStudio. When I run the app, however, the coordinates are based on (-1,1) instead of (0,windowWidth/Height). I’ve been scratching my brain trying to figure out where the code is that does this translation but I’m unable to find it.

Any help would be greatly appreciated.

Thanks,
Kyle

Hi!

OF is typically setup in window coordinates. However if you are using an ofCamera or ofEasyCamera the coordinates will be in 3D style with 0,0 being at the center of the screen.

Is that what you are experiencing?

All the best!
Theo

Yes. If I draw a filled rect at (0,0) it will have its top-left corner at the center of the window.

– edit –

To provide a little more information, I’m using ofGLProgrammableRenderer and to my knowledge there isn’t a camera that is setup.

setupPerspective is the function that sets the transformation matrices in the renderers. if you are using the programable renderer then in your shaders you need to use the uploaded matrices in order to actually transform the coordinates correctly

Thanks! The issue was that I had was using some pre-made openGL code for testing in my draw() method and I didn’t realize it would interfere with the OpenFrameworks code. In hindsight it seems pretty obvious that it would:

GLfloat vertices[] =
	{
		0.0f,  0.5f, 0.0f,
		-0.5f, -0.5f, 0.0f,
		0.5f, -0.5f, 0.0f,
	};

	// Set the viewport
	//glViewport(0, 0, 1024, 900);

	// Clear the color buffer
	glClear(GL_COLOR_BUFFER_BIT);

	// Use the program object
	glUseProgram(mProgram);

	// Load the vertex data
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vertices);
	glEnableVertexAttribArray(0);
	
	glDrawArrays(GL_TRIANGLES, 0, 3);

Anyways, it works as expected now. Thanks!

Glad to hear!
Out of curiosity are you using ANGLE to get OF working with UWP?

Yeah. I’ve been updating the code from msopentech to work with the latest OpenFrameworks. I’m coming from an Android/iOS/OSX background and getting OpenFrameworks to work with UWP has been a very … frustrating process to say the least. Originally I had compiled using MinGW which was easy, but since my end goal was to incorporate OpenFrameworks into an existing Cordova project the code had to be compatible with UWP.

The cordova project is an HTML5 application with a native camera with live filters. I chose OpenFrameworks since its relatively easy to port the native code to other platforms.

Wow - yeah I can imagine.
Please keep us posted on the progress.

We’d love to find a way to officially include UWP support with OF.
I think when the OpenTech team originally did the port, we were kind of kept in the dark until the work was done, so it was at that point very hard to integrate.

It would be great to find a way to have this exist alongside OF and not break with each release.

@DANtheMAN was looking into this also and I know there would be others interested in your efforts.

Thanks!
Theo

Sure. I don’t think it would be too difficult to include it in the platforms supported by OpenFrameworks. I have a fork over at github with the changes I’ve made, which really isn’t much. The next steps to make it ready for inclusion in the master branch would be to make the video grabber, player, and window be part of an addon, and then create a project generator for it.

@kkirbatski - great! would be great to coordinate on a PR to bring it in, when you think its at a good place.

Good luck with the effort!

1 Like