我目前正在处理读取3D obj文件的软件的打印循环。
我已将我的obj文件存储在变量tie
中。该变量包含OpenGL列表。我的目标是能够使用键盘移动读取对象。键盘读取正确实现(我可以通过日志看到)。
当我编译以下代码循环时,gluLookAt
正确执行,我可以通过更改参数的值来移动我的对象。
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
light();
gluPerspective (60.0, 250/(float)250, 0.1, 500.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(eyeX,eyeY,eyeZ,eyeX+directionX,eyeY+directionY,eyeZ+directionZ,upX,upY,upZ);
glPushMatrix();
glRotated(45,0,0,1);
glTranslated(0,0,50);
glBindTexture(GL_TEXTURE_2D,texture1);
//glCallList(xwing); //ICI
glEnd();
glPopMatrix();
glColor3d(1,1,1);
glDisable(GL_LIGHTING);
glBindTexture(GL_TEXTURE_2D,texture2);
GLUquadric* params = gluNewQuadric();
gluQuadricDrawStyle(params,GLU_FILL);
gluQuadricTexture(params,GL_TRUE);
gluSphere(params,100,20,20);
gluDeleteQuadric(params);
glEnable(GL_LIGHTING);
glBindTexture(GL_TEXTURE_2D,texture1);
glCallList(tie); //ICI
glPointSize(5.0);
glBegin(GL_POINTS);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(-1.0f,0.0f,0.0f);
glEnd();
SwapBuffers(hDC);
//} //else
Sleep(1);
但是当我评论这4行时:
glBegin(GL_POINTS);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(-1.0f,0.0f,0.0f);
glEnd();
我的物体不再移动了。好像gluLookAt
没有成功执行。
你知道为什么会这样吗?我忘记了代码中的某些内容吗?
答案 0 :(得分:1)
glBegin
和glEnd
分界定义基元或一组类似基元的顶点。您必须确保每个glBegin
后跟一个glEnd
这意味着,如果您的Display Lists包含glBegin
,那么它也应包含glEnd
。我强烈建议这样做。另一种可能性是在glCallList之后手动完成:
09-23 15:24:45.981 10438-10438/com.thewell.thewell_dev.companylink E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.thewell.thewell_dev.companylink, PID: 10438
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.thewell.thewell_dev.companylink/com.thewell.thewell_dev.fourslink.Activity.SplashActivity}: java.lang.ClassNotFoundException: Didn't find class "com.thewell.thewell_dev.fourslink.Activity.SplashActivity" on path: DexPathList[[zip file "/data/app/com.thewell.thewell_dev.companylink-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.thewell.thewell_dev.companylink-1, /vendor/lib, /system/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
at android.app.ActivityThread.access$900(ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
at android.os.Handler.dispatchMessage(Handler.java:102)
glPushMatrix
和glPopMatrix
用于从矩阵堆栈中推送矩阵和弹出矩阵。如果要将模型矩阵添加到视图矩阵,则必须执行以下步骤。
glPushMatrix
。这会在堆栈上推送视图矩阵的副本。glCallList(tie);
glEnd();
,glRotated
,...)glCallList
,glTranslated
,...)glPopMatrix
)。
像这样改编你的代码:
gluSphere