2012-01-06 6 views
1

저를 도울 수있는 사람이 있습니까? 비트 맵을 반환하는 Renderframe 함수가 있지만 OpenGL (TK)을 사용하여 3D에서 무언가를 그릴 수 있도록 C#으로 작성했습니다. 회전 된 큐브를 반환 할 수 있습니까? 또는 유효한 코드를 얻으려면 어떻게해야합니까? 모든 아이디어에 대한Bitmap with OpenGL with C#

많은 감사 또는 도움 :

public Animation() 
{ 
} 

public void Draw3D() 
{ 

    GL.Begin(BeginMode.Quads); 

    GL.Color3(0.0f, 1.0f, 0.0f);   // Set The Color To Green 
    GL.Vertex3(1.0f, 1.0f, -1.0f);  // Top Right Of The Quad (Top) 
    GL.Vertex3(-1.0f, 1.0f, -1.0f);  // Top Left Of The Quad (Top) 
    GL.Vertex3(-1.0f, 1.0f, 1.0f);  // Bottom Left Of The Quad (Top) 
    GL.Vertex3(1.0f, 1.0f, 1.0f);   // Bottom Right Of The Quad (Top) 

    GL.Color3(1.0f, 0.5f, 0.0f);   // Set The Color To Orange 
    GL.Vertex3(1.0f, -1.0f, 1.0f);  // Top Right Of The Quad (Bottom) 
    GL.Vertex3(-1.0f, -1.0f, 1.0f);  // Top Left Of The Quad (Bottom) 
    GL.Vertex3(-1.0f, -1.0f, -1.0f);  // Bottom Left Of The Quad (Bottom) 
    GL.Vertex3(1.0f, -1.0f, -1.0f);  // Bottom Right Of The Quad (Bottom) 

    GL.Color3(1.0f, 0.0f, 0.0f);   // Set The Color To Red 
    GL.Vertex3(1.0f, 1.0f, 1.0f);   // Top Right Of The Quad (Front) 
    GL.Vertex3(-1.0f, 1.0f, 1.0f);  // Top Left Of The Quad (Front) 
    GL.Vertex3(-1.0f, -1.0f, 1.0f);  // Bottom Left Of The Quad (Front) 
    GL.Vertex3(1.0f, -1.0f, 1.0f);  // Bottom Right Of The Quad (Front) 

    GL.Color3(1.0f, 1.0f, 0.0f);   // Set The Color To Yellow 
    GL.Vertex3(1.0f, -1.0f, -1.0f);  // Bottom Left Of The Quad (Back) 
    GL.Vertex3(-1.0f, -1.0f, -1.0f);  // Bottom Right Of The Quad (Back) 
    GL.Vertex3(-1.0f, 1.0f, -1.0f);  // Top Right Of The Quad (Back) 
    GL.Vertex3(1.0f, 1.0f, -1.0f);  // Top Left Of The Quad (Back) 

    GL.Color3(0.0f, 0.0f, 1.0f);   // Set The Color To Blue 
    GL.Vertex3(-1.0f, 1.0f, 1.0f);  // Top Right Of The Quad (Left) 
    GL.Vertex3(-1.0f, 1.0f, -1.0f);  // Top Left Of The Quad (Left) 
    GL.Vertex3(-1.0f, -1.0f, -1.0f);  // Bottom Left Of The Quad (Left) 
    GL.Vertex3(-1.0f, -1.0f, 1.0f);  // Bottom Right Of The Quad (Left) 

    GL.Color3(1.0f, 0.0f, 1.0f);   // Set The Color To Violet 
    GL.Vertex3(1.0f, 1.0f, -1.0f);  // Top Right Of The Quad (Right) 
    GL.Vertex3(1.0f, 1.0f, 1.0f);   // Top Left Of The Quad (Right) 
    GL.Vertex3(1.0f, -1.0f, 1.0f);  // Bottom Left Of The Quad (Right) 
    GL.Vertex3(1.0f, -1.0f, -1.0f);  // Bottom Right Of The Quad (Right) 

    GL.End(); 

    GL.Rotate(50, 1.0, 0, 0); 
} 


static Bitmap GetSnapShot(int width, int height) 
{ 
    var snapShotBmp = new Bitmap(width, height); 
    BitmapData bmpData = snapShotBmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); 
    GL.ReadPixels(0, 0, width, height, OpenTK.Graphics.OpenGL.PixelFormat.Bgr, PixelType.UnsignedByte, bmpData.Scan0); 
    snapShotBmp.UnlockBits(bmpData); 
    return snapShotBmp; 
} 

public Bitmap RenderFrame (int width, int height, int currentFrame, int totalFrames) 
{ 



    Draw3D(); 

    return GetSnapShot(width, height); 


} 

답변

2

당신은 렌더링 된 픽셀 얻기 위해 다음과 같은 방법을 사용할 수 있습니다 :

static Bitmap GetSnapShot(int width, int height) 
    { 
     var snapShotBmp = new Bitmap(width, height); 
     BitmapData bmpData = snapShotBmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, 
                PixelFormat.Format24bppRgb); 
     GL.ReadPixels(0, 0, width, height, OpenTK.Graphics.OpenGL.PixelFormat.Bgr, PixelType.UnsignedByte, 
         bmpData.Scan0); 
     snapShotBmp.UnlockBits(bmpData); 
     return snapShotBmp; 
    } 

widthheight가의 치수됩니다 뷰포트.