Partage
  • Partager sur Facebook
  • Partager sur Twitter

Problème affichage =S

Sujet résolu
    2 octobre 2011 à 15:10:56

    Bonjour,

    Je suis entrain de faire un jeu mais voila :
    quand j'affiche un block, il est bizarre :
    Image utilisateur

    normalement, il doit être blanc !

    Merci de votre aide !

    Ps: j'utilise la libraire Tao.OpenGl et Tao.Sdl + la classe Bitmap de System.Drawing
    • Partager sur Facebook
    • Partager sur Twitter
    Anonyme
      2 octobre 2011 à 15:17:50

      Salut,

      Avec le peu de code source qu'on peut voir en arrière plan, on va avoir du mal à t'aider :D
      • Partager sur Facebook
      • Partager sur Twitter
        2 octobre 2011 à 15:28:22

        Ah oui sut le seul truc que j'ai oublier !

        Veiw.cs :
        using System;
        using System.Drawing;
        using System.Threading;
        using Tao.OpenGl;
        using Tao.Sdl;
        
        namespace Jeu
        {
        	public class View
        	{
        		public StoneBlock st = new StoneBlock(0, 0, 0);
        		public uint[] texture;
        		
        		public void drawing()
        		{
        			//Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);	// Clear Screen and Depth Buffer
        			//Gl.glMatrixMode(Gl.GL_MODELVIEW);
        			//Gl.glLoadIdentity();
        			
        			st.render();
        			
        			Thread.Sleep(10);
        		}
        		
        		public View ()
        		{
        			texture = new uint[1];
        			bool con = true;
        			Sdl.SDL_Event ev = new Sdl.SDL_Event();
        			
        			Sdl.SDL_Init(Sdl.SDL_INIT_VIDEO);
        			Sdl.SDL_WM_SetCaption("test", null);
        			Sdl.SDL_SetVideoMode(640, 480, 32, Sdl.SDL_OPENGL);
        			
        			Gl.glMatrixMode( Gl.GL_PROJECTION );
        			Glu.gluPerspective(70,(double)640/480,1,1000);
        			Gl.glEnable(Gl.GL_DEPTH_TEST);
        			Gl.glEnable(Gl.GL_TEXTURE_2D);
        			
        			texture[0] = Utils.LoadTexture("data/terrain.bmp");
        			
        			Gl.glClearColor(0, 0, 0, 0);
        			
        			Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture[0]);
        			
        			float ax=0, ay=0;
        			
        			while (con)
            		{
                		Sdl.SDL_WaitEvent(out ev);
                		switch(ev.type)
                		{
                   			case Sdl.SDL_QUIT:
                        		con = false;
        						break;
                		}
        				Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);	// Clear Screen and Depth Buffer
        				Gl.glMatrixMode(Gl.GL_MODELVIEW);
        				Gl.glLoadIdentity();
        				
        				Glu.gluLookAt(-2, -2, -2, 0, 0, 0, 0, 0, 1);
        				
        				this.drawing();
        
               			Gl.glFlush();
                		Sdl.SDL_GL_SwapBuffers();
            		}
        
           	 		Sdl.SDL_Quit();
        		}	
        	}
        }
        


        StoneBlock.cs :
        using System;
        using Tao.OpenGl;
        
        namespace Jeu
        {
        	public class StoneBlock : Block
        	{
        		private float[] texpos;
        		
        		public StoneBlock (int x, int z, int y) : base(x, z, y, 1)
        		{
        			this.opac = true;
        			
        			texpos = new float[2] {0.0f, 0.0f};
        		}
        		
        		public void render()
        		{
        			Gl.glTranslatef((float)x, (float)z, (float)y);
        			
        			Gl.glBegin(Gl.GL_QUADS);
        			
            		Gl.glTexCoord2f(texpos[0], texpos[1]); Gl.glVertex3d(1,1,1);
            		Gl.glTexCoord2f(texpos[0]+TEX_LONG, texpos[1]); Gl.glVertex3d(1,1,-1); 
            		Gl.glTexCoord2f(texpos[0]+TEX_LONG, texpos[1]+TEX_LONG); Gl.glVertex3d(-1,1,-1); 
            		Gl.glTexCoord2f(texpos[0], texpos[1]+TEX_LONG); Gl.glVertex3d(-1,1,1); 
        
            		Gl.glTexCoord2f(texpos[0], texpos[1]);Gl.glVertex3d(1,-1,1); 
            		Gl.glTexCoord2f(texpos[0]+TEX_LONG, texpos[1]);Gl.glVertex3d(1,-1,-1); 
            		Gl.glTexCoord2f(texpos[0]+TEX_LONG, texpos[1]+TEX_LONG);Gl.glVertex3d(1,1,-1); 
            		Gl.glTexCoord2f(texpos[0], texpos[1]+TEX_LONG);Gl.glVertex3d(1,1,1); 
        
            		Gl.glTexCoord2f(texpos[0], texpos[1]);Gl.glVertex3d(-1,-1,1); 
            		Gl.glTexCoord2f(texpos[0]+TEX_LONG, texpos[1]);Gl.glVertex3d(-1,-1,-1); 
            		Gl.glTexCoord2f(texpos[0]+TEX_LONG, texpos[1]+TEX_LONG);Gl.glVertex3d(1,-1,-1); 
            		Gl.glTexCoord2f(texpos[0], texpos[1]+TEX_LONG);Gl.glVertex3d(1,-1,1); 
        
            		Gl.glTexCoord2f(texpos[0], texpos[1]);Gl.glVertex3d(-1,1,1); 
            		Gl.glTexCoord2f(texpos[0]+TEX_LONG, texpos[1]);Gl.glVertex3d(-1,1,-1); 
            		Gl.glTexCoord2f(texpos[0]+TEX_LONG, texpos[1]+TEX_LONG);Gl.glVertex3d(-1,-1,-1); 
            		Gl.glTexCoord2f(texpos[0], texpos[1]+TEX_LONG);Gl.glVertex3d(-1,-1,1); 
        
            		Gl.glTexCoord2f(texpos[0], texpos[1]);Gl.glVertex3d(1,1,-1); 
            		Gl.glTexCoord2f(texpos[0]+TEX_LONG, texpos[1]);Gl.glVertex3d(1,-1,-1); 
            		Gl.glTexCoord2f(texpos[0]+TEX_LONG, texpos[1]+TEX_LONG);Gl.glVertex3d(-1,-1,-1); 
            		Gl.glTexCoord2f(texpos[0], texpos[1]+TEX_LONG);Gl.glVertex3d(-1,1,-1); 
        
            		Gl.glTexCoord2f(texpos[0], texpos[1]);Gl.glVertex3d(1,-1,1); 
            		Gl.glTexCoord2f(texpos[0]+TEX_LONG, texpos[1]);Gl.glVertex3d(1,1,1); 
            		Gl.glTexCoord2f(texpos[0]+TEX_LONG, texpos[1]+TEX_LONG);Gl.glVertex3d(-1,1,1); 
            		Gl.glTexCoord2f(texpos[0], texpos[1]+TEX_LONG);Gl.glVertex3d(-1,-1,1); 
        
            		Gl.glEnd();
        		}
        	}
        }
        


        Utils.cs :
        using System;
        using System.IO;
        using System.IO.Compression;
        using System.Drawing;
        using System.Drawing.Imaging;
        
        using Tao.OpenGl;
        using Tao.Sdl;
        
        namespace Jeu
        {
        	public class Utils
        	{
        		public static IntPtr getFormat(IntPtr surface)
        		{
        			Sdl.SDL_Surface sur = (Sdl.SDL_Surface)System.Runtime.InteropServices.Marshal.PtrToStructure(surface, typeof(Sdl.SDL_Surface));
        			return sur.format;
        		}
        		
        		public static Sdl.SDL_Surface PtrToSurface(IntPtr surface)
        		{
        			return (Sdl.SDL_Surface)System.Runtime.InteropServices.Marshal.PtrToStructure(surface, typeof(Sdl.SDL_Surface));
        		}
        		
        		public static IntPtr SurfaceToPtr(Sdl.Surface surface)
        		{
        			System.Runtime.InteropServices.Marshal.StructureToPtr(
        		}
        		
        		public static void Compress(FileInfo fi)
                {
                    // Get the stream of the source file.
                    using (FileStream inFile = fi.OpenRead())
                    {
                        // Prevent compressing hidden and already compressed files.
                        if ((File.GetAttributes(fi.FullName) & FileAttributes.Hidden)
                                != FileAttributes.Hidden & fi.Extension != ".gz")
                        {
                            // Create the compressed file.
                            using (FileStream outFile = File.Create(fi.FullName + ".gz"))
                            {
                                using (GZipStream Compress = new GZipStream(outFile,
                                        CompressionMode.Compress))
                                {
                                    // Copy the source file into the compression stream.
                                    byte[] buffer = new byte[4096];
                                    int numRead;
                                    while ((numRead = inFile.Read(buffer, 0, buffer.Length)) != 0)
                                    {
                                        Compress.Write(buffer, 0, numRead);
                                    }
                                    //Console.WriteLine("Compressed {0} from {1} to {2} bytes.",
                                    //    fi.Name, fi.Length.ToString(), outFile.Length.ToString());
                                }
                            }
                        }
                    }
                }
        		
        		public static void Decompress(FileInfo fi)
                {
                    // Get the stream of the source file.
                    using (FileStream inFile = fi.OpenRead())
                    {
                        // Get original file extension, for example "doc" from report.doc.gz.
                        string curFile = fi.FullName;
                        string origName = curFile.Remove(curFile.Length - fi.Extension.Length);
        
                        //Create the decompressed file.
                        using (FileStream outFile = File.Create(origName))
                        {
                            using (GZipStream Decompress = new GZipStream(inFile,
                                    CompressionMode.Decompress))
                            {
                                //Copy the decompression stream into the output file.
                                byte[] buffer = new byte[4096];
                                int numRead;
                                while ((numRead = Decompress.Read(buffer, 0, buffer.Length)) != 0)
                                {
                                    outFile.Write(buffer, 0, numRead);
                                }
                                //Console.WriteLine("Decompressed: {0}", fi.Name);
        
                            }
                        }
                    }
                }
        		
        		public static uint LoadTexture(string path)
        		{
        			if(!File.Exists(path)) {
        				Console.WriteLine("File {0} do not exist !", path);
        				return 0;
        			}
        			
        			uint Texture=0;
        			Bitmap bm = new Bitmap(path);
        			bm.RotateFlip(RotateFlipType.RotateNoneFlipY);
        			Rectangle r = new Rectangle(0, 0, bm.Width, bm.Height);
        			
        			BitmapData bd = bm.LockBits(r, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
         
        		    //Gl.glGenTextures(0, out Texture);            // Allocate space for texture
        		    Gl.glBindTexture(Gl.GL_TEXTURE_2D, Texture); // Set our Tex handle as current
        			
            		Gl.glTexImage2D(Gl.GL_TEXTURE_2D,0,Gl.GL_RGBA,bm.Width,bm.Height,0,
                          		    Gl.GL_RGB,Gl.GL_UNSIGNED_BYTE,bd.Scan0);
        			
           			Gl.glTexParameteri(Gl.GL_TEXTURE_2D,Gl.GL_TEXTURE_MIN_FILTER,Gl.GL_LINEAR);
           			Gl.glTexParameteri(Gl.GL_TEXTURE_2D,Gl.GL_TEXTURE_MAG_FILTER,Gl.GL_LINEAR);
           			Gl.glTexParameteri(Gl.GL_TEXTURE_2D,Gl.GL_TEXTURE_WRAP_S,Gl.GL_CLAMP);
           			Gl.glTexParameteri(Gl.GL_TEXTURE_2D,Gl.GL_TEXTURE_WRAP_T,Gl.GL_CLAMP);
        			
        			bm.UnlockBits(bd);
        			bm.Dispose();
         
          			return Texture;
        		}
        	}
        }
        


        EDit : Problème résolut !

        Merci quand même !
        • Partager sur Facebook
        • Partager sur Twitter

        Problème affichage =S

        × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
        × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
        • Editeur
        • Markdown