Rev 828 | Rev 831 | 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 | { |
| 826 | chris | 83 | mOffscreen.activate(); |
| 84 | |||
| 85 | mApp.getGraphics().clear(1, 0.5f, 0.3f, 0); |
||
| 86 | mApp.getRenderStates().projection.setOrtho( |
||
| 87 | 0.0f, |
||
| 88 | 480, |
||
| 830 | chris | 89 | 480, |
| 826 | chris | 90 | 0.0f, |
| 91 | 0.0f, |
||
| 92 | 1.0f |
||
| 93 | ); |
||
| 94 | |||
| 797 | chris | 95 | mSprite.render(); |
| 826 | chris | 96 | mOffscreen.deactivate(); |
| 97 | |||
| 830 | chris | 98 | mApp.getGraphics().clear(0, 0.5f, 0.3f, 0); |
| 99 | |||
| 100 | //Gl.glViewport(0, 0, mGlView.Width, mGlView.Height); |
||
| 101 | mApp.getRenderStates().projection.setOrtho( |
||
| 102 | 0.0f, |
||
| 103 | mApp.getGraphics().getWidth(), |
||
| 104 | mApp.getGraphics().getHeight(), |
||
| 105 | 0.0f, |
||
| 106 | 0.0f, |
||
| 107 | 1.0f |
||
| 108 | ); |
||
| 109 | |||
| 826 | chris | 110 | BauzoidNET.graphics.renderstates.RenderStates rs = mApp.getGraphics().renderStates; |
| 111 | |||
| 827 | chris | 112 | rs.view.identity(); |
| 113 | rs.model.identity(); |
||
| 114 | |||
| 826 | chris | 115 | mShader.activate(); |
| 116 | { |
||
| 117 | //mOffscreen.getColorBufferTexture().setFilter(TextureFilter.Nearest, TextureFilter.Nearest); |
||
| 118 | // HACK: |
||
| 119 | |||
| 120 | mTextureHandle.set(0); |
||
| 121 | rs.getTextureStage(0).bindTexture(mOffscreen.getColorTexture()); |
||
| 122 | |||
| 123 | rs.blending.setEnabled(false); |
||
| 124 | rs.culling.setEnabled(false); |
||
| 125 | rs.depthTest.setEnabled(false); |
||
| 126 | rs.activate(); |
||
| 127 | { |
||
| 128 | mQuad.render(); |
||
| 129 | } |
||
| 130 | rs.deactivate(); |
||
| 131 | rs.popModelMatrix(); |
||
| 132 | rs.popViewMatrix(); |
||
| 133 | } |
||
| 134 | mShader.deactivate(); |
||
| 780 | chris | 135 | } |
| 816 | chris | 136 | |
| 137 | private void colorWidget1_ColorChange(object sender, EventArgs e) |
||
| 138 | { |
||
| 819 | chris | 139 | foreColorPanel.BackColor = mainColorWidget.CurrentColor; |
| 825 | chris | 140 | swatchesBox.CurrentColor = mainColorWidget.CurrentColor; |
| 816 | chris | 141 | } |
| 824 | chris | 142 | |
| 143 | private void colorPalette1_ColorPicked(object sender, EventArgs e) |
||
| 144 | { |
||
| 825 | chris | 145 | mainColorWidget.CurrentColor = swatchesBox.CurrentColor; |
| 146 | foreColorPanel.BackColor = swatchesBox.CurrentColor; |
||
| 824 | chris | 147 | } |
| 825 | chris | 148 | |
| 149 | private void mGlView_Resize(object sender, EventArgs e) |
||
| 150 | { |
||
| 828 | chris | 151 | mApp.getGraphics().updateSurfaceDimensions(mGlView.Width, mGlView.Height); |
| 825 | chris | 152 | } |
| 780 | chris | 153 | } |
| 154 | } |