何が悪いのですか?私はOpenGLとObjective-Cを学ぼうとしています。コードをCからObjective-Cに移植しています。
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <GL/glew.h>
#include <GL/freeglut.h>
#define WINDOW_TITLE_PREFIX "Chapter 1"
int CurrentWidth = 800,
CurrentHeight = 600,
WindowHandle = 0;
void Initialize(int, char*[]);
void InitWindow(int, char*[]);
void ResizeFunction(int, int);
void RenderFunction(void);
int main(int argc, char* argv[])
{
Initialize(argc, argv);
glutMainLoop();
exit(EXIT_SUCCESS);
}
void Initialize(int argc, char* argv[])
{
InitWindow(argc, argv);
fprintf(
stdout,
"INFO: OpenGL Version: %s\n",
glGetString(GL_VERSION)
);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}
void InitWindow(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitContextVersion(4, 0);
glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
glutInitContextProfile(GLUT_CORE_PROFILE);
glutSetOption(
GLUT_ACTION_ON_WINDOW_CLOSE,
GLUT_ACTION_GLUTMAINLOOP_RETURNS
);
glutInitWindowSize(CurrentWidth, CurrentHeight);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
WindowHandle = glutCreateWindow(WINDOW_TITLE_PREFIX);
if(WindowHandle < 1) {
fprintf(
stderr,
"ERROR: Could not create a new rendering window.\n"
);
exit(EXIT_FAILURE);
}
glutReshapeFunc(ResizeFunction);
glutDisplayFunc(RenderFunction);
}
void ResizeFunction(int Width, int Height)
{
CurrentWidth = Width;
CurrentHeight = Height;
glViewport(0, 0, CurrentWidth, CurrentHeight);
}
void RenderFunction(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
glutPostRedisplay();
}
このコードは http://openglbook.com/the-book/chapter-1-getting-started/から入手しました
私はこれを行いましたが、問題がポインタにあると思うエラーが何であるかはよくわかりません。
header.h
#import <Foundation/Foundation.h>
#import <stdio.h>
#import <string.h>
#import <GL/glew.h>
#import <GL/freeglut.h>
#define WINDOW_TITLE_PREFIX "test gl objective c"
@interface princ : NSObject {
int CurrentWidth;
int CurrentHeight;
int WindowHandle;
}
-(void)InitValues;
-(void)ResizeFunction;
-(void)RenderFunction;
-(void)InitWindow: (int)argc: (char*[])argv:(void*)FoundRZ:(void*)FoundRD;
-(void)Initialize: (int)argc: (char*[])argv;
@end
@implementation princ
-(void)InitValues {
CurrentWidth = 800;
CurrentHeight = 600;
WindowHandle = 0;
}
-(void)ResizeFunction {
int Width = 0;
int Height = 0;
CurrentWidth = Width;
CurrentHeight = Height;
glViewport(0, 0, CurrentWidth, CurrentHeight);
}
-(void)RenderFunction {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
glutPostRedisplay();
}
-(void)InitWindow: (int)argc: (char*[])argv:(void*)FoundRZ:(void*)FoundRD {
glutInit(&argc, argv);
glutInitContextVersion(4, 0);
glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
glutInitContextProfile(GLUT_CORE_PROFILE);
glutSetOption (
GLUT_ACTION_ON_WINDOW_CLOSE,
GLUT_ACTION_GLUTMAINLOOP_RETURNS
);
glutInitWindowSize(CurrentWidth, CurrentHeight);
WindowHandle = glutCreateWindow(WINDOW_TITLE_PREFIX);
if(WindowHandle < 1) {
fprintf(
stderr, "ERROR: Could not create a new rendering window.\n"
);
exit(EXIT_FAILURE);
}
glutReshapeFunc(FoundRZ);
glutDisplayFunc(FoundRD);
}
-(void)Initialize: (int)argc: (char*[])argv {
fprintf(stdout, "INFO: OpenGL Version: %s\n", glGetString(GL_VERSION));
}
@end
1.m
#import "header.h"
int main (int argc, char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(@"hello");
princ *GLMAIN = [[princ alloc] init];
[GLMAIN InitValues];
[GLMAIN InitWindow:argc:argv:[GLMAIN ResizeFunction]:[GLMAIN RenderFunction]];
[GLMAIN Initialize:argc:argv];
[pool drain];
return 0;
}
エラー :
$ clang -ObjC 1.m -o 1 `gnustep-config --objc-flags` -I/usr/local/lib/gcc42/gcc/x86_64-portbld-freebsd9.0/4.2.5/include -fconstant-string-class=NSConstantString -I/usr/local/GNUstep/System/Library/Headers -L/usr/local/GNUstep/System/Library/Libraries -L/usr/local/lib -lgnustep-base -I/usr/local/include -L/usr/local/lib -lglut -lGL
1.m:12:31: error: sending 'void' to parameter of incompatible type 'void *';
[GLMAIN InitWindow:argc:argv:[GLMAIN ResizeFunction]:[GLMAIN RenderFunction]];
^~~~~~~~~~~~~~~~~~~~~~~
./header.h:18:52: note: passing argument to parameter 'FoundRZ' here
-(void)InitWindow: (int)argc: (char*[])argv:(void*)FoundRZ:(void*)FoundRD;
^
1.m:12:55: error: sending 'void' to parameter of incompatible type 'void *';
[GLMAIN InitWindow:argc:argv:[GLMAIN ResizeFunction]:[GLMAIN RenderFunction]];
^~~~~~~~~~~~~~~~~~~~~~~
./header.h:18:67: note: passing argument to parameter 'FoundRD' here
-(void)InitWindow: (int)argc: (char*[])argv:(void*)FoundRZ:(void*)FoundRD;
^
2 errors generated.
私はMacを使用していません。FreeBSDを使用していますが、アップルの開発者なら誰でもこの小さな問題を解決できることを願っています。