Guest User

Untitled

a guest
Apr 24th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.62 KB | None | 0 0
  1. public void Draw()
  2. {
  3. if (TitleScreen == true)
  4. {
  5. GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
  6.  
  7. GL.glBindTexture(GL.GL_TEXTURE_2D, m_TextureIDs[0]);
  8. DrawClouds();
  9. //System.Threading.Thread.Sleep(1000);
  10. DrawString(100, 575, "PROTECT THE PIE!", 0);
  11. DrawString(500, 575, "Press 'P' to Play", 0);
  12. DrawString(1000, 575, "Press 'E' to Exit", 0);
  13. }
  14. if (GamePlay == true)
  15. {
  16. GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
  17. DrawPicnicMat();
  18. DrawPieMask();
  19. DrawPie();
  20. DrawFly();
  21. DrawString(520, 825, "Protect The Pie!", 0);
  22. DrawString(75, 65, "Score:", 0);
  23. DrawString(900, 65, "Flies Killed:", 0);
  24. }
  25.  
  26. }
  27.  
  28. public void DrawString(int x, int y, string str, int charSet)
  29. {
  30. GL.glEnable(GL.GL_BLEND);
  31. GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);
  32.  
  33. //GL.glEnable(GL.GL_TEXTURE_2D);
  34. if (charSet > 1) { charSet = 1; }
  35. GL.glBindTexture(GL.GL_TEXTURE_2D, m_TextureIDs[1]);// Select Our Font Texture
  36. GL.glDisable(GL.GL_DEPTH_TEST);// Disables Depth Testing
  37. GL.glMatrixMode(GL.GL_PROJECTION);// Select The Projection Matrix
  38. GL.glPushMatrix();// Store The Projection Matrix
  39. GL.glLoadIdentity();// Reset The Projection Matrix
  40. GL.glOrtho(0, m_ScreenWidth, 0, m_ScreenHeight, 0, 10);// Set Up An Ortho
  41. // Screen with the same dimensions as the screen
  42. GL.glMatrixMode(GL.GL_MODELVIEW);// Select The Modelview Matrix
  43. GL.glPushMatrix();// Store The Modelview Matrix
  44. GL.glLoadIdentity();// Reset The Modelview Matrix
  45. GL.glTranslated(x, y, 0);// Position The Text (0,0 - Bottom Left)
  46. // Choose The Font Set (0 or 1)
  47. GL.glListBase((uint)(BaseList - 32 + (128 * charSet)));
  48. object[] t = new object[str.Length];// Convert string to an array of objects
  49. for (int i = 0; i < str.Length; i++)
  50. {
  51. t[i] = str[i];
  52. }
  53.  
  54. GL.glEnable(GL.GL_BLEND);
  55. // Write The Text To The Screen
  56. GL.glCallLists(str.Length * 4, GL.GL_UNSIGNED_int, t);
  57. GL.glDisable(GL.GL_BLEND);
  58. GL.glMatrixMode(GL.GL_PROJECTION);// Select The Projection Matrix
  59. GL.glPopMatrix();// Restore The Old Projection Matrix
  60. GL.glMatrixMode(GL.GL_MODELVIEW);// Select The Modelview Matrix
  61. GL.glPopMatrix();// Restore The Old Projection Matrix
  62. GL.glEnable(GL.GL_DEPTH_TEST);// Enables Depth Testing
  63. }
  64.  
  65. public void TextInitialise()
  66. {
  67. float cx, cy;
  68.  
  69. BaseList = GL.glGenLists(256);
  70. GL.glBindTexture(GL.GL_TEXTURE_2D, this.m_TextureIDs[1]);
  71.  
  72. //Select font Texture\\
  73. Bitmap image = new Bitmap("C:\\Users\\Emma Challis\\Desktop\\Project12\\Project1\\font.bmp");
  74. image.RotateFlip(RotateFlipType.RotateNoneFlipY);
  75. System.Drawing.Imaging.BitmapData bitmapdata;
  76. Rectangle rect = new Rectangle(0, 0, image.Width, image.Height);
  77. bitmapdata = image.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly,
  78. System.Drawing.Imaging.PixelFormat.Format24bppRgb);
  79.  
  80. GL.glBindTexture(GL.GL_TEXTURE_2D, m_TextureIDs[1]);
  81. GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, (int)GL.GL_RGB8, image.Width,
  82. image.Height, 0, GL.GL_BGR_EXT,
  83. GL.GL_UNSIGNED_byte, bitmapdata.Scan0);
  84. GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, (int)GL.GL_LINEAR);
  85. GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, (int)GL.GL_LINEAR);
  86.  
  87. image.UnlockBits(bitmapdata);
  88. image.Dispose();
  89.  
  90. for (float row = 0; row < 16; row++)
  91. {
  92. for (float col = 0; col < 16; col++)
  93. {
  94. cx = (float)row / 16.0f; // X Tex Coord Of Current Character
  95. cy = (float)col / 16.0f; // Y Tex Coord Of Current Character
  96. GL.glNewList((uint)(this.BaseList + col * 16 + row), GL.GL_COMPILE);
  97. // Start Building A List
  98. GL.glBegin(GL.GL_QUADS); // Use A Quad For Each Character
  99. GL.glTexCoord2f(cx, 1 - cy - 1f / 16f); //Texture Coord (Bottom Left)
  100. GL.glVertex2i(0, 0); // Vertex Coord (Bottom Left)
  101. GL.glTexCoord2f(cx + 1f / 16f, 1 - cy - 1f / 16f);// Texture Coord (Bottom Right)
  102. GL.glVertex2i(16, 0); // Vertex Coord (Bottom Right)
  103. GL.glTexCoord2f(cx + 1f / 16f, 1 - cy); // Texture Coord (Top Right)
  104. GL.glVertex2i(16, 16); // Vertex Coord (Top Right)
  105. GL.glTexCoord2f(cx, 1 - cy); // Texture Coord (Top Left)
  106. GL.glVertex2i(0, 16); // Vertex Coord (Top Left)
  107. GL.glEnd(); // Done Building Our Quad (Character)
  108. GL.glTranslated(10, 0, 0); // Move To The Right Of The Character Ready to
  109. // So That We’re Ready To Draw Another Character If We Need To
  110. GL.glEndList();// Done Building The Display List
  111. }
  112. }
  113. }
Add Comment
Please, Sign In to add comment