JTalton's picture

Issue: GameWindow Icon Support

Project:The Open Toolkit library
Version:1.0-beta-1
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

I am getting to the point in my project where it would be nice to post screen shots. It would be nice to have Icon support for the GameWindow.


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

#11

Ok, I have added support for this on Windows (rev. 2331, trunk). Linux/Mac OS X support is missing right now.

Follow the instructions above to set the application icon - OpenTK should pick that automatically.

ghiboz's picture

#12

Thanks fiddler, I tried, but only the .exe have the icon that I set under options->application, the window and in the task bar doesn't have the icon...
the only solution that works is to send the message to change the icon...

rakkarage's picture

#13

the easiest way i have found to do it is to...

from the project settings where you can set the manifest icon...
click on resources 4 tabs down and create a resource file if one not exist...
drag the icon from project (or anywhere) to the icon section of the resource editor...

how its in resources you can access with

using WindowsFormsApplication1.Properties;
 
...
 
private void Form1_Load(object sender, EventArgs e)
{
	Icon = Properties.Resources.IconName;
}

there are a few other ways to include icons in your project...
1. use the manifest icon in project settings... but how you load this at runtime i have not figured out
2.you can goto properties of a icon in your project and change its build action to embedded resource... again how to load a runtime...
3.if you use the windows form editor and you set the icon in the desgner it adds the actual icon to the forms resx file

i guess the best was would be as you said to try and get the manifest icon somehow? unless people have a need for more then one icon which maybe

rakkarage's picture

#14

i figured out how to get the application manifest icon...

Assembly a = Assembly.GetExecutingAssembly();
string[] name = a.GetManifestResourceNames();

Stream s = a.GetManifestResourceStream(name[1]); //or namespace.folder.icon
Icon = new Icon(s);

but not sure how the app can do this generically... the names and order of the resources will be diff... maybe just provide a method to set icon

the Fiddler's picture

#15

Thanks for the code.

What I was trying to do is load the default application icon automatically (the one set through the "Application Icon" field in the project properties). I've hit the same roadblock: I haven't been able to find a way to do this generically. I've tried using "ExtractAssociatedIcon" and similar APIs, but all return the generic "exe" icon (this what you are seeing in the latest SVN version).

Well, if worse comes to worst, I'll simply provide an Icon property as you suggest. WinForms do this, so it's not that strange, but I don't really like this solution (you have to embed the icon twice: once for the "application" icon and once for the taskbar/menu icon).

rakkarage's picture

#16

Assembly a = Assembly.GetExecutingAssembly();
string[] name = a.GetManifestResourceNames();
Stream s = a.GetManifestResourceStream(name[1]); 
Icon = new Icon(s);

this will get the icon from the manifest and set it to the forms icons... so you dont need to include it twice... this should at least fix the "your icon not showing" problem but it does not fix the "our icon not showing" problem :)

the code is not great... you can examine the name array and just use a constant string (was having problems typing the correct name myself) to get the value you need to pass to getmanifestresourcestream then set Form.Icon to new Icon(stream)

but if you set the default gamewindow icon to the assembly icon (some defult opentk icon?) and then expose some icon property to change icons? some may even have dif windows and want dif icons for each?

thanks

rakkarage's picture

#17

for example

form.Icon = new Icon(Assembly.GetExecutingAssembly().GetManifestResourceStream("Namespace.Iconname.ico"));

rakkarage's picture

#18

o sorry i guess i misunderstood... you wanted to leave the icon setting on the property page at the default setting?

it worked for me after i changed the icon (on the project property page) from default to one that i had just added to the project...

this added a new stream to Assembly.GetExecutingAssembly().GetManifestResourceNames();

the icon that you use now (the default, i guess) (but the default icon for a new windows form application is different?) shows up in the right left of the form (GameWindow) itself AND in the alt tab window but not on the task bar? i wonder why that is...

but its a different problem... you can set a custom and the default is working except in the taskbar?

rakkarage's picture

#19

is gamewindow even a form? or just a win32 window?

checked out the source trying to find where to test this setting icon stuff

the Fiddler's picture

#20

It is a native win32 window (and x11 or carbon window on Linux / Mac OS X, respectively). WinForms do not perform well enough for real time games.

RIght now, the icon is set OpenTK/Platform/Windows/WinGLNative.cs:545 and extracted through the GetApplicationIcon() method at line 589 of the same file.

If it proves impossible to extract the application icon reliably, we'll just add an "Icon" property to OpenTK/INativeWindow.cs and expose it through OpenTK/NativeWindow.cs.