在xcode 6.3.2中,我得到了在替换之后运行的示例
(ID)initWithFrame:方法(的NSRect)帧
同
(空隙)awakeFromNib
和更换
self = [super initWithFrame:frame pixelFormat:pixelFormat];
同
super.pixelFormat =像素格式;
和删除
回归自我;
或详细写出:
#import "MyOpenGLVIEw.h"@implementation MyOpenGLVIEw- (voID)awakeFromNib{ NSLog(@"...was here"); // 1. Create a context with opengl pixel format NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = { NSOpenGLPFAOpenGLProfile,NSOpenGLProfiLeversion3_2Core,NSOpenGLPFAcolorSize,24,NSOpenGLPFAAlphaSize,8,NSOpenGLPFADoubleBuffer,NSOpenGLPFAAccelerated,NSOpenGLPFAnorecovery,0 }; NSOpenGLPixelFormat *pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes]; super.pixelFormat=pixelFormat; // 2. Make the context current [[self openGLContext] makeCurrentContext]; // 3. define and compile vertex and fragment shaders gluint vs; gluint fs; const char *vss="#version 150\n\ uniform vec2 p;\ in vec4 position;\ in vec4 colour;\ out vec4 colourV;\ voID main (voID)\ {\ colourV = colour;\ gl_position = vec4(p,0.0,0.0) + position;\ }"; const char *fss="#version 150\n\ in vec4 colourV;\ out vec4 fragColour;\ voID main(voID)\ {\ fragColour = colourV;\ }"; vs = glCreateShader(GL_VERTEX_SHADER); glShaderSource(vs,1,&vss,NulL); glCompileShader(vs); fs = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fs,&fss,NulL); glCompileShader(fs); printf("vs: %i,fs: %i\n",vs,fs); // 4. Attach the shaders shaderProgram = glCreateProgram(); glAttachShader(shaderProgram,vs); glAttachShader(shaderProgram,fs); glBindFragDataLocation(shaderProgram,"fragColour"); gllinkProgram(shaderProgram); // 5. Get pointers to uniforms and attributes positionUniform = glGetUniformlocation(shaderProgram,"p"); colourAttribute = glGetAttribLocation(shaderProgram,"colour"); positionAttribute = glGetAttribLocation(shaderProgram,"position"); glDeleteShader(vs); glDeleteShader(fs); printf("positionUniform: %i,colourAttribute: %i,positionAttribute: %i\n",positionUniform,colourAttribute,positionAttribute); // 6. Upload vertices (1st four values in a row) and colours (following four values) GLfloat vertexData[]= { -0.5,-0.5,1.0,0.5,1.0}; glGenVertexArrays(1,&vertexArrayObject); glBindVertexArray(vertexArrayObject); glGenBuffers(1,&vertexBuffer); glBindBuffer(GL_ARRAY_BUFFER,vertexBuffer); glBufferData(GL_ARRAY_BUFFER,4*8*sizeof(GLfloat),vertexData,GL_STATIC_DRAW); glEnabLevertexAttribarray((gluint)positionAttribute); glEnabLevertexAttribarray((gluint)colourAttribute ); glVertexAttribPointer((gluint)positionAttribute,4,GL_float,GL_FALSE,8*sizeof(GLfloat),0); glVertexAttribPointer((gluint)colourAttribute,(char*)0+4*sizeof(GLfloat));}- (voID)drawRect:(NSRect)dirtyRect { [super drawRect:dirtyRect]; // Drawing code here. glClearcolor(0.0,1.0); glClear(GL_color_BUFFER_BIT); gluseProgram(shaderProgram); GLfloat p[]={0,0}; gluniform2fv(positionUniform,(const GLfloat *)&p); glDrawArrays(GL_TRIANGLE_FAN,4); [[self openGLContext] flushBuffer];}@end总结
以上是内存溢出为你收集整理的最简单,简约的opengl 3.2可可项目全部内容,希望文章能够帮你解决最简单,简约的opengl 3.2可可项目所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)