Rev 827 | Rev 830 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 780 | chris | 1 | using System; |
| 2 | using System.Collections.Generic; |
||
| 3 | using System.ComponentModel; |
||
| 4 | using System.Data; |
||
| 5 | using System.Drawing; |
||
| 6 | using System.Linq; |
||
| 7 | using System.Text; |
||
| 8 | using System.Threading.Tasks; |
||
| 9 | using System.Windows.Forms; |
||
| 10 | |||
| 781 | chris | 11 | using Tao.OpenGl; |
| 780 | chris | 12 | |
| 789 | chris | 13 | using BauzoidNET.app; |
| 14 | |||
| 793 | chris | 15 | using System.IO; |
| 16 | |||
| 780 | chris | 17 | namespace BauzoidEdit |
| 18 | { |
||
| 19 | public partial class MainForm : Form |
||
| 20 | { |
||
| 789 | chris | 21 | private BauzoidApp mApp = null; |
| 780 | chris | 22 | |
| 797 | chris | 23 | private BauzoidNET.graphics.sprite.Sprite mSprite = null; |
| 826 | chris | 24 | private BauzoidNET.graphics.texture.Framebuffer mOffscreen = null; |
| 797 | chris | 25 | |
| 826 | chris | 26 | private BauzoidNET.graphics.model.SimpleGeometry mQuad = null; |
| 27 | private BauzoidNET.graphics.shader.ShaderProgram mShader = null; |
||
| 28 | private BauzoidNET.graphics.shader.ShaderUniform mTextureHandle = null; |
||
| 29 | |||
| 780 | chris | 30 | public MainForm() |
| 31 | { |
||
| 32 | InitializeComponent(); |
||
| 33 | } |
||
| 34 | |||
| 789 | chris | 35 | private void MainForm_Load(object sender, EventArgs e) |
| 36 | { |
||
| 37 | mApp = new BauzoidApp(); |
||
| 825 | chris | 38 | mApp.init(mGlView.Width, mGlView.Height); |
| 797 | chris | 39 | |
| 826 | chris | 40 | mQuad = BauzoidNET.graphics.model.GeometryUtil.createQuad(mApp.getGraphics(), 0.0f, 0, 100.0f, 100.0f); |
| 41 | |||
| 42 | //mShader = ShaderUtil.createShaderFromFile(mApp.getGraphics(), Gdx.files.internal("data/shaders/offscreen.vert"), |
||
| 43 | //Gdx.files.internal("data/shaders/offscreen.frag"));*/ |
||
| 44 | mShader = BauzoidNET.graphics.shader.ShaderUtil.createShaderFromFile(mApp.getGraphics(), "data/shaders/offscreen.vert", "data/shaders/offscreen.frag"); |
||
| 45 | |||
| 46 | if (mShader != null) |
||
| 47 | { |
||
| 48 | mTextureHandle = mShader.getUniform("uDiffuse"); |
||
| 49 | } |
||
| 50 | |||
| 797 | chris | 51 | mSprite = new BauzoidNET.graphics.sprite.Sprite(mApp.getGraphics(), "data/textures/test.png"); |
| 802 | chris | 52 | mSprite.init(10, 10, 300, 300, 0, 0); |
| 826 | chris | 53 | |
| 54 | mOffscreen = new BauzoidNET.graphics.texture.Framebuffer(mApp.getGraphics(), 128, 128, false); |
||
| 789 | chris | 55 | } |
| 56 | |||
| 57 | private void MainForm_FormClosing(object sender, FormClosingEventArgs e) |
||
| 58 | { |
||
| 797 | chris | 59 | if (mSprite != null) |
| 60 | { |
||
| 61 | mSprite.dispose(); |
||
| 62 | mSprite = null; |
||
| 63 | } |
||
| 64 | |||
| 826 | chris | 65 | if (mOffscreen != null) |
| 66 | { |
||
| 67 | mOffscreen.dispose(); |
||
| 68 | mOffscreen = null; |
||
| 69 | } |
||
| 70 | |||
| 71 | if (mQuad != null) |
||
| 72 | { |
||
| 73 | mQuad.dispose(); |
||
| 74 | mQuad = null; |
||
| 75 | } |
||
| 76 | |||
| 800 | chris | 77 | if (mApp != null) |
| 78 | mApp.exit(); |
||
| 789 | chris | 79 | } |
| 80 | |||
| 781 | chris | 81 | private void mGlView_Paint(object sender, PaintEventArgs e) |
| 780 | chris | 82 | { |
| 799 | chris | 83 | mApp.getGraphics().clear(0, 0.5f, 0.3f, 0); |
| 797 | chris | 84 | |
| 826 | chris | 85 | //Gl.glViewport(0, 0, mGlView.Width, mGlView.Height); |
| 797 | chris | 86 | mApp.getRenderStates().projection.setOrtho( |
| 87 | 0.0f, |
||
| 88 | 800, |
||
| 89 | 480, |
||
| 90 | 0.0f, |
||
| 91 | 0.0f, |
||
| 92 | 1.0f |
||
| 93 | ); |
||
| 800 | chris | 94 | |
| 801 | chris | 95 | /*Gl.glClearColor(1, 1, 1, 1); |
| 800 | chris | 96 | Gl.glClear(Gl.GL_COLOR_BUFFER_BIT); |
| 97 | |||
| 98 | Gl.glBegin(Gl.GL_TRIANGLES); |
||
| 99 | |||
| 100 | Gl.glColor3f(1, 0, 0); |
||
| 101 | Gl.glVertex2f(-1, -1); |
||
| 102 | |||
| 103 | Gl.glColor3f(0, 1, 0); |
||
| 104 | Gl.glVertex2f(1, -1); |
||
| 105 | |||
| 106 | Gl.glColor3f(0, 0, 1); |
||
| 107 | Gl.glVertex2f(0, 1); |
||
| 801 | chris | 108 | Gl.glEnd();*/ |
| 800 | chris | 109 | |
| 826 | chris | 110 | mOffscreen.activate(); |
| 111 | |||
| 112 | mApp.getGraphics().clear(1, 0.5f, 0.3f, 0); |
||
| 113 | mApp.getRenderStates().projection.setOrtho( |
||
| 114 | 0.0f, |
||
| 115 | 800, |
||
| 116 | 480, |
||
| 117 | 0.0f, |
||
| 118 | 0.0f, |
||
| 119 | 1.0f |
||
| 120 | ); |
||
| 121 | |||
| 797 | chris | 122 | mSprite.render(); |
| 826 | chris | 123 | |
| 124 | mOffscreen.deactivate(); |
||
| 125 | |||
| 126 | BauzoidNET.graphics.renderstates.RenderStates rs = mApp.getGraphics().renderStates; |
||
| 127 | |||
| 827 | chris | 128 | rs.view.identity(); |
| 129 | rs.model.identity(); |
||
| 130 | |||
| 826 | chris | 131 | mShader.activate(); |
| 132 | { |
||
| 133 | //mOffscreen.getColorBufferTexture().setFilter(TextureFilter.Nearest, TextureFilter.Nearest); |
||
| 134 | // HACK: |
||
| 135 | |||
| 136 | mTextureHandle.set(0); |
||
| 137 | rs.getTextureStage(0).bindTexture(mOffscreen.getColorTexture()); |
||
| 138 | |||
| 139 | rs.blending.setEnabled(false); |
||
| 140 | rs.culling.setEnabled(false); |
||
| 141 | rs.depthTest.setEnabled(false); |
||
| 142 | rs.activate(); |
||
| 143 | { |
||
| 144 | mQuad.render(); |
||
| 145 | } |
||
| 146 | rs.deactivate(); |
||
| 147 | rs.popModelMatrix(); |
||
| 148 | rs.popViewMatrix(); |
||
| 149 | } |
||
| 150 | mShader.deactivate(); |
||
| 780 | chris | 151 | } |
| 816 | chris | 152 | |
| 153 | private void colorWidget1_ColorChange(object sender, EventArgs e) |
||
| 154 | { |
||
| 819 | chris | 155 | foreColorPanel.BackColor = mainColorWidget.CurrentColor; |
| 825 | chris | 156 | swatchesBox.CurrentColor = mainColorWidget.CurrentColor; |
| 816 | chris | 157 | } |
| 824 | chris | 158 | |
| 159 | private void colorPalette1_ColorPicked(object sender, EventArgs e) |
||
| 160 | { |
||
| 825 | chris | 161 | mainColorWidget.CurrentColor = swatchesBox.CurrentColor; |
| 162 | foreColorPanel.BackColor = swatchesBox.CurrentColor; |
||
| 824 | chris | 163 | } |
| 825 | chris | 164 | |
| 165 | private void mGlView_Resize(object sender, EventArgs e) |
||
| 166 | { |
||
| 828 | chris | 167 | mApp.getGraphics().updateSurfaceDimensions(mGlView.Width, mGlView.Height); |
| 825 | chris | 168 | } |
| 780 | chris | 169 | } |
| 170 | } |