About Monkey 2 › Forums › Monkey 2 Programming Help › Incorrect colours in Windows
This topic contains 7 replies, has 2 voices, and was last updated by 
 Hezkore
 2 years, 5 months ago.
- 
		AuthorPosts
 - 
		
			
				
November 16, 2016 at 4:33 pm #5103
It seems colours are incorrect when compiling to Windows.
But are correct when using Emscripten.Here’s how my Windows executable looks: (Wrong)

And here’s Emscripten: (Correct)

Here’s the test code:
Monkey1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class MyWindow Extends WindowMethod OnRender( canvas:Canvas ) Override'Blue via HEXcanvas.Color=GetHexColor("#282C34")canvas.DrawRect(0,0,256,256)'Blue via RGBcanvas.Color=New Color(40.0/255.0,44.0/255.0,52.0/255.0)canvas.DrawRect(256,0,256,256)'Green via HEXcanvas.Color=GetHexColor("#223333")canvas.DrawRect(0,256,256,256)EndEndFunction Main()New AppInstanceNew MyWindowApp.Run()End'Taken from Mojo's theme loaderFunction GetHexColor:Color(str:String)Local a:=1.0,r:=0.0,g:=0.0,b:=0.0If str.StartsWith("#")If str.Length=4 '#RGBr=StringToULong( str.Slice( 1,2 ),16 )/15.0g=StringToULong( str.Slice( 2,3 ),16 )/15.0b=StringToULong( str.Slice( 3,4 ),16 )/15.0Else If str.Length=5 '#ARGBa=StringToULong( str.Slice( 1,2 ),16 )/15.0r=StringToULong( str.Slice( 2,3 ),16 )/15.0g=StringToULong( str.Slice( 3,4 ),16 )/15.0b=StringToULong( str.Slice( 4,5 ),16 )/15.0Else If str.Length=7 '#RRGGBBr=StringToULong( str.Slice( 1,3 ),16 )/255.0g=StringToULong( str.Slice( 3,5 ),16 )/255.0b=StringToULong( str.Slice( 5,7 ),16 )/255.0Else If str.Length=9 '#AARRGGBBa=StringToULong( str.Slice( 1,3 ),16 )/255.0r=StringToULong( str.Slice( 3,5 ),16 )/255.0g=StringToULong( str.Slice( 5,7 ),16 )/255.0b=StringToULong( str.Slice( 7,9 ),16 )/255.0ElseReturn Color.MagentaEndifElseReturn Color.MagentaEndifReturn New Color( r,g,b,a )EndNovember 16, 2016 at 8:44 pm #5111Might be something up with OpenGL initializion. Does this produce a ‘smooth’ range of colors?
Monkey1234567891011121314151617181920212223242526272829303132333435363738Namespace myapp#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class MyWindow Extends WindowMethod New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=Null )Super.New( title,width,height,flags )EndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()For Local r:=0 until 256For Local g:=0 until 256canvas.Color=New Color( r/256.0,g/256,0 )canvas.DrawPoint( r,g )NextNextEndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndNovember 16, 2016 at 8:49 pm #5112It certainly does not.

Looks great in Emscripten though!
November 16, 2016 at 9:04 pm #5115Woah, 4 bit color!
Will investigate…also, what OS/graphics card are you using?
November 16, 2016 at 9:10 pm #5117Thanks Mark, you da man!
I’m on Windows 10.
Ati/AMD card (r390x)
I updated my GPU drivers, uninstalled every program that might interfere with my colours (like f.lux), but sofar nothing’s solved it.I first noticed the problem when trying to make a Theme for Ted2Go and all the colours ending up wrong.
So I’ve been whining over at the Ted2Go thread heh.November 16, 2016 at 9:19 pm #5118OK, just pushed a possible fix to the ‘develop’ branch.
November 16, 2016 at 9:33 pm #5119Actually, before trying that you might want to give this a go – does it give a clean gradation of red in the lower half (top half yellow)?
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899#import "<libc>"#import "<sdl2>"#import "<gles20>"Namespace sdl2testUsing sdl2..Using gles20..Class SdlWindowField sdlWindow:SDL_Window PtrField sdlGLContext:SDL_GLContextMethod New()SDL_Init( SDL_INIT_VIDEO )libc.atexit( SDL_Quit )SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK,SDL_GL_CONTEXT_PROFILE_ES )SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION,2 )SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION,0 )SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER,1 )SDL_GL_SetAttribute( SDL_GL_RED_SIZE,8 )SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE,8 )SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE,8 )sdlWindow=SDL_CreateWindow( "SDL2 OpenGL Window",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,640,480,SDL_WINDOW_OPENGL )sdlGLContext=SDL_GL_CreateContext( sdlWindow )SDL_GL_MakeCurrent( sdlWindow,sdlGLContext )EndMethod Run()RepeatLocal event:SDL_EventWhile( SDL_PollEvent( Varptr event ) )Select event.typeCase SDL_WINDOWEVENTLocal wevent:=Cast<SDL_WindowEvent Ptr>( Varptr event )Select wevent->eventCase SDL_WINDOWEVENT_CLOSElibc.exit_(0)EndEndWendOnRender()SDL_GL_SwapWindow( sdlWindow )ForeverEndMethod OnRender()glClearColor( 1,1,0,1 )glClear( GL_COLOR_BUFFER_BIT )glEnable( GL_SCISSOR_TEST )For Local y:=0 Until 256glScissor( 0,y,640,1 )glClearColor( y/256.0,0,0,1 )glClear( GL_COLOR_BUFFER_BIT )NextglDisable( GL_SCISSOR_TEST )EndEndFunction Main()Local window:=New SdlWindowwindow.Run()EndNovember 16, 2016 at 9:35 pm #5120Yep, you did it Mark!
Looks great now, and finally I can have the IDE colours I want heh.
Thanks for the quick fix.Update: Oh didn’t see your second post.
I’ve still got the old version though and that last example you posted looks fine even on that one.

 - 
		AuthorPosts
 
You must be logged in to reply to this topic.