public static void ccDrawCubicBezier(CCPoint origin, CCPoint control1, CCPoint control2, CCPoint destination, int segments, ccColor4F color) { VertexPositionColor[] vector3 = new VertexPositionColor[segments + 1]; float contentScaleFactor = CCDirector.sharedDirector().ContentScaleFactor; CCApplication cCApplication = CCApplication.sharedApplication(); float single = 0f; for (int i = 0; i < segments; i++) { float single1 = (float)Math.Pow((double)(1f - single), 3) * origin.x + 3f * (float)Math.Pow((double)(1f - single), 2) * single * control1.x + 3f * (1f - single) * single * single * control2.x + single * single * single * destination.x; float single2 = (float)Math.Pow((double)(1f - single), 3) * origin.y + 3f * (float)Math.Pow((double)(1f - single), 2) * single * control1.y + 3f * (1f - single) * single * single * control2.y + single * single * single * destination.y; vector3[i] = new VertexPositionColor(); vector3[i].Position = new Vector3(single1 * contentScaleFactor, single2 * contentScaleFactor, 0f); vector3[i].Color = new Color(color.r, color.g, color.b, color.a); single = single + 1f / (float)segments; } VertexPositionColor vertexPositionColor = new VertexPositionColor() { Color = new Color(color.r, color.g, color.b, color.a), Position = new Vector3(destination.x * contentScaleFactor, destination.y * contentScaleFactor, 0f) }; vector3[segments] = vertexPositionColor; cCApplication.basicEffect.TextureEnabled = false; cCApplication.basicEffect.VertexColorEnabled = true; foreach (EffectPass pass in cCApplication.basicEffect.CurrentTechnique.Passes) { pass.Apply(); cCApplication.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineStrip, vector3, 0, segments); } }
public static void ccDrawCircle(CCPoint center, float radius, float angle, int segments, bool drawLineToCenter, ccColor4B color) { int num = 1; if (drawLineToCenter) { num++; } CCApplication cCApplication = CCApplication.sharedApplication(); float contentScaleFactor = CCDirector.sharedDirector().ContentScaleFactor; float single = 6.28318548f / (float)segments; VertexPositionColor[] vector3 = new VertexPositionColor[2 * (segments + 2)]; for (int i = 0; i <= segments; i++) { float single1 = (float)i * single; float single2 = radius * (float)Math.Cos((double)(single1 + angle)) + center.x; float single3 = radius * (float)Math.Sin((double)(single1 + angle)) + center.y; vector3[i] = new VertexPositionColor(); vector3[i].Position = new Vector3(single2 * contentScaleFactor, single3 * contentScaleFactor, 0f); vector3[i].Color = new Color((int)color.r, (int)color.g, (int)color.b, (int)color.a); } cCApplication.basicEffect.TextureEnabled = false; cCApplication.basicEffect.VertexColorEnabled = true; foreach (EffectPass pass in cCApplication.basicEffect.CurrentTechnique.Passes) { pass.Apply(); cCApplication.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineStrip, vector3, 0, segments); } }
/// <summary> /// @brief Get resource file data /// @param[in] pszFileName The resource file name which contain the path /// @param[in] pszMode The read mode of the file /// @param[out] pSize If get the file data succeed the it will be the data size,or it will be 0 /// @return if success,the pointer of data will be returned,or NULL is returned /// @warning If you get the file data succeed,you must delete it after used. /// </summary> /// <param name="pszFileName"></param> /// <param name="pszMode"></param> /// <param name="pSize"></param> /// <returns></returns> public static string getFileData(string pszFileName, string pszMode, UInt64 pSize) { ContentManager content = CCApplication.sharedApplication().content; CCContent data = content.Load <CCContent>(pszFileName); return(data.Content); }
public bool initWithWidthAndHeight(int w, int h, CCTexture2DPixelFormat eFormat) { if (CCConfiguration.sharedConfiguration().getGlesVersion() <= CCGlesVersion.GLES_VER_1_0) { return(false); } w = w * (int)CCDirector.sharedDirector().ContentScaleFactor; h = h * (int)CCDirector.sharedDirector().ContentScaleFactor; ccUtils.ccNextPOT((long)w); ccUtils.ccNextPOT((long)h); this.m_pTexture = new CCTexture2D(); CCApplication cCApplication = CCApplication.sharedApplication(); this.m_RenderTarget2D = new RenderTarget2D(cCApplication.GraphicsDevice, w, h); cCApplication.GraphicsDevice.SetRenderTarget(this.m_RenderTarget2D); cCApplication.GraphicsDevice.Clear(new Color(0, 0, 0, 0)); this.m_pTexture.initWithTexture(this.m_RenderTarget2D); this.m_pSprite = CCSprite.spriteWithTexture(this.m_pTexture); this.addChild(this.m_pSprite); ccBlendFunc _ccBlendFunc = new ccBlendFunc() { src = 1, dst = 771 }; this.m_pSprite.BlendFunc = _ccBlendFunc; return(true); }
public override void draw() { base.draw(); CCApplication app = CCApplication.sharedApplication(); CCSize size = CCDirector.sharedDirector().getWinSize(); app.basicEffect.VertexColorEnabled = true; app.basicEffect.TextureEnabled = false; app.basicEffect.Alpha = (float)this.m_cOpacity / 255.0f; VertexDeclaration vertexDeclaration = new VertexDeclaration(new VertexElement[] { new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), new VertexElement(12, VertexElementFormat.Vector4, VertexElementUsage.Color, 0) }); foreach (var pass in app.basicEffect.CurrentTechnique.Passes) { pass.Apply(); app.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>( PrimitiveType.TriangleStrip, vertices, 0, 2); } app.basicEffect.Alpha = 1; }
public override void draw() { base.draw(); if (this.m_pVertexData == null) { return; } if (this.m_pSprite == null) { return; } this.vertices = new VertexPositionColorTexture[(int)this.m_pVertexData.Length]; this.getIndexes(); for (int i = 0; i < (int)this.m_pVertexData.Length; i++) { ccV2F_C4B_T2F mPVertexData = this.m_pVertexData[i]; this.vertices[i] = new VertexPositionColorTexture(new Vector3(mPVertexData.vertices.x, mPVertexData.vertices.y, 0f), new Color((int)mPVertexData.colors.r, (int)mPVertexData.colors.g, (int)mPVertexData.colors.b, (int)mPVertexData.colors.a), new Vector2(mPVertexData.texCoords.u, mPVertexData.texCoords.v)); } CCApplication texture2D = CCApplication.sharedApplication(); texture2D.basicEffect.Texture = this.m_pSprite.Texture.getTexture2D(); texture2D.basicEffect.TextureEnabled = true; VertexElement[] vertexElement = new VertexElement[] { new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Color, 0), new VertexElement(24, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0) }; VertexDeclaration vertexDeclaration = new VertexDeclaration(vertexElement); foreach (EffectPass pass in texture2D.basicEffect.CurrentTechnique.Passes) { pass.Apply(); texture2D.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionColorTexture>(PrimitiveType.TriangleList, this.vertices, 0, this.m_nVertexDataCount, this.indexes, 0, this.m_nVertexDataCount - 2); } }
/// <summary> /// initializes a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid /// </summary> public bool initWithWidthAndHeight(int w, int h, CCTexture2DPixelFormat eFormat) { bool bRet = false; do { w *= (int)CCDirector.sharedDirector().ContentScaleFactor; h *= (int)CCDirector.sharedDirector().ContentScaleFactor; //glGetIntegerv(0x8CA6, m_nOldFBO); // textures must be power of two squared uint powW = (uint)ccUtils.ccNextPOT(w); uint powH = (uint)ccUtils.ccNextPOT(h); m_pTexture = new CCTexture2D(); CCApplication app = CCApplication.sharedApplication(); m_RenderTarget2D = new RenderTarget2D(app.GraphicsDevice, (int)w, (int)h); app.GraphicsDevice.SetRenderTarget(m_RenderTarget2D); app.GraphicsDevice.Clear(new Microsoft.Xna.Framework.Color(0, 0, 0, 0)); m_pTexture.initWithTexture(m_RenderTarget2D); // generate FBO //ccglGenFramebuffers(1, &m_uFBO); //ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_uFBO); // associate texture with FBO //ccglFramebufferTexture2D(CC_GL_FRAMEBUFFER, CC_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_pTexture->getName(), 0); // check if it worked (probably worth doing :) ) //GLuint status = ccglCheckFramebufferStatus(CC_GL_FRAMEBUFFER); //if (status != CC_GL_FRAMEBUFFER_COMPLETE) //{ // CCAssert(0, "Render Texture : Could not attach texture to framebuffer"); // CC_SAFE_DELETE(m_pTexture); // break; //} //m_pTexture.setAliasTexParameters(); m_pSprite = CCSprite.spriteWithTexture(m_pTexture); //m_pTexture->release(); //m_pSprite.scaleY = -1; this.addChild(m_pSprite); ccBlendFunc tBlendFunc = new ccBlendFunc { src = 1, dst = 0x0303 }; m_pSprite.BlendFunc = tBlendFunc; //ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_nOldFBO); bRet = true; } while (false); return(bRet); }
public override void draw() { base.draw(); BlendState blendState = CCApplication.sharedApplication().GraphicsDevice.BlendState; BlendState alphaBlend = BlendState.AlphaBlend; if (base.IsBlendAdditive) { alphaBlend = BlendState.Additive; } CCApplication.sharedApplication().spriteBatch.Begin(SpriteSortMode.Deferred, alphaBlend); for (int i = 0; i < base.ParticleCount; i++) { CCParticle particle = base.m_pParticles[i]; CCPoint obPoint = CCPointExtension.ccpAdd(CCAffineTransform.CCPointApplyAffineTransform(new CCPoint(), base.nodeToWorldTransform()), new CCPoint(this.m_pQuads[i].bl.vertices.x, this.m_pQuads[i].bl.vertices.y)); obPoint = CCDirector.sharedDirector().convertToUI(obPoint); Vector2 position = new Vector2(obPoint.x, obPoint.y); Color color = new Color(particle.color.r, particle.color.g, particle.color.b, particle.color.a); float scale = 1f; if (this.Texture.getTexture2D().Width > this.Texture.getTexture2D().Height) { scale = particle.size / ((float)this.Texture.getTexture2D().Height); } else { scale = particle.size / ((float)this.Texture.getTexture2D().Width); } float rotation = particle.rotation; Vector2 origin = new Vector2((float)(this.Texture.getTexture2D().Width / 2), (float)(this.Texture.getTexture2D().Height / 2)); Rectangle?sourceRectangle = null; CCApplication.sharedApplication().spriteBatch.Draw(this.Texture.getTexture2D(), position, sourceRectangle, color, rotation, origin, scale, SpriteEffects.None, 0f); } CCApplication.sharedApplication().spriteBatch.End(); CCApplication.sharedApplication().GraphicsDevice.BlendState = blendState; }
/// <summary> /// draws a quad bezier path /// @since v0.8 /// </summary> public static void ccDrawQuadBezier(CCPoint origin, CCPoint control, CCPoint destination, int segments, ccColor4F color) { VertexPositionColor[] vertices = new VertexPositionColor[segments + 1]; float factor = CCDirector.sharedDirector().ContentScaleFactor; CCApplication app = CCApplication.sharedApplication(); float t = 0.0f; for (int i = 0; i < segments; i++) { float x = (float)Math.Pow(1 - t, 2) * origin.x + 2.0f * (1 - t) * t * control.x + t * t * destination.x; float y = (float)Math.Pow(1 - t, 2) * origin.y + 2.0f * (1 - t) * t * control.y + t * t * destination.y; vertices[i] = new VertexPositionColor(); vertices[i].Position = new Vector3(x * factor, y * factor, 0); vertices[i].Color = new Color(color.r, color.g, color.b, color.a); t += 1.0f / segments; } vertices[segments] = new VertexPositionColor() { Position = new Vector3(destination.x * factor, destination.y * factor, 0), Color = new Color(color.r, color.g, color.b, color.a), }; app.basicEffect.TextureEnabled = false; app.basicEffect.VertexColorEnabled = true; foreach (var pass in app.basicEffect.CurrentTechnique.Passes) { pass.Apply(); app.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineStrip, vertices, 0, segments); } }
protected void setNextScene() { // If it is not a transition, call onExit/cleanup /*if (! newIsTransition)*/ if (!(m_pNextScene is CCTransitionScene)) { if (m_pRunningScene != null) { m_pRunningScene.onExit(); //CLEAR TOUCHES BEFORE LEAVING CCApplication.sharedApplication().ClearTouches(); } // issue #709. the root node (scene) should receive the cleanup message too // otherwise it might be leaked. if (m_bSendCleanupToScene && m_pRunningScene != null) { m_pRunningScene.cleanup(); } } m_pRunningScene = m_pNextScene; // m_pNextScene.retain(); m_pNextScene = null; if (m_pRunningScene != null) { m_pRunningScene.onEnter(); if (m_pRunningScene is CCTransitionScene) { m_pRunningScene.onEnterTransitionDidFinish(); } } }
public void grab(ref CCTexture2D pTexture) { // If the gles version is lower than GLES_VER_1_0, // all the functions in CCGrabber return directly. if (m_eGlesVersion <= CCGlesVersion.GLES_VER_1_0) { return; } //glGetIntegerv(CC_GL_FRAMEBUFFER_BINDING, &m_oldFBO); // bind //ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_fbo); m_RenderTarget2D = new RenderTarget2D(CCApplication.sharedApplication().GraphicsDevice, (int)pTexture.ContentSizeInPixels.width, (int)pTexture.ContentSizeInPixels.height); pTexture.Texture = m_RenderTarget2D; // associate texture with FBO //ccglFramebufferTexture2D(CC_GL_FRAMEBUFFER, CC_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, //pTexture->getName(), 0); // check if it worked (probably worth doing :) ) //GLuint status = ccglCheckFramebufferStatus(CC_GL_FRAMEBUFFER); //if (status != CC_GL_FRAMEBUFFER_COMPLETE) //{ // CCLOG("Frame Grabber: could not attach texture to frmaebuffer"); //} //ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_oldFBO); }
public void beforeRender(ref CCTexture2D pTexture) { // If the gles version is lower than GLES_VER_1_0, // all the functions in CCGrabber return directly. if (m_eGlesVersion <= CCGlesVersion.GLES_VER_1_0) { return; } CCApplication.sharedApplication().GraphicsDevice.SetRenderTarget(m_RenderTarget2D); //CCApplication.sharedApplication().GraphicsDevice.Clear(new Color(0, 0, 0, 0)); //CCApplication app = CCApplication.sharedApplication(); //Texture2D td = app.content.Load<Texture2D>("Images/blocks"); //app.spriteBatch.Begin(); //app.spriteBatch.Draw(td, new Rectangle(100, 100, 200, 200), Color.White); //app.spriteBatch.End(); //glGetIntegerv(CC_GL_FRAMEBUFFER_BINDING, &m_oldFBO); //ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_fbo); // BUG XXX: doesn't work with RGB565. /*glClearColor(0, 0, 0, 0);*/ // BUG #631: To fix #631, uncomment the lines with #631 // Warning: But it CCGrabber won't work with 2 effects at the same time //glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // #631 //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //glColorMask(true, true, true, false); // #631 }
public bool enableRetinaDisplay(bool enabled) { if (enabled && this.m_fContentScaleFactor == 2f) { return(true); } if (!enabled && this.m_fContentScaleFactor == 1f) { return(false); } if (!CCApplication.sharedApplication().canSetContentScaleFactor) { return(false); } float single = (float)((enabled ? 2 : 1)); CCApplication.sharedApplication().setContentScaleFactor(single); if (this.m_fContentScaleFactor != 2f) { this.m_bRetinaDisplay = false; } else { this.m_bRetinaDisplay = true; } return(true); }
public void transform() { CCApplication application = CCApplication.sharedApplication(); if (this.m_bIsTransformGLDirty) { TransformUtils.CGAffineToGL(this.nodeToParentTransform(), ref this.m_pTransformGL); this.m_bIsTransformGLDirty = false; } this.m_tCCNodeTransform = TransformUtils.CGAffineToMatrix(this.m_pTransformGL); if (this.m_fVertexZ > 0f) { this.m_tCCNodeTransform *= Matrix.CreateRotationZ(this.m_fVertexZ); } if ((this.m_pCamera != null) && ((this.m_pGrid == null) || !this.m_pGrid.Active)) { if (this.m_tAnchorPointInPixels.x == 0f) { float y = this.m_tAnchorPointInPixels.y; } Matrix?nullable = this.m_pCamera.locate(); if (nullable.HasValue) { this.m_tCCNodeTransform = ((Matrix.CreateTranslation(-this.m_tAnchorPointInPixels.x, -this.m_tAnchorPointInPixels.y, 0f) * nullable.Value) * Matrix.CreateTranslation(this.m_tAnchorPointInPixels.x, this.m_tAnchorPointInPixels.y, 0f)) * this.m_tCCNodeTransform; } } application.basicEffect.World = this.m_tCCNodeTransform * application.basicEffect.World; }
protected void setNextScene() { if (!(this.m_pNextScene is CCTransitionScene)) { if (this.m_pRunningScene != null) { this.m_pRunningScene.onExit(); CCApplication.sharedApplication().ClearTouches(); } if (this.m_bSendCleanupToScene && this.m_pRunningScene != null) { this.m_pRunningScene.cleanup(); } } this.m_pRunningScene = this.m_pNextScene; this.m_pNextScene = null; if (this.m_pRunningScene != null) { this.m_pRunningScene.onEnter(); if (this.m_pRunningScene is CCTransitionScene) { this.m_pRunningScene.onEnterTransitionDidFinish(); } } }
public override void blit() { int mSGridSize = this.m_sGridSize.x; int num = this.m_sGridSize.y; CCApplication texture2D = CCApplication.sharedApplication(); CCDirector.sharedDirector().getWinSize(); texture2D.basicEffect.Texture = this.m_pTexture.getTexture2D(); texture2D.basicEffect.TextureEnabled = true; texture2D.GraphicsDevice.BlendState = BlendState.AlphaBlend; texture2D.basicEffect.VertexColorEnabled = true; List <VertexPositionColorTexture> vertexPositionColorTextures = new List <VertexPositionColorTexture>(); for (int i = 0; i < (this.m_sGridSize.x + 1) * (this.m_sGridSize.y + 1); i++) { VertexPositionColorTexture vertexPositionColorTexture = new VertexPositionColorTexture() { Position = new Vector3(this.m_pVertices[i].x, this.m_pVertices[i].y, this.m_pVertices[i].z), TextureCoordinate = new Vector2(this.m_pTexCoordinates[i].x, this.m_pTexCoordinates[i].y), Color = Color.White }; vertexPositionColorTextures.Add(vertexPositionColorTexture); } short[] mPIndices = this.m_pIndices; foreach (EffectPass pass in texture2D.basicEffect.CurrentTechnique.Passes) { pass.Apply(); texture2D.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionColorTexture>(PrimitiveType.TriangleList, vertexPositionColorTextures.ToArray(), 0, vertexPositionColorTextures.Count, mPIndices, 0, (int)mPIndices.Length / 3); } }
/// <summary> /// starts grabbing /// </summary> public void begin() { // Save the current matrix //glPushMatrix(); CCSize texSize = m_pTexture.ContentSizeInPixels; // Calculate the adjustment ratios based on the old and new projections CCSize size = CCDirector.sharedDirector().displaySizeInPixels; float widthRatio = size.width / texSize.width; float heightRatio = size.height / texSize.height; CCApplication.sharedApplication().GraphicsDevice.SetRenderTarget(m_RenderTarget2D); // Adjust the orthographic propjection and viewport //ccglOrtho((float)-1.0 / widthRatio, (float)1.0 / widthRatio, (float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1,1); //glViewport(0, 0, (GLsizei)texSize.width, (GLsizei)texSize.height); // CCDirector::sharedDirector()->getOpenGLView()->setViewPortInPoints(0, 0, texSize.width, texSize.height); //glGetIntegerv(CC_GL_FRAMEBUFFER_BINDING, &m_nOldFBO); //ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_uFBO);//Will direct drawing to the frame buffer created above // Issue #1145 // There is no need to enable the default GL states here // but since CCRenderTexture is mostly used outside the "render" loop // these states needs to be enabled. // Since this bug was discovered in API-freeze (very close of 1.0 release) // This bug won't be fixed to prevent incompatibilities with code. // // If you understand the above mentioned message, then you can comment the following line // and enable the gl states manually, in case you need them. //CC_ENABLE_DEFAULT_GL_STATES(); }
/// <summary> /// draws n quads from an index (offset). /// n + start can't be greater than the capacity of the atlas /// @since v1.0 /// </summary> public void drawNumberOfQuads(int n, int start) { if (n == start) { return; } if (this.m_pQuads == null || this.m_pQuads.Length < 1) { return; } CCApplication app = CCApplication.sharedApplication(); CCSize size = CCDirector.sharedDirector().getWinSize(); //app.basicEffect.World = app.worldMatrix *TransformUtils.CGAffineToMatrix( this.nodeToWorldTransform()); app.basicEffect.Texture = this.Texture.getTexture2D(); app.basicEffect.TextureEnabled = true; app.GraphicsDevice.BlendState = BlendState.AlphaBlend; app.basicEffect.VertexColorEnabled = true; List <VertexPositionColorTexture> vertices = new List <VertexPositionColorTexture>(); short[] indexes = new short[n * 6]; for (int i = start; i < start + n; i++) { ccV3F_C4B_T2F_Quad quad = this.m_pQuads[i]; if (quad != null) { vertices.AddRange(quad.getVertices(ccDirectorProjection.CCDirectorProjection3D).ToList()); indexes[i * 6 + 0] = (short)(i * 4 + 0); indexes[i * 6 + 1] = (short)(i * 4 + 1); indexes[i * 6 + 2] = (short)(i * 4 + 2); // inverted index. issue #179 indexes[i * 6 + 3] = (short)(i * 4 + 2); indexes[i * 6 + 4] = (short)(i * 4 + 1); indexes[i * 6 + 5] = (short)(i * 4 + 3); } } VertexDeclaration vertexDeclaration = new VertexDeclaration(new VertexElement[] { new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Color, 0), new VertexElement(24, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0) }); foreach (var pass in app.basicEffect.CurrentTechnique.Passes) { pass.Apply(); app.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionColorTexture>( PrimitiveType.TriangleList, vertices.ToArray(), 0, vertices.Count, indexes, 0, vertices.Count / 2); } }
protected void updateContentScaleFactor() { if (CCApplication.sharedApplication().canSetContentScaleFactor) { CCApplication.sharedApplication().setContentScaleFactor(this.m_fContentScaleFactor); this.m_bIsContentScaleSupported = true; } }
public void beforeRender(ref CCTexture2D pTexture) { if (this.m_eGlesVersion <= CCGlesVersion.GLES_VER_1_0) { return; } CCApplication.sharedApplication().GraphicsDevice.SetRenderTarget(this.m_RenderTarget2D); }
/// <summary> /// changes the projection size /// </summary> /// <param name="newWindowSize"></param> public void reshapeProjection(CCSize newWindowSize) { // CC_UNUSED_PARAM(newWindowSize); m_obWinSizeInPoints = CCApplication.sharedApplication().getSize(); m_obWinSizeInPixels = new CCSize(m_obWinSizeInPoints.width * m_fContentScaleFactor, m_obWinSizeInPoints.height * m_fContentScaleFactor); Projection = m_eProjection; }
public void begin() { CCSize contentSizeInPixels = this.m_pTexture.ContentSizeInPixels; CCSize cCSize = CCDirector.sharedDirector().displaySizeInPixels; float single = cCSize.width / contentSizeInPixels.width; float single1 = cCSize.height / contentSizeInPixels.height; CCApplication.sharedApplication().GraphicsDevice.SetRenderTarget(this.m_RenderTarget2D); }
public void grab(ref CCTexture2D pTexture) { if (this.m_eGlesVersion <= CCGlesVersion.GLES_VER_1_0) { return; } this.m_RenderTarget2D = new RenderTarget2D(CCApplication.sharedApplication().GraphicsDevice, (int)pTexture.ContentSizeInPixels.width, (int)pTexture.ContentSizeInPixels.height); pTexture.Texture = this.m_RenderTarget2D; }
public void afterRender(ref CCTexture2D pTexture) { if (this.m_eGlesVersion <= CCGlesVersion.GLES_VER_1_0) { return; } CCApplication.sharedApplication().GraphicsDevice.SetRenderTarget(null); pTexture.Texture = this.m_RenderTarget2D; }
public override void visit() { if (base.m_bIsVisible) { base.transform(); this.draw(); CCApplication.sharedApplication().basicEffect.World *= Matrix.Invert(base.m_tCCNodeTransform); base.m_tCCNodeTransform = Matrix.Identity; } }
public virtual void visit() { Matrix world = CCApplication.sharedApplication().basicEffect.World; if (this.m_bIsVisible) { CCNode node; this.m_tCCNodeTransform = Matrix.Identity; Matrix matrix2 = Matrix.Identity * CCApplication.sharedApplication().basicEffect.View; if ((this.m_pGrid != null) && this.m_pGrid.Active) { this.m_pGrid.beforeDraw(); this.transformAncestors(); } this.transform(); int num = 0; if ((this.m_pChildren != null) && (this.m_pChildren.Count > 0)) { while (num < this.m_pChildren.Count) { node = this.m_pChildren[num]; if ((node == null) || (node.m_nZOrder >= 0)) { break; } Matrix matrix3 = CCApplication.sharedApplication().basicEffect.World; node.visit(); CCApplication.sharedApplication().basicEffect.World = matrix3; num++; } } this.draw(); if ((this.m_pChildren != null) && (this.m_pChildren.Count > 0)) { while (num < this.m_pChildren.Count) { node = this.m_pChildren[num]; if (node != null) { Matrix matrix4 = CCApplication.sharedApplication().basicEffect.World; node.visit(); CCApplication.sharedApplication().basicEffect.World = matrix4; } num++; } } if ((this.m_pGrid != null) && this.m_pGrid.Active) { this.m_pGrid.afterDraw(this); } CCApplication.sharedApplication().basicEffect.World = world; CCApplication.sharedApplication().basicEffect.View = matrix2; CCApplication.sharedApplication().viewMatrix = matrix2; } }
public void end() { CCApplication.sharedApplication().GraphicsDevice.SetRenderTarget(null); //this.m_pTexture.initWithTexture(this.m_RenderTarget2D); //m_pSprite = CCSprite.spriteWithTexture(m_pTexture); //this.addChild(m_pSprite); //ccBlendFunc tBlendFunc = new ccBlendFunc { src = 1, dst = 0x0303 }; //m_pSprite.BlendFunc = tBlendFunc; }
public override void blit() { int mSGridSize = this.m_sGridSize.x * this.m_sGridSize.y; CCApplication texture2D = CCApplication.sharedApplication(); CCDirector.sharedDirector().getWinSize(); texture2D.basicEffect.Texture = this.m_pTexture.getTexture2D(); texture2D.basicEffect.TextureEnabled = true; texture2D.GraphicsDevice.BlendState = BlendState.AlphaBlend; texture2D.basicEffect.VertexColorEnabled = true; List <VertexPositionColorTexture> vertexPositionColorTextures = new List <VertexPositionColorTexture>(); for (int i = 0; i < mSGridSize; i++) { ccQuad3 mPVertices = this.m_pVertices[i]; ccQuad2 mPTexCoordinates = this.m_pTexCoordinates[i]; if (mPVertices != null) { VertexPositionColorTexture vertexPositionColorTexture = new VertexPositionColorTexture() { Position = new Vector3(mPVertices.bl.x, mPVertices.bl.y, mPVertices.bl.z), Color = Color.White, TextureCoordinate = new Vector2(mPTexCoordinates.bl.x, mPTexCoordinates.bl.y) }; vertexPositionColorTextures.Add(vertexPositionColorTexture); vertexPositionColorTexture = new VertexPositionColorTexture() { Position = new Vector3(mPVertices.br.x, mPVertices.br.y, mPVertices.br.z), Color = Color.White, TextureCoordinate = new Vector2(mPTexCoordinates.br.x, mPTexCoordinates.br.y) }; vertexPositionColorTextures.Add(vertexPositionColorTexture); vertexPositionColorTexture = new VertexPositionColorTexture() { Position = new Vector3(mPVertices.tl.x, mPVertices.tl.y, mPVertices.tl.z), Color = Color.White, TextureCoordinate = new Vector2(mPTexCoordinates.tl.x, mPTexCoordinates.tl.y) }; vertexPositionColorTextures.Add(vertexPositionColorTexture); vertexPositionColorTexture = new VertexPositionColorTexture() { Position = new Vector3(mPVertices.tr.x, mPVertices.tr.y, mPVertices.tr.z), Color = Color.White, TextureCoordinate = new Vector2(mPTexCoordinates.tr.x, mPTexCoordinates.tr.y) }; vertexPositionColorTextures.Add(vertexPositionColorTexture); } } foreach (EffectPass pass in texture2D.basicEffect.CurrentTechnique.Passes) { pass.Apply(); texture2D.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionColorTexture>(PrimitiveType.TriangleList, vertexPositionColorTextures.ToArray(), 0, vertexPositionColorTextures.Count, this.m_pIndices, 0, (int)this.m_pIndices.Length / 3); } }
public override void blit() { int n = m_sGridSize.x * m_sGridSize.y; //////// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY //////// Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY //////// Unneeded states: GL_COLOR_ARRAY //////glDisableClientState(GL_COLOR_ARRAY); //////glVertexPointer(3, GL_FLOAT, 0, m_pVertices); //////glTexCoordPointer(2, GL_FLOAT, 0, m_pTexCoordinates); //////glDrawElements(GL_TRIANGLES, (GLsizei)n * 6, GL_UNSIGNED_SHORT, m_pIndices); //////// restore GL default state //////glEnableClientState(GL_COLOR_ARRAY); CCApplication app = CCApplication.sharedApplication(); CCSize size = CCDirector.sharedDirector().getWinSize(); //app.basicEffect.World = app.worldMatrix * TransformUtils.CGAffineToMatrix(this.nodeToWorldTransform()); app.basicEffect.Texture = this.m_pTexture.getTexture2D(); app.basicEffect.TextureEnabled = true; app.GraphicsDevice.BlendState = BlendState.AlphaBlend; app.basicEffect.VertexColorEnabled = true; //RasterizerState rs = new RasterizerState(); //rs.CullMode = CullMode.None; //app.GraphicsDevice.RasterizerState = rs; List <VertexPositionColorTexture> vertices = new List <VertexPositionColorTexture>(); for (int i = 0; i < (m_sGridSize.x + 1) * (m_sGridSize.y + 1); i++) { VertexPositionColorTexture vct = new VertexPositionColorTexture(); vct.Position = new Vector3(m_pVertices[i].x, m_pVertices[i].y, m_pVertices[i].z); vct.TextureCoordinate = new Vector2(m_pTexCoordinates[i].x, m_pTexCoordinates[i].y); vct.Color = Color.White; vertices.Add(vct); } short[] indexes = m_pIndices; foreach (var pass in app.basicEffect.CurrentTechnique.Passes) { pass.Apply(); app.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionColorTexture>( PrimitiveType.TriangleList, vertices.ToArray(), 0, vertices.Count, indexes, 0, indexes.Length / 3); } }
protected bool m_bPurgeDirecotorInNextLoop; // this flag will be set to true in end() protected void updateContentScaleFactor() { // [openGLView responseToSelector:@selector(setContentScaleFactor)] if (CCApplication.sharedApplication().canSetContentScaleFactor) { CCApplication.sharedApplication().setContentScaleFactor(m_fContentScaleFactor); m_bIsContentScaleSupported = true; } else { //CCLOG("cocos2d: setContentScaleFactor:'is not supported on this device"); } }