Switching OpenGL to perspective mode on top of a semi-realized spelling scene?

We have a mostly 2D game that works in spelling mode, but one part shows a 3D model that is displayed between other 2D objects. How to switch to perspective mode, display this model, and then go back to display other objects in spelling mode?

Kudos, if you can show how this is done in OpenGL ES.

+4
source share
3 answers

I think this is not exactly the question asked. Do you want more views? Or do you want to have a 2D background, 3D game objects, 2D gii. If you want this, then:

  • make fullscreen background
  • set viewport to position = obj.pos-obj.size / 2, size = obj.size, render object
  • render 2D gui

Or do you want something else?

EDIT:

Here's a little code:

glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,w,0,h,near,far); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(pos.x,...); DrawQuads(); //if you want to keep your previus matrix glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluPerspective(90,width/(float)height,0.001,1000); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glTranslatef(pos.x,...); glRotate(-45.0f,1,0,0); glTranslate(0,0,distance from object); glRotate(90.0f,1,0,0); // or use gluLookAt // 0,0,1 - if you want have z as up in view // 0,1,0 - for y //gluLookAt(pos.x,pos.y,pos.z,cam.x,cam.y,cam.z,0,0,1); glScale(object.width/model.width,...); DrawModel(); // Restore old ortho glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); 
+4
source

Well, "just do it"

  • set the projection matrix as ortho
  • Define your modeling for 2D objects
  • display your 2D objects
  • set the projection matrix as projection
  • Define your simulation for 3D objects
  • render your 3D objects

... and this may happen again

  • and swap buffers.

If you KNOW the order of your objects, as it seems to you, you can also clear the z-buffer between each render.

+2
source

I agree with the previous posts, and I think the more general case is similar to a 3D object and a 2D-gui. Just for re-emphasis. :)

 glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective( 45.0f, (GLfloat)s_width/(GLfloat)s_height, near, far); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // render 3D object glUseProgram(modelProgram); glSetUniformMat(glGetUniformLocation(model.mvp, "mvp"), mvpMat); glBindVertexArray(model.vao); glDrawArrays(GL_TRIANGLES, 0, model.size); glUseProgram(0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, width, 0, height, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // draw GUI renderGUI(); 
0
source

All Articles