大佬教程收集整理的这篇文章主要介绍了ios – iPad纹理加载差异(32位与64位),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这是32位iPad上绘制的纹理:
这是64位iPad上绘制的纹理:
64位是我想要的,但似乎也许是丢失一些数据?
UIGraphicsBeginImageContext(CGSizeMake(64,64)); CGContextRef defBrushTextureContext = UIGraphicsGetCurrentContext(); UIGraphicsPushContext(defBrushTextureContext); size_t num_LOCATIOns = 3; CGFloat LOCATIOns[3] = { 0.0,0.8,1.0 }; CGFloat components[12] = { 1.0,1.0,0.0 }; CGColorSpaceRef myColorspace = CGColorSpaceCreateDeviceRGB(); CGGradientRef myGradient = CGGradientCreateWithColorComponents (myColorspace,components,LOCATIOns,num_LOCATIOns); CGPoint myCentrePoint = CGPointMake(32,32); float myRadius = 20; CGGradientDrawingOptions options = kCGGradientDrawsBeforeStartLOCATIOn | kCGGradientDrawsAfterEndLOCATIOn; CGContextDrawRadialGradient (UIGraphicsGetCurrentContext(),myGradient,myCentrePoint,myRadius,options); CFRelease(myGradient); CFRelease(myColorspacE); UIGraphicsPopContext(); [self setBrushTexture:UIGraphicsGetImageFromCurrentImageContext()]; UIGraphicsEndImageContext();
然后实际上设置这样的画笔纹理:
-(void) setBrushTexture:(UIImage*)brushImage{ // save our current texture. currentTexture = brushImage; // first,delete the old texture if needed if (brushTexturE){ gldeleteTextures(1,&brushTexturE); brushTexture = 0; } // fetch the cgimage for us to draw into a texture CGImageRef brushCGImage = brushImage.CGImage; // Make sure the image exists if(brushCGImagE) { // Get the width and height of the image GLint width = CGImageGetWidth(brushCGImagE); GLint height = CGImageGetHeight(brushCGImagE); // Texture dimensions must be a power of 2. If you write an application that allows users to supply an image,// you'll want to add code that checks the dimensions and takes appropriate action if they are not a power of 2. // Allocate memory needed for the bitmap context GLubyte* brushData = (GLubyte *) calloc(width * height * 4,sizeof(GLubytE)); // Use the bitmatp creation function provided by the Core Graphics framework. CGContextRef brushContext = CGBitmapContextCreate(brushData,width,height,8,width * 4,CGImageGetColorSpace(brushCGImagE),kCGImageAlphaPremultipliedLast); // After you create the context,you can draw the image to the context. CGContextDrawImage(brushContext,CGRectMake(0.0,0.0,(CGFloat)width,(CGFloat)height),brushCGImagE); // You don't need the context at this point,so you need to release it to avoid memory leaks. CGContextRelease(brushContext); // Use OpenGL ES to generate a name for the texture. glGentextures(1,&brushTexturE); // Bind the texture name. glBindTexture(GL_TEXTURE_2D,brushTexturE); // Set the texture parameters to use a minifying filter and a linear filer (weighted averagE) glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Specify a 2D texture image,providing the a pointer to the image data in memory glTexImage2D(GL_TEXTURE_2D,GL_RGBA,GL_UNSIGNED_BYTE,brushData); // Release the image data; it's no longer needed free(brushData); } }
更新:
我已经将CGFloats更新为GLfloats,没有成功.也许这个渲染代码有问题吗?
if(frameBuffer){ // draw the stroke element [self prepOpenGLStateForFBO:frameBuffer]; [self prepOpenGLBlendModeForColor:element.color]; checkGLError(); } // find our screen scale so that we can convert from // points to pixels GLfloat scale = self.contentScaleFactor; // fetch the vertex data from the element struct Vertex* vertexBuffer = [element generatedVertexArrayWithPrevIoUSELER_169_11845@ent:prevIoUSELER_169_11845@ent forScale:scale]; glLineWidth(2); // if the element has any data,then draw it if(vertexBuffer){ glVertexPointer(2,GL_FLOAT,sizeof(struct VerteX),&vertexBuffer[0].Position[0]); glColorPointer(4,&vertexBuffer[0].Color[0]); glTexCoordPointer(2,&vertexBuffer[0].Texture[0]); glDrawArrays(GL_TRIANGLES,(GLint)[element numberOfSteps] * (GLint)[element numberOfVerticesPerStep]); checkGLError(); } if(frameBuffer){ [self unprepOpenGLState]; }
顶点结构如下:
struct Vertex{ GLfloat Position[2]; // x,y position GLfloat Color [4]; // rgba color GLfloat Texture[2]; // x,y texture coord };
更新:
这个问题实际上并不是32位,64位,而是与A7 GPU和GL驱动程序不同.我发现这是通过在64位iPad上运行32位构建和64位构建.纹理最终在应用程序的两个构建上看起来完全相同.
>在OpenGL中检查Alpha混合逻辑(或选项).
检查与拖动速度成比例的插值逻辑.
似乎你没有第二个或没有效果,这是绘制应用程序所必需的
以上是大佬教程为你收集整理的ios – iPad纹理加载差异(32位与64位)全部内容,希望文章能够帮你解决ios – iPad纹理加载差异(32位与64位)所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。