Sign in to follow this  
Phil15

OpenGL Opengl ES on Windows 8 using EGL

Recommended Posts

Phil15    184

Hi,

I am trying to make a cross platform graphics engine where I could write a library test it on my desktop with windows 8 and use the same library with Android/Iphone.(Including OpenGL ES libs ofcourse). As far as I am aware Android uses EGL to render images within a window (Correct me if I am wrong ). A lot of sources keep saying that EGL can be done on windows other say you need WGL, some others say Windows 8 can not support OpenGL ES at all. I also have an Nvidia card and only OpenGL ES libraries that I found are from AMD. Does anyone know what is the best way to get through this problem??

Share this post


Link to post
Share on other sites
WiredCat    1450

well its not that hard as you think. First of all decide which es version you target, then you need to get somekind of wrapper that creates opengl window on every platform you can do that writing different codes for different platforms or use some kind of libs that provide this.

 

Then you just use only OpenGL functions that are avail in your ES version, nothing more nothing less

 

 

OpenGL will work the same way on all platforms if you will be using same functions.

 

 

So for windows you dont link es version you can link normal opengl lib provided with windows...

Edited by WiredCat

Share this post


Link to post
Share on other sites
alh420    5995


Then you just use only OpenGL functions that are avail in your ES version, nothing more nothing less
OpenGL will work the same way on all platforms if you will be using same functions.

 

well almost... except for vendor specific bugs and slight differences between versions...

There are not many, but there are a few #ifdefs in our engine if you run it on  "normal" GL instead of GLES. Mostly because of different enum names. Then some function which for some reason has an f for float on the end on GLES but not on GL.

There are also #ifdefs if you run on GLES for android, or GLES for iOS... (again different enum names)

 

Also the shader code had to be slightly modified before the opengl driver liked it.

Share this post


Link to post
Share on other sites
WiredCat    1450

wlll i know that glClearColorf is for es and glClearColor for normal one (not sure if theres glClearColorf for ogl too) but you can typename so it will point onto another,

actually es shader code looks liek be more strict so ogl will eat it.

Share this post


Link to post
Share on other sites
Phil15    184

Thank you everyone for your time and replies.
 

Found this link a couple of days ago when a similar question was asked: http://www.g-truc.net/post-0457.html

This very link I also found whilst researching, it said I cannot run EGL or WGL on Windows 8 ....
 

 

well its not that hard as you think. First of all decide which es version you target, then you need to get somekind of wrapper that creates opengl window on every platform you can do that writing different codes for different platforms or use some kind of libs that provide this.

 

Then you just use only OpenGL functions that are avail in your ES version, nothing more nothing less

 

 

OpenGL will work the same way on all platforms if you will be using same functions.

 

 

So for windows you dont link es version you can link normal opengl lib provided with windows...

I am planning on using OpenGL ES 2.0 ...How would I know which functions are supported in ES 2.0 and which are not if I am using openGL ... I mainly used Glut and glew before to run a small graphics engine on a pc but I can no longer use this in Android as android uses EGL, also the plan is making it compatible with ios in future. what is the most efficient approach you can suggest from your experience? What kind of libraries should I use ?

Share this post


Link to post
Share on other sites
WiredCat    1450

list of functions supported by opengl es 2.0

https://www.khronos.org/opengles/sdk/docs/man/

 

 

additionally

 

opengl es 2.0 GL SL shading lang list:

https://www.khronos.org/opengles/sdk/docs/reference_cards/OpenGL-ES-2_0-Reference-card.pdf

 

 

 

please note that even when ES 3.0 device is bacward compatible its not always true, and you will have to rewrite shader s ES 3.0 could read that. (goo way to avoid such thing is not to name variables as "texture" becasue its reserved word for es 3.0 glsl

and actually use mediump highp lowp defines : )

Edited by WiredCat

Share this post


Link to post
Share on other sites
Erik Rufelt    5901


it said I cannot run EGL or WGL on Windows 8 ....

 

Think it says Windows RT, which only goes if you buy one of those Surface tablets with an ARM processor or a Windows Phone. If you have a desktop then it most definitely runs OpenGL as well as anything, a long as you have the Nvidia graphics card driver installed

Share this post


Link to post
Share on other sites
C0lumbo    4411

You might want to consider using this: http://community.imgtec.com/developers/powervr/tools/pvrvframe/

 

It's a library from PowerVR, who design the GPUs used by iOS devices and many of those in Android devices. It lets you use GLES on desktop, and apparently interfaces pretty well with some of their performance analysis tools so you can even do some optimisation work on desktop (although you should always measure on a target device).

 

I should say that I haven't used it yet, but I'm planning to try it out. I'm not sure how good of an idea it'd be to use it if you're planning to release on Windows though, at the very least you'd need to carefully read the license agreement, I'm hoping to use it purely to speed up development of mobile-only projects.

Share this post


Link to post
Share on other sites
Phil15    184

 


it said I cannot run EGL or WGL on Windows 8 ....

 

Think it says Windows RT, which only goes if you buy one of those Surface tablets with an ARM processor or a Windows Phone. If you have a desktop then it most definitely runs OpenGL as well as anything, a long as you have the Nvidia graphics card driver installed

 


I apologize I did not read that carefully, yes you are correct.


I was trying to go to the basics and at least use opengl in a window (WIN32_API). I managed to create a blank window and supposedly an Opengl context. But I cannot understand how do you use the context, I could not even change the color...
 

#include <Windows.h>
#include <gl\GL.h>
#include <iostream>

#pragma comment(lib , "opengl32.lib")

bool InitMainWindow(HINSTANCE, int);

LRESULT CALLBACK MsgProc(HWND, UINT, WPARAM, LPARAM);

const int WIDTH = 800;
const int HEIGHT= 600;

HWND hwnd = NULL;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	if (!InitMainWindow(hInstance, nCmdShow))
	return 1;

	MSG msg = { 0 };
	HDC hdc = GetDC(hwnd);

	while (WM_QUIT != msg.message)
	{
		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}
	return 0;

}


bool InitMainWindow(HINSTANCE hInstance, int nCmdShow)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(wcex);
	wcex.style = CS_HREDRAW | CS_VREDRAW;
	wcex.cbClsExtra = 0;
	wcex.cbWndExtra = 0;


	wcex.lpfnWndProc = MsgProc;
	wcex.hInstance = hInstance;
	wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);

	wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
	wcex.lpszClassName = "WIndow";
	wcex.lpszMenuName = NULL;
	wcex.hIconSm = LoadIcon(NULL, IDI_WINLOGO);

	if (!RegisterClassEx(&wcex))
	{
		return false;
	}

	hwnd = CreateWindow("WIndow", "Win32", WS_OVERLAPPEDWINDOW | WS_SYSMENU | WS_CAPTION
		, GetSystemMetrics(SM_CXSCREEN) / 2 - WIDTH / 2,
		GetSystemMetrics(SM_CYSCREEN) / 2 - HEIGHT / 2,
		WIDTH,
		HEIGHT,
		(HWND)NULL,
		(HMENU)NULL,
		hInstance,
		(LPVOID*)NULL
		);

	if (!hwnd)
		return false;


	ShowWindow(hwnd, nCmdShow);
	return true;

}

LRESULT CALLBACK MsgProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
	switch (msg)
	{
	case WM_CREATE:
	{
 		PIXELFORMATDESCRIPTOR pfd =
		{
			sizeof(PIXELFORMATDESCRIPTOR),
			1,
			PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,    //Flags
			PFD_TYPE_RGBA,            //The kind of framebuffer. RGBA or palette.
			32,                        //Colordepth of the framebuffer.
			0, 0, 0, 0, 0, 0,
			0,
			0,
			0,
			0, 0, 0, 0,
			24,                        //Number of bits for the depthbuffer
			8,                        //Number of bits for the stencilbuffer
			0,                        //Number of Aux buffers in the framebuffer.
			PFD_MAIN_PLANE,
			0,
			0, 0, 0
		};

		HDC ourWindowHandleToDeviceContext = GetDC(hwnd);

		int  letWindowsChooseThisPixelFormat;
		letWindowsChooseThisPixelFormat = ChoosePixelFormat(ourWindowHandleToDeviceContext, &pfd);
		SetPixelFormat(ourWindowHandleToDeviceContext, letWindowsChooseThisPixelFormat, &pfd);

		HGLRC ourOpenGLRenderingContext = wglCreateContext(ourWindowHandleToDeviceContext);
		bool value = wglMakeCurrent(ourWindowHandleToDeviceContext, ourOpenGLRenderingContext);

		
		while (1)
		{
			glClearColor(0.0f, 1.0f, 0.0f, 0.0f);
		}
		//MessageBoxA(0, (char*)glGetString(GL_VERSION), "OPENGL VERSION", 0);

		wglDeleteContext(ourOpenGLRenderingContext);
		PostQuitMessage(0);
	}
	break;

	case WM_DESTROY: //recieved destroy msg
		PostQuitMessage(0);
		return 0;
	}

	return DefWindowProc(hwnd, msg, wparam, lparam);


}




 

Share this post


Link to post
Share on other sites
Erik Rufelt    5901

You need a SwapBuffers(HDC) to present the image to screen.

Then just put wglDeleteContext on exit and do SwapBuffers over and over.

 

Also, glClearColor only specifies the color to use to clear, you need to call glClear to actually clear after it.

 

Like:

if(PeekMessage(...)) {
  Translate(...
  ...
}
else {
  glClear(...);

  // draw stuff

  SwapBuffers(HDC);
}
Edited by Erik Rufelt

Share this post


Link to post
Share on other sites
Phil15    184

Ok here is the simplest OpenGLES with EGL context creation (with memory leaks and probably bugs ) for people who might be struggling (like me) in getting started

 

#include <Windows.h>
#include <iostream>

#include <GLES2\gl2.h>
#include <GLES2\gl2ext.h>
#include <GLES2\gl2platform.h>

#include <EGL\egl.h>
#include <EGL\eglext.h>
#include <EGL\eglplatform.h>

#include <string>

bool InitMainWindow(HINSTANCE, int);

LRESULT CALLBACK MsgProc(HWND, UINT, WPARAM, LPARAM);

const int WIDTH = 800;
const int HEIGHT = 600;

 HWND hwnd = NULL;
float theta = 0.0f;

HGLRC ourOpenGLRenderingContext;

void InitEGL(const HWND &WindowHandle);
EGLConfig *  chooseConfig(EGLDisplay display);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	InitMainWindow(hInstance, nCmdShow); // initialize me a window

	MSG msg = { 0 };
	HDC hdc = GetDC(hwnd);

	while (WM_QUIT != msg.message)
	{
		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{

			glClearColor(0.0f, 1.0f, 0.0f, 0.0f);
			glClear(GL_COLOR_BUFFER_BIT);
			//Continue your OpenGLES here
			
			
			SwapBuffers(hdc);

		}
	}

	//eglTerminate here to Implement and release resources here
	return 0;

}


bool InitMainWindow(HINSTANCE hInstance, int nCmdShow)
{
	WNDCLASSEX wcex; // window class wcex 

	wcex.cbSize = sizeof(wcex);
	wcex.style = CS_HREDRAW | CS_VREDRAW;
	wcex.cbClsExtra = 0;
	wcex.cbWndExtra = 0;

	wcex.lpfnWndProc = MsgProc; //A pointer to the window procedure. You must use the CallWindowProc function to call the window procedure.
	wcex.hInstance = hInstance;
	wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);

	wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
	wcex.lpszClassName = "WIndow";
	wcex.lpszMenuName = NULL;
	wcex.hIconSm = LoadIcon(NULL, IDI_WINLOGO);

	if (!RegisterClassEx(&wcex))
	{
		return false;
	}

	hwnd = CreateWindow("WIndow", "Win32", WS_OVERLAPPEDWINDOW | WS_SYSMENU | WS_CAPTION
		, GetSystemMetrics(SM_CXSCREEN) / 2 - WIDTH / 2,
		GetSystemMetrics(SM_CYSCREEN) / 2 - HEIGHT / 2,
		WIDTH,
		HEIGHT,
		(HWND)NULL,
		(HMENU)NULL,
		hInstance,
		(LPVOID*)NULL
		);

	if (!hwnd)
		return false;

	ShowWindow(hwnd, nCmdShow);
	return true;

}

LRESULT CALLBACK MsgProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
	switch (msg)
	{
	case WM_CREATE:
	{
		PIXELFORMATDESCRIPTOR pfd =
		{
			sizeof(PIXELFORMATDESCRIPTOR),
			1,
			PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,    //Flags
			PFD_TYPE_RGBA,            //The kind of framebuffer. RGBA or palette.
			32,                        //Colordepth of the framebuffer.
			0, 0, 0, 0, 0, 0,
			0,
			0,
			0,
			0, 0, 0, 0,
			24,                        //Number of bits for the depthbuffer
			8,                        //Number of bits for the stencilbuffer
			0,                        //Number of Aux buffers in the framebuffer.
			PFD_MAIN_PLANE,
			0,
			0, 0, 0
		};

		InitEGL(hwnd);
		
		break;
	}
	case WM_DESTROY: //recieved destroy msg
		PostQuitMessage(0);
		return 0;
	}

	return DefWindowProc(hwnd, msg, wparam, lparam);
}



void InitEGL(const HWND & Windowhandle)
{

	static EGLint const attribute_list[] = {
		EGL_RED_SIZE, 1,
		EGL_GREEN_SIZE, 1,
		EGL_BLUE_SIZE, 1,
		EGL_NONE };

	EGLDisplay display;
	EGLConfig config;
	EGLContext context;
	EGLSurface surface;
	NativeWindowType native_window;
	EGLint num_config;
	/* get an EGL display connection */
	display = eglGetDisplay(EGL_DEFAULT_DISPLAY);

	EGLBoolean eglbool = eglInitialize(display, NULL, NULL);
	eglbool = eglbool;


	EGLConfig * matches = chooseConfig(display);


	int attrib_list[] = {
		EGL_CONTEXT_CLIENT_VERSION, 2,EGL_NONE
		
	};

	///* create an EGL rendering context */
	context = eglCreateContext(display, matches[0], NULL, attrib_list);
	///* create a native window */

	surface = eglCreateWindowSurface(display, matches[0], Windowhandle, NULL);
	//EGLint errNum = eglGetError();
	//std::cout << Error(errNum) << std::endl;
	
	eglMakeCurrent(display, surface, surface, context);
	
}

EGLConfig *  chooseConfig(EGLDisplay display)
{

	EGLint attributes[] = {	EGL_RED_SIZE, 5,
							EGL_GREEN_SIZE, 6,
							EGL_BLUE_SIZE, 5,
							EGL_SAMPLES, 4,
							EGL_NONE };

	EGLint numberConfigs;
	EGLConfig* matchingConfigs;

	if (EGL_FALSE == eglChooseConfig(display, attributes, NULL, 0, &numberConfigs))
	{
		/* An error */
	}
	if (numberConfigs == 0) {
		/* An error */
	}

	matchingConfigs = (EGLConfig*)malloc(numberConfigs * sizeof(EGLConfig));
	/* ...and this time actually get the list (notice the 3rd argument is
	* now the buffer to write matching EGLConfig's to)
	*/
	if (EGL_FALSE == eglChooseConfig(display, attributes, matchingConfigs, numberConfigs, &numberConfigs))
	{
		/* An error */
	}


	return matchingConfigs;

}

Thanks everyone for your help! :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By pseudomarvin
      I assumed that if a shader is computationally expensive then the execution is just slower. But running the following GLSL FS instead just crashes
      void main() { float x = 0; float y = 0; int sum = 0; for (float x = 0; x < 10; x += 0.00005) { for (float y = 0; y < 10; y += 0.00005) { sum++; } } fragColor = vec4(1, 1, 1 , 1.0); } with unhandled exception in nvoglv32.dll. Are there any hard limits on the number of steps/time that a shader can take before it is shut down? I was thinking about implementing some time intensive computation in shaders where it would take on the order of seconds to compute a frame, is that possible? Thanks.
    • By Arulbabu Donbosco
      There are studios selling applications which is just copying any 3Dgraphic content and regenerating into another new window. especially for CAVE Virtual reality experience. so that the user opens REvite or CAD or any other 3D applications and opens a model. then when the user selects the rendered window the VR application copies the 3D model information from the OpenGL window. 
      I got the clue that the VR application replaces the windows opengl32.dll file. how this is possible ... how can we copy the 3d content from the current OpenGL window.
      anyone, please help me .. how to go further... to create an application like VR CAVE. 
       
      Thanks
    • By cebugdev
      hi all,

      i am trying to build an OpenGL 2D GUI system, (yeah yeah, i know i should not be re inventing the wheel, but this is for educational and some other purpose only),
      i have built GUI system before using 2D systems such as that of HTML/JS canvas, but in 2D system, i can directly match a mouse coordinates to the actual graphic coordinates with additional computation for screen size/ratio/scale ofcourse.
      now i want to port it to OpenGL, i know that to render a 2D object in OpenGL we specify coordiantes in Clip space or use the orthographic projection, now heres what i need help about.
      1. what is the right way of rendering the GUI? is it thru drawing in clip space or switching to ortho projection?
      2. from screen coordinates (top left is 0,0 nd bottom right is width height), how can i map the mouse coordinates to OpenGL 2D so that mouse events such as button click works? In consideration ofcourse to the current screen/size dimension.
      3. when let say if the screen size/dimension is different, how to handle this? in my previous javascript 2D engine using canvas, i just have my working coordinates and then just perform the bitblk or copying my working canvas to screen canvas and scale the mouse coordinates from there, in OpenGL how to work on a multiple screen sizes (more like an OpenGL ES question).
      lastly, if you guys know any books, resources, links or tutorials that handle or discuss this, i found one with marekknows opengl game engine website but its not free,
      Just let me know. Did not have any luck finding resource in google for writing our own OpenGL GUI framework.
      IF there are no any available online, just let me know, what things do i need to look into for OpenGL and i will study them one by one to make it work.
      thank you, and looking forward to positive replies.
    • By fllwr0491
      I have a few beginner questions about tesselation that I really have no clue.
      The opengl wiki doesn't seem to talk anything about the details.
       
      What is the relationship between TCS layout out and TES layout in?
      How does the tesselator know how control points are organized?
          e.g. If TES input requests triangles, but TCS can output N vertices.
             What happens in this case?
      In this article,
      http://www.informit.com/articles/article.aspx?p=2120983
      the isoline example TCS out=4, but TES in=isoline.
      And gl_TessCoord is only a single one.
      So which ones are the control points?
      How are tesselator building primitives?
    • By Orella
      I've been developing a 2D Engine using SFML + ImGui.
      Here you can see an image
      The editor is rendered using ImGui and the scene window is a sf::RenderTexture where I draw the GameObjects and then is converted to ImGui::Image to render it in the editor.
      Now I need to create a 3D Engine during this year in my Bachelor Degree but using SDL2 + ImGui and I want to recreate what I did with the 2D Engine. 
      I've managed to render the editor like I did in the 2D Engine using this example that comes with ImGui. 
      3D Editor preview
      But I don't know how to create an equivalent of sf::RenderTexture in SDL2, so I can draw the 3D scene there and convert it to ImGui::Image to show it in the editor.
      If you can provide code will be better. And if you want me to provide any specific code tell me.
      Thanks!
  • Popular Now