
[Solved] All textures appear in same size!
Posted Monday, 1 June, 2009 - 12:06 by CheatCat inI have 3 images in different sizes: 32x32; 128x128 and 256x256. But when I try to use them as textures they will appear in same size!
What is wrong?
The code:
using System; using System.Drawing; using OpenTK; using OpenTK.Graphics; using OpenTK.Audio; using OpenTK.Math; using OpenTK.Input; using OpenTK.Platform; namespace StarterKit { class Game : GameWindow { // Creates a new TextPrinter to draw text on the screen. TextPrinter printer = new TextPrinter(TextQuality.Medium); Font sans_serif = new Font(FontFamily.GenericSansSerif, 18.0f); int texture = 0, tex2 = 0, tex3 = 0; public Game() : base(800, 600, GraphicsMode.Default, "Test") { VSync = VSyncMode.On; } public override void OnLoad(EventArgs e) { TexLib.TexUtil.InitTexturing(); GL.ClearColor(System.Drawing.Color.CornflowerBlue); texture = TexLib.TexUtil.CreateTextureFromFile("hej.png"); tex2 = TexLib.TexUtil.CreateTextureFromFile("tjo.png"); tex3 = TexLib.TexUtil.CreateTextureFromFile("tja.png"); GL.Enable(EnableCap.DepthTest); } protected override void OnResize(ResizeEventArgs e) { GL.Viewport(0, 0, Width, Height); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); Glu.Perspective(45.0, Width / (double)Height, 1.0, 64.0); } public override void OnUpdateFrame(UpdateFrameEventArgs e) { if (Keyboard[Key.Escape]) { Exit(); } } public override void OnRenderFrame(RenderFrameEventArgs e) { GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); Glu.LookAt(Vector3.Zero, Vector3.UnitZ, Vector3.UnitY); //First texture GL.BindTexture(TextureTarget.Texture2D, texture); GL.LoadIdentity(); GL.Translate(6, 0, -15); GL.Begin(BeginMode.Quads); GL.TexCoord2(0, 0); GL.Vertex3(-1, 1, 0); GL.TexCoord2(1, 0); GL.Vertex3(1, 1, 0); GL.TexCoord2(1, 1); GL.Vertex3(1, -1, 0); GL.TexCoord2(0, 1); GL.Vertex3(-1, -1, 0); GL.End(); //Second texture GL.BindTexture(TextureTarget.Texture2D, tex2); GL.LoadIdentity(); GL.Translate(-3, 0, -15); GL.Begin(BeginMode.Quads); GL.TexCoord2(0, 0); GL.Vertex3(-1, 1, 0); GL.TexCoord2(1, 0); GL.Vertex3(1, 1, 0); GL.TexCoord2(1, 1); GL.Vertex3(1, -1, 0); GL.TexCoord2(0, 1); GL.Vertex3(-1, -1, 0); GL.End(); //3:rd texture GL.BindTexture(TextureTarget.Texture2D, tex3); GL.LoadIdentity(); GL.Translate(5, 5, -15); GL.Begin(BeginMode.Quads); GL.TexCoord2(0, 0); GL.Vertex3(-1, 1, 0); GL.TexCoord2(1, 0); GL.Vertex3(1, 1, 0); GL.TexCoord2(1, 1); GL.Vertex3(1, -1, 0); GL.TexCoord2(0, 1); GL.Vertex3(-1, -1, 0); GL.End(); SwapBuffers(); } [STAThread] static void Main() { using (Game game = new Game()) { game.Run(30.0, 0.0); } } } }


Comments
Re: All textures appear in same size!
This thread makes awesome general advice about the difference between rendering 2D and 3D.
Cheers, guys. That stuff will come in handy for me, too!
Re: All textures appear in same size!
@CheatCat
About layers; one simple approach is to render quads using different z-values. Z-values are still valid in orthographic projection. Just use the depth-buffer as usual.
It still requires you to find out how to pick good z-values though, and that is something application/game specific you must decide yourself.
Make sure you supply some sane values when specifying the Ortho projection matrix:
GL.Ortho(0, W, 0, H, -100, 100);
.. then you can have "layers" ranging from -100 (in the way back) to 100 (up close). Remember that in orthographic mode, the z value does not alter the x and y coordinate of vertices.
Re: All textures appear in same size!
Hehe, I just want to have some background stuff, not do a 2D - 3D game! :P
And when I want change the z-depth using the Vertex3 stuff? Or GL.Translate?
Well, now I don't see the texture again! xD
NVM, when l add GL.LoadIdentity() to the Blit function it works!
And it works to change the z-depth with Vertex3! OpenGL is cool! I made a new Blit function for this purpose:
Re: [Solved] All textures appear in same size!
CheatCat:
Whether to set the z-value from Vertex-calls or via Translate is a matter of choice. You decide ;)
Re: [Solved] All textures appear in same size!
Well, then I think I use Translate! :)
Re: [Solved] All textures appear in same size!
When will you show us some screenshots? You can blog about your progress here at opentk.com:
http://www.opentk.com/blog
Re: [Solved] All textures appear in same size!
Screenshots? It only a screen with colored squares! xD
Re: [Solved] All textures appear in same size!
Using translate is more future-proof. It will continue to work even if you replace immediate mode (
GL.Vertex3()and the rest) with a more performant approach (e.g. vertex buffers).Re: [Solved] All textures appear in same size!
Hey !!
Well most graphics hardware requires that your texture images be always a size that is a power of two in each dimension.
I used Panda3D for my drawing images into textures, it might help you. Panda3D will rescale your images to next larger power than shrinking them down.