
Why can't I simply draw an image on the screen?
Posted Friday, 4 March, 2011 - 10:55 by EFileTahi-A inI want to use OpenTK for 2D ONLY. Having said that, I require only to draw text, lines, images and rectangles on the screen.
My first challenge: to draw a simple image on the screen at a given location. Why I'm having a hard time doing this? I mean, ok, I'm new to openGL but once I was also new to GDI+, SDL and DirectX and I managed to the 2D drawing thingie in such blissfuly and flawlessly way... Unfortunately SDL .NET does not work on Win7 64bit so I was forced to seek another Cross-platform solution.
I'm about to give up on openTK because I'm loosing time doing something that should be the most easy thing to do. I've ready the docs but there is nothing dedicated to 2D drawing. I know OpenGL is mainly for 3D but so is DirectX. Why DirectX is so easy to used towards 2D? Too bad is not cross-platform.
Anyway I've managed to draw an image to the screen through the example that came with the openTK package but I simply can't handle it's positionating right. I'm also surprised (by the negative) by the amout of lines of code that it requires to load a simply image to the screen. Than I have this GL.Ortho thing to help me out.
I have the GL.Ortho(0,800,600,0,0,1) as suggested in some website for 2D drawing, but I'm not getting anything to the screen. I don't even know if the way the texture is loaded is the right one for 2D. I don't know if I need quads to render the image to the screen. I don't know anything at this moment... apart from being completely lost on openTK.
So, if no one manages to help me at this forum I will be forced to deny opentk and keep the slow GDI+


Comments
Re: Why can't I simply draw an image on the screen?
Can you post your current code?
Re: Why can't I simply draw an image on the screen?
Re: Why can't I simply draw an image on the screen?
Short answer would be that "simply" is a relative term and you're loosing time because you're using a chainsaw to drive a screw. The type of functionality you want is offered by 2D engines.
OpenGL and by extent OpenTK is 3D oriented. It doesn't matter how many D's you use though, the code is more or less the same. On the other hand GDI+ and SDL are 2D oriented so they're *simpler* (not simple mind you!) to use in these scenarios. I don't know about DirectX and I can't be bothered.
You've forgotten about GL.Finish() before this.glControl.SwapBuffers();
Re: Why can't I simply draw an image on the screen?
Try this instead:
It's not necessary to call
GL.Finish()beforeSwapBuffers()as it is implicitly called anyway, according to the gl specs.Re: Why can't I simply draw an image on the screen?
Short answer would be that "simply" is a relative term and you're loosing time because you're using a chainsaw to drive a screw.
I believe i'm trying to use a hand-screw-drive to screw a giant bolt which was degined to be operated by an industrial screwier, accompanied by 500 page manual so that just the screwing rotation concept could be fully understood and put into practice.
A -
The type of functionality you want is offered by 2D engines.
Well DirectX happens to do this in a single line of code:
Sprite.Draw(Texture, theSprite.SourceRectangle, New Vector3(0.0F, 0.0F, 0.0F), New Vector3(0.0F, 0.0F, 0.0F), Color.White). And DirectX is not a 2D engine and yet operates 2D as almost as simple as GDI+. Unfortunately DX lacks cross-platform capabilities.
OpenGL and by extent OpenTK is 3D oriented. It doesn't matter how many D's you use though, the code is more or less the same. On the other hand GDI+ and SDL are 2D oriented so they're *simpler* (not simple mind you!) to use in these scenarios.
Yes, a thing I already knew and that I totally agree with you.
I don't know about DirectX and I can't be bothered.
This is the reason why you statement at 'A' will always return false.
So in sum, the complexity in using 2D on openTK / opengl is merely related to the way opengl was assembled. It's difficulty level also gets worse when no documentation is available to explain how to operate the industrial screw driver to screw small hand-bolts. OpenGL reminds me of the WWII Bismark German Battleship, incredible fast and powerful yet inefficient to shoot down the simple WWI primitive airplanes that attacked her destroying the rudder with a single torpedo, rendering the ship useless.
You've forgotten about GL.Finish() before this.glControl.SwapBuffers();
the GL.Finish() is not here in the code because I was passing code from my application's classes to the forum and it got left out by mistake.
The problem remains: (As I stated in my first post) How can I draw an image at a specific X,Y coordinate on the screen. My problem is not displaying a picture in the screen but to display it at a given location at certain size.
To be honest I begin actually to not care about it, I'm loosing too much time with this and I doubt someone will actually help me out, specialy, when I see people paying more attention to what and how I write instead focusing in helping.
Re: Why can't I simply draw an image on the screen?
Thanks I will try that once I get home.
But still How do I manage the 2D coord system for image positionation on the screen?
Is the way I'm redering the image the right one for 2D?
Re: Why can't I simply draw an image on the screen?
Well, I couldn't find anything inherently wrong with the code. It "should" work as it is. Maybe a forgotten setup call somewhere?
Now don't get me wrong but platform independence is a key issue here. IMO, DirectX can achieve this in a single line (apparently) BECAUSE it's platform limited. In other words, it knows what's what and behaves accordingly. OpenGL, on the other hand, has no concept of windows (in the general sense not the OS) or composition therefore it cannot directly stick a bitmap at (230, 440). OpenGL, as you probably know, operates in abstract (3D) space and has no knowledge about its surroundings. This is where all sorts of utilities and toolkits step in. And that's why you're likely to find it in both a digital watch and a tomograph at your nearest hospital.
This is the reason why you statement at 'A' will always return false.
Mine was an advice not a statement. 2D engines go far beyond displaying images. Finding a good one is hard though, because everyone focuses on 3D nowadays. It's apparently much cooler and girls go crazy about it or so I've heard.
Using OpenGL for text rendering could also turn out to be a nightmare. So you really should consider a 2D engine given the requirements in your OP. There's at least one based on OpenTK (http://www.opentk.com/node/257?page=1). I'm not sure about its state though.
Edit: Hmmm, you're TextureMinFilter'ing twice. Probably a typo. One of them should read TextureMagFilter.
Edit2: Now that I think of it, you can copy images around using Frame Buffer Objects and framebuffer blitting but that might end up being more verbose codewise. Search for FBOs and glBlitFramebuffer.
Edit3: Unlike Windows, OpenGL Y coordinate is inverted (up is more) so you should also flip the bitmap upside down before displaying it.
Re: Why can't I simply draw an image on the screen?
Well, I decided to abandon OpenTK. I will stick with GDI+ for now. Its slow but it will do it. Yes a 2D is what I was seeking but after the SDL failure I ran out of options and decided to try OpenGL, also for curiosity as I had never tried it before.
Thanks for the post though and take care.
Re: Why can't I simply draw an image on the screen?
I dont know why nobody pointed out these errors in the code:
- it draws only to one pixel on the screen.
- is z-test disabled?
- it only draws points, it doesnt fill anything with a texture.
Re: Why can't I simply draw an image on the screen?
I dont know why nobody pointed out these errors in the code:
The world is cruel :(