[REF/DEV] KaiserGL SDK (for Imageon on Qualcomm 72xx devices)

NuShrike

Senior Recognized Developer
Sep 18, 2007
1,128
69
0
Following up from post getting OT in thread:
My opengl es init function is called after UpdateWindow(), so I'm still stumped as to why the surface still cannot be created... here's my winmain:
You might be missing some of the modern WM6 calls. Here's the relevant code from the working ported version of Graphics for the Masses.

I started with working code from the AppWizard. tabs/spaces is pushing the formatting everywhere:

Code:
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPTSTR    lpCmdLine,
                   int       nCmdShow)
{
	MSG msg;
	HACCEL hAccelTable;
	int retval;

	// Perform application initialization:
	if (!InitInstance(hInstance, nCmdShow)) 
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_APPSTUFF));

	// Main message loop:
	for(;;)
	{
		switch(gMinimized_mode)
		{
		case 0:
game_loop:
			while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) == TRUE)
			{
				if (GetMessage(&msg, NULL, 0, 0) )
				{
					if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
					{
						TranslateMessage(&msg);
						DispatchMessageW(&msg);
					}
				}
				else
				{
					retval = (int) msg.wParam;
					goto out;
				}
			}

			if (!gMinimized_mode)
			{
				/* app code */
				eglSwapBuffers  (eglDisplay, eglWindowSurface);
				if(retval == 0)
				{
					/* app exit code */
					goto out;
				}
			}
			break;
		default:
			while (GetMessage(&msg, NULL, 0, 0) )
			{
				if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
				{
					TranslateMessage(&msg);
					DispatchMessageW(&msg);
				}
				if (msg.message == WM_PAINT)
				{
					gMinimized_mode = 0;
					goto game_loop;
				}
			}
			retval = (int) msg.wParam;
			goto out;
		}
	}
out:
	return retval;
}

ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
{
	WNDCLASS wc;

	wc.style         = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc   = WndProc;
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = hInstance;
	wc.hIcon         = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPSTUFF));
	wc.hCursor       = 0;
	wc.hbrBackground = NULL;//(HBRUSH) GetStockObject(WHITE_BRUSH);
	wc.lpszMenuName  = 0;
	wc.lpszClassName = szWindowClass;

	return RegisterClass(&wc);
}

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
    HWND hWnd;
    TCHAR szTitle[MAX_LOADSTRING];		// title bar text
    TCHAR szWindowClass[MAX_LOADSTRING];	// main window class name

    g_hInst = hInstance; // Store instance handle in our global variable

    // SHInitExtraControls should be called once during your application's initialization to initialize any
    // of the device specific controls such as CAPEDIT and SIPPREF.
    SHInitExtraControls();

    //LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	wcscpy(szTitle, appName);
    LoadString(hInstance, IDC_OGLESEXFW, szWindowClass, MAX_LOADSTRING);

    //If it is already running, then focus on the window, and exit
    hWnd = FindWindow(szWindowClass, szTitle);	
    if (hWnd) 
    {
        // set focus to foremost child window
        // The "| 0x00000001" is used to bring any owned windows to the foreground and
        // activate them.
        SetForegroundWindow((HWND)((ULONG) hWnd | 0x00000001));
        return 0;
    } 

    if (!MyRegisterClass(hInstance, szWindowClass))
    {
    	return FALSE;
    }

    hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
        CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);

    if (!hWnd)
    {
        return FALSE;
    }

    // When the main window is created using CW_USEDEFAULT the height of the menubar (if one
    // is created is not taken into account). So we resize the window after creating it
    // if a menubar is present
    if (g_hWndMenuBar)
    {
        RECT rc;
        RECT rcMenuBar;

        GetWindowRect(hWnd, &rc);
        GetWindowRect(g_hWndMenuBar, &rcMenuBar);
        rc.bottom -= (rcMenuBar.bottom - rcMenuBar.top);
		
        MoveWindow(hWnd, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, FALSE);
    }


    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);

	{
		/* EGL Setup */
		EGLContext ctx;
		EGLint majorVersion;
		EGLint minorVersion;

		//eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
		eglDisplay = eglGetDisplay(GetDC(hWnd));
		eglInitialize(eglDisplay, &majorVersion, &minorVersion);
		eglConfig = select_config(eglDisplay, EGL_WINDOW_BIT, 16, 16, 4); 
		ctx = eglCreateContext(eglDisplay, eglConfig, NULL, NULL);
		eglWindowSurface = eglCreateWindowSurface(eglDisplay, eglConfig, hWnd, NULL);
		eglMakeCurrent(eglDisplay, eglWindowSurface, eglWindowSurface, ctx);
		/* rest of app init */
	}

    return TRUE;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int wmId, wmEvent;
    PAINTSTRUCT ps;
    HDC hdc;

    static SHACTIVATEINFO s_sai;
	
    switch (message) 
    {
        case WM_COMMAND:
            wmId    = LOWORD(wParam); 
            wmEvent = HIWORD(wParam); 
            // Parse the menu selections:
            switch (wmId)
            {
                case IDM_HELP_ABOUT:
                    DialogBox(g_hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, About);
                    break;
                case IDM_OK:
                    SendMessage (hWnd, WM_CLOSE, 0, 0);				
                    break;
                default:
                    return DefWindowProc(hWnd, message, wParam, lParam);
            }
            break;
        case WM_CREATE:
			{
				SHMENUBARINFO mbi;

				memset(&mbi, 0, sizeof(SHMENUBARINFO));
				mbi.cbSize     = sizeof(SHMENUBARINFO);
				mbi.hwndParent = hWnd;
				mbi.nToolBarId = IDR_MENU;
				mbi.hInstRes   = g_hInst;

				if (!SHCreateMenuBar(&mbi)) 
				{
					g_hWndMenuBar = NULL;
				}
				else
				{
					g_hWndMenuBar = mbi.hwndMB;
				}

				// Initialize the shell activate info structure
				memset(&s_sai, 0, sizeof (s_sai));
				s_sai.cbSize = sizeof (s_sai);
			}
            break;
        case WM_PAINT:
            hdc = BeginPaint(hWnd, &ps);            
            // TODO: Add any drawing code here...            
            EndPaint(hWnd, &ps);
            if (!gMinimized_mode) eglSwapBuffer();
            break;
        case WM_DESTROY:
            eglMakeCurrent(NULL, NULL, NULL, NULL);
            eglDestroyContext(eglDisplay, eglContext);
            eglDestroySurface(eglDisplay, eglWindowSurface);
            eglTerminate(eglDisplay);

            CommandBar_Destroy(g_hWndMenuBar);
            PostQuitMessage(0);
            break;

		case WM_SIZE:
			switch(wParam)
			{
			case SIZE_MINIMIZED:
				gMinimized_mode = 1;
				break;
			case SIZE_MAXIMIZED: case SIZE_RESTORED: case SIZE_MAXSHOW:
				gMinimized_mode = 0;
			default:
				{
					RECT wrect;
					GetClientRect(hwnd, &wrect);
					/* app resize code */
					break;
				}
			}
			break;

        case WM_ACTIVATE:
            // Notify shell of our activate message
            SHHandleWMActivate(hWnd, wParam, lParam, &s_sai, FALSE);
            break;
        case WM_SETTINGCHANGE:
            SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai);
            break;

        case WM_KEYDOWN:
        {
            switch(wParam)
            {
            case(VK_UP):
                break;
            case(VK_DOWN):
                break;
            case(VK_LEFT):
                break;
            case(VK_RIGHT):
                break;
            case(VK_RETURN):
                break;
            }
            if (wParam == VK_ESCAPE)
				SendMessage(hwnd, WM_CLOSE, 0, 0);
			break;
        }

        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}
 

ycavan

Senior Member
Nov 9, 2007
408
294
83
I'm using evc4, so I can't build for a THUMB ( wince 5.0 ) device... any way you can recompile the lib for ARMv4?

Otherwise, I'm still linking w/ the Vincent lib.

Anyway, I started a whole new app ( appwizard hello template ) instead of writing the winmain from scratch and I still cannot generate a surface when I have anything but EGL_NONE in the config requests.

One thing I note is that fps is about 47-48, but once again, the texture is not mapped onto the object. If I put it in my folder w/ the Vincent dll, the texture is mapped and the fps is about 11-12.

I'm not quite familiar w/ EGL, but... does anyone know the EGLConfig structure? I tried searching for it to see what the requested width/height per config was so I can debug why the surface just doesn't get created.

anyway, here's my code:
View attachment TestApp2.zip
 

NuShrike

Senior Recognized Developer
Sep 18, 2007
1,128
69
0
I'm using evc4, so I can't build for a THUMB ( wince 5.0 ) device... any way you can recompile the lib for ARMv4?
That's ARMv4 or ARMv4i? I'm going to assume latter because that's what most of the dlls seem to be targeting. I'll put this up soon.

Meantime, GetClientRect() on your hwnd and make sure the rect is sane before you pass it on to eglCreateWindowSurface().

Also, Imageon may work better with GLfloat values although it probably kills Vincent (with software emulation on the ARM without native FP support in armv6 by the compiler) with anything but GLfixed. Try some benchmarking to see which works out better.
 
Last edited:

ycavan

Senior Member
Nov 9, 2007
408
294
83
That's ARMv4 or ARMv4i? I'm going to assume latter because that's what most of the dlls seem to be targeting. I'll put this up soon.

Meantime, GetClientRect() on your hwnd and make sure the rect is sane before you pass it on to eglCreateWindowSurface().
.
ARMv4 is what evc4 targets...
GetClientRect() is giving me very sane values, 268x240... 268 due to the bars up top & below.

I guess I'm just confused as to why Vincent is able to properly create the proper surface while our drivers cannot...

Edit:
//eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglDisplay = eglGetDisplay(GetDC(hWnd));
eglInitialize(eglDisplay, &majorVersion, &minorVersion);
eglConfig = select_config(eglDisplay, EGL_WINDOW_BIT, 16, 16, 4);
ctx = eglCreateContext(eglDisplay, eglConfig, NULL, NULL);
eglWindowSurface = eglCreateWindowSurface(eglDisplay, eglConfig, hWnd, NULL);
eglMakeCurrent(eglDisplay, eglWindowSurface, eglWindowSurface, ctx);
/* rest of app init */
I just realized that you don't provide egl config attribs for for eglCreateWindowSurface or for eglCreateContext... huh. Doing that, the surface and context are created ok, but the texture still isn't loaded... mebbe a problem w/ texture loading. :p
 
Last edited:

cp_kirkley

Senior Member
Oct 29, 2007
269
13
0
Cypress, TX, USA
That's ARMv4 or ARMv4i? I'm going to assume latter because that's what most of the dlls seem to be targeting. I'll put this up soon.

Meantime, GetClientRect() on your hwnd and make sure the rect is sane before you pass it on to eglCreateWindowSurface().

Also, Imageon may with better with GLfloat values although it probably kills Vincent (with software emulation on the ARM without native FP support in armv6 by the compiler) with anything but GLfixed. Try some benchmarking to see which works out better.
In the words of the great Sammy L.
ENGLISH MOTHAF*CKA DO YOU SPEAK IT!?!
:D:D
 

ycavan

Senior Member
Nov 9, 2007
408
294
83
In the words of the great Sammy L.

:D:D
That's just rude, dood... lol

Anywho, it looks like the problem w/ texturing is that our drivers do not seem to support mipmap. By commenting out the linear mipmap flag when loading the texture, we get a fully working opengl es test app. :) I get about 44 fps.

See for yourselves. :)

View attachment testapp2.zip

@nushrike, both of your libgles_cm.lib's are designed for the 'THUMB' device. It's ok. I'll just keep on linking to the vincent lib.

Just remember that our driver does not support mipmap.
 

NuShrike

Senior Recognized Developer
Sep 18, 2007
1,128
69
0
I think it's eVC is too old then. It's been thumb since WinCE5. Most all the system libs I have to link to insiste on Thumb -- if I set it to ARM, it refuses to link. Hey, that's an idea.. I'll try ARM to see if it generates any .lib.

For hardware, or supported mipmapping (software or not), look up glGenerateMipmapOES(GL_TEXTURE_2D). The tech demo I posted earlier demonstrates this. It's that blurry looking rotating texture behind the checker-board and various other textures.

edit: nope, can't create a dummy .lib by trying to link ARM.
Instead, you can modify Vincent to fake-support the extended functions as you need them and as they exist in the HWA .dll exports list. Here's an example:
Code:
#ifdef __GL_EXPORTS
#   define GL_API __declspec(dllexport)
#else
#   define GL_API
#endif

#define GL_APICALL GL_API
#define GL_APIENTRY
#ifdef __cplusplus
extern "C" {
#endif
{
	GL_APICALL void         GL_APIENTRY glGenerateMipmapOES (GLenum target)
	{ return; }
#ifdef __cplusplus
}
#endif
 
Last edited:

NuShrike

Senior Recognized Developer
Sep 18, 2007
1,128
69
0
can you make a sourceforce project??
No code to make it a SourceForge project. Now, if it was code to make the drivers, that would be worthy.

ycavan: figured out your bug. You have to pass NULL for configAttrib (the last parameter) for eglCreateContext, and eglCreateWindowSurface. Also, using glGenerateMipmapOES(GL_TEXTURE_2D) with your source, texture works fine now. Same FPS. I'm seeing if converting to GLfloat will speed it up.

edit: float is no speed increase so far, but no decrease either.
 
Last edited:

ycavan

Senior Member
Nov 9, 2007
408
294
83
I'm sorry about not responding to the pm's... lol, I just didn't see them.

Anyway, just unzip the file on your pc and copy the exe and resources folder to your device and run the exe. Just make sure to keep the exe and resources folder together.
 

NuShrike

Senior Recognized Developer
Sep 18, 2007
1,128
69
0
Anyway, just unzip the file on your pc and copy the exe and resources folder to your device and run the exe. Just make sure to keep the exe and resources folder together.
It doesn't work for me after I drop it into the "Program Files" folder because this code is hard-coded for root directory then.
 

ycavan

Senior Member
Nov 9, 2007
408
294
83
really odd... i ran the program in its own directory w/o a problem... i'm @ work, so i'll check it out when i get home.

it looks like the "resources" directory must be on the root of the device...

I'm working on finding the cwd, but loading resources fails even though it's the correct wd... :p

You guys can try and see if this works...

Code:
TCHAR tPath[255];
char sPath[255];

// get full path to this executable
GetModuleFileName(NULL,tPath,255);
// find the last '\'
TCHAR* pos = wcsrchr(tPath,'\\');
// end the string after the last '\'
*(pos+1) = '\0';

// copy wide char array to multi-byte string
wcstombs(sPath,tPath,255);
sPath should contain the working directory... but my app is failing the resource loads even though this is the same full path as before...
 
Last edited:

jaikben22

Senior Member
Jan 23, 2007
88
3
0
this can be very intresting for xda flame with goforce? can you build the libs because there is no SDK avialeble, the test app doesn't work message:

OpenGL ES init error:
eglInitialize
 

ycavan

Senior Member
Nov 9, 2007
408
294
83
this can be very intresting for xda flame with goforce? can you build the libs because there is no SDK avialeble, the test app doesn't work message:

OpenGL ES init error:
eglInitialize
EDIT:
Just realized that you're talking about another phone w/ the goforce... lol
You will need to prolly google "goforce opengl es sdk" There should be quite a few out there. :)

On another note... I figured out the problem with working directory resource loading. :)
I prefer to make a call once when it's something configuration-related... like storing my current working directory... it seems that evc4 doesn't like it when I do that so I had to update mesh.cpp and texture.cpp to perform the GetModuleFileName calls in each load function.

Here's an updated TestApp2. You just need to keep testapp2.exe and the resources directory together.

View attachment testapp2.zip

Updates include:
+ fullscreen now
+ up/down rotation
+ left/right acceleration -100 to 100
+ spouting of particles

Have fun guys. :)

The resources directory contains these files that you can change if you want to try different things. :)

spot.raw - the particle system's balls texture
font.raw - the font texture
knot.gsd - the main object mesh
fire128.tga - the mesh object's texture
 
Last edited:
Our Apps
Get our official app!
The best way to access XDA on your phone
Nav Gestures
Add swipe gestures to any Android
One Handed Mode
Eases uses one hand with your phone