Tag: opengl es

撤消绘画应用程序中的绘图

我正在使用OpenGl框架进行绘制应用程序,我被卡在UNDO / REDO选项..我实现的代码是这样的: -(void)undo_called { artbrushAppDelegate *app=(artbrushAppDelegate *)[[UIApplication sharedApplication]delegate]; mbrushscale=app.brushscale; brushimage=app.brush_image; Erase=YES; [self playRayundo]; } -(void)playRayundo { artbrushAppDelegate *app=(artbrushAppDelegate *)[[UIApplication sharedApplication]delegate]; glColor4f(app.r1g, app.b1g, app.g1g, 0); NSLog(@"%f",app.r1g); if(undo != NULL) { for(int l = 0; l < [undo count]; l++) { //replays my writRay -1 because of location point for(int p = 0; p < [[undo […]

在GLKViewController中使用glTexImage2D的EXC_BAD_ACCESS

我在这段代码的最后一行有一个EXC_BAD_ACCESS (这段代码每秒被触发几次),但我不知道是什么问题: [EAGLContext setCurrentContext:_context]; glActiveTexture(GL_TEXTURE0); glPixelStorei(GL_PACK_ALIGNMENT, 1); glBindTexture(GL_TEXTURE_2D, _backgroundTexture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _outputFrame.cols, _outputFrame.rows, 0, GL_BGRA, GL_UNSIGNED_BYTE, _outputFrame.data); 当debugging时,我确定纹理被创build(id是> 0),输出帧有一个指向数据的有效指针,是一个4通道matrix。 我在GLKViewController的drawRect方法中。 我想我不应该绑定帧缓冲器,因为它是这里自动化的东西之一。 它在第一帧没有崩溃,但在几十帧之后。 有人可以发现问题吗? 更新: 看起来是因为_outputFrame上的竞争条件,它正在被glTexImage2D读取的同时被更新。 我会尝试locking它的阅读,然后报告。

使用GPUImage在OpenGL ES着色器中使用bool返回types

我正在使用GPUImage框架在iOS项目上工作。 我无法让我的着色器编译。 在我的片段着色器中有一个函数: const vec2 boundMin = vec2(0.0, 0.0); const vec2 boundMax = vec2(1.0, 1.0); bool inBounds (vec2 p) { return all(lessThan(boundMin, p)) && all(lessThan(p, boundMax)); } 着色器编译日志: ERROR: 0:1: '_Bool' : syntax error syntax error 当我replace所有的function inBounds(vec2 p) 同 all(lessThan(boundMin, p)) && all(lessThan(p, boundMax)) 它很好用! 问题: OpenGL ES 2.0 Fragment Shader是否支持boolfunction? 如果是这样,我哪里错了? 如果没有,为什么有像all() , […]

NSString drawInRect:并在iOS上放置阴影

我正在使用[NSString drawInRect:]绘制文本到纹理,一切正常,直到我添加阴影。 它们看起来是正确的,但是经常被我正在绘制的矩形裁剪。 问题是[NSString sizeWithFont:]不知道下拉阴影,因为它们是通过CGContextSetShadowWithColor(…) 。 这里是我使用的代码(去除绒毛): CGSize dim = [theString sizeWithFont:uifont]; … CGContextSetRGBFillColor(context, 1.0f, 1.0f, 1.0f, 1.0f); CGContextTranslateCTM(context, 0.0f, dim.height); CGContextScaleCTM(context, 1.0f, -1.0f); CGContextSetShadowWithColor(context, CGSizeMake(dropOffset.x, dropOffset.y), dropBlur, dropColorRef); … [theString drawInRect:dim withFont:uifont lineBreakMode:UILineBreakModeWordWrap alignment:align]; 我已经尝试了扩展dim ,把阴影和模糊考虑在内,这主要是工作,但有时扩展矩形导致线被完全不同,由于额外的空间被添加。 有没有更好的方法来find绘制(或绘制string)所需的纹理/矩形的大小比我使用?

如何在OpenGLES中的球运动中画一条线?

目前我在iphone上使用OpenGLES进行球类游戏的应用,使用GL_TRIANGLE_STRIP从左到右画球和移动动作,然后GL_LINES画出一条线,但是画线内部不能画球运动,怎么解决呢? 我试过的示例代码: #1 – (void)update { self.timeSinceLastSpawn += self.timeSinceLastUpdate; self.timeSinceLastSpawn = 0; if (self.timeSinceLastSpawn > 2.0) { [self target]; // Call the Method target } for (SGGSprite * sprite in self.children) //SGGSprite is a class { [sprite update:self.timeSinceLastUpdate]; // call the update method in SGGSprite class. } } #2 – (void)update:(float)dt { GLKVector2 curMove = […]

如何更改CCTexture2D颜色

我有一个使用纹理和glDrawArray填充的多边形(使用本教程中描述的方法: http : //www.raywenderlich.com/32954/how-to-create-a-game-like-tiny-wings-with -cocos2d-2-x-part-1 )。 我希望能够使用在游戏中随机生成的纯色填充我的多边形。 要使用本教程中的技巧来做到这一点,我需要dynamic地创build一个纯色的纹理(例如,我可能想要生成一个1×1的红色正方形,并用它来填充我的多边形)。 有没有办法改变cocos2d纹理的颜色,类似于你将如何使用[mySprite changeColor:ccRed]来改变一个精灵的颜色? 所以,如果我有我的初始纹理,说一个1×1的白色正方形,有没有办法我可以改变这个纹理到一个1×1的红色正方形? 我已经尝试使用CCRenderTexture(如本教程中所述: http ://www.raywenderlich.com/33266/how-to-create-dynamic-textures-with-ccrendertexture-in-cocos2d-2-x),但是,作为我将填充许多多边形,这种方法certificate是相当缓慢的。 我也尝试使用下面的代码来创build我的纹理: // fill with solid red GLubyte buffer[3] = {255, 0, 0}; CCTexture2D *texture = [[CCTexture2D alloc] initWithData:buffer pixelFormat:kCCTexture2DPixelFormat_RGB888 pixelsWide:1 pixelsHigh:1 contentSize:m]; 虽然上面的工作相当不错,但它比从CCSprite抓取纹理还要慢。 基本上,我正在寻找一种尽可能高效地生成dynamic纹理的方法。 这里是我用来填充我的多边形的代码: GLubyte buffer[3] = {arc4random()%256,arc4random()%256,arc4random()%256}; CGSize size; size.width = 2; size.height = 2; CCTexture2D *texture = [[CCTexture2D […]

在iOS 5.1的股票OpenGL ES应用程序,他们真的在使用他们声明的顶点数组吗?

在股票OpenGL ES应用程序中(当您在XCode中创build一个新的“OpenGL游戏”时),在setupGL函数中,有: glEnable(GL_DEPTH_TEST); //glGenVertexArraysOES( 1, &_vertexArray ) ; // va's are not being used! //glBindVertexArrayOES( _vertexArray ) ; // we comment these out // to no ill effect — are these calls extraneous? glGenBuffers( 1, &_vertexBuffer ) ; glBindBuffer( GL_ARRAY_BUFFER, _vertexBuffer ) ; glBufferData( GL_ARRAY_BUFFER, sizeof(gCubeVertexData), gCubeVertexData, GL_STATIC_DRAW ) ; glEnableVertexAttribArray(GLKVertexAttribPosition); glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, […]

iOS 7和OpenGL问题/崩溃

我正在开发iPad应用程序,自从iOS 7更新以来,我们看到iPad上的随机挂起。 我有点新的XCodedebugging。 从我所知道的,主线程被阻塞,等待某件事完成,但是我不知道那是什么。 这是线程转储: * thread #1: tid = 0x260c, 0x384f4554 libsystem_kernel.dylib`__semwait_signal + 28, queue = 'com.apple.main-thread, stop reason = instruction step over frame #0: 0x384f4554 libsystem_kernel.dylib`__semwait_signal + 28 frame #1: 0x3846580c libsystem_c.dylib`nanosleep + 172 frame #2: 0x3846575a libsystem_c.dylib`usleep + 50 frame #3: 0x2fd28b9e QuartzCore`native_window_begin_iosurface(_EAGLNativeWindowObject*) + 1062 frame #4: 0x2fa25d42 GLEngine`gliGetNewIOSurfaceES + 54 frame […]

用平移手势上下左右旋转相机

我想使用opengl lookat函数向上或向下,向左或向右旋转摄像头(360度视图),使用opengl lookat函数,我使用swift和Metal(在本例中为Metal = opengl es)。 这里是代码: lookat函数(这个函数在另一个ViewController中,它是inheritance了ViewController的主要ViewController和pan手势函数): let viewMatrix = lookAt(location, center: ktarget, up: up) viewDidLoad和var: var ktarget = V3f() var up = V3f() let location =V3f() override func viewDidLoad() { super.viewDidLoad() location = V3f(0.0, 0.0, -2.0) ktarget = V3f(0.0, 0.0, 0.0) up = V3f(0.0, 1.0, 0.0) } 平底锅手势: func pan(panGesture: UIPanGestureRecognizer){ up = […]

GPUImage着色器与“错误:一个或多个附加着色器未成功编译”

我想基于这个Javascript为GPUImage构build一个Vibrancefilter: /** * @filter Vibrance * @description Modifies the saturation of desaturated colors, leaving saturated colors unmodified. * @param amount -1 to 1 (-1 is minimum vibrance, 0 is no change, and 1 is maximum vibrance) */ function vibrance(amount) { gl.vibrance = gl.vibrance || new Shader(null, '\ uniform sampler2D texture;\ uniform float amount;\ varying vec2 […]