Results 1 to 2 of 2

Thread: Viewport and other help needed please

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2009
    Posts
    2

    Viewport and other help needed please

    I'm going to post my code but I will explain what I need help with first.

    I'm currently trying to setup my project and have two wireframe teapots appear on the screen, one in orthographic view and one in perspective view.

    I have drawn two windows and I think the code is right for the different type of viewports (ortho and perspective) but it is what I want to do after this that is stalling me.

    In the orthographic view I want to be able to view the x,y,z axis by pressing their keys respectively without the teapot in the perspective window moving also, and in perspective view I want to be able to use the arrow keys to rotate around the teapot without the ortho teapot moving.

    My main problem is that I dont know how to separate the teapots so I can do this, I think my windows are setup correctly but I'm just having a tonne of trouble. Code is posted below

    Code :
     
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <GL/glut.h>
     
    static int WIN_H = 800; /* window height */
    static int WIN_W = 800; /* window width */
    static int WIN_POS_X = 200; /* window's x position */
    static int WIN_POS_Y = 0; /* window's y position */
     
    float xAngle;
    float yAngle;
    float zAngle;
     
    void drawTeapot() 
    {
    	glRotatef(xAngle,1.0,0.0,0.0);
    	glRotatef(yAngle,0.0,1.0,0.0);
    	glColor3f(150.0,200.0,100.0);
    	glutWireTeapot(0.5);
    	glFlush ();
    }
     
    void display()
    {
    	glClearColor(0.0,1.0,0.0,1.0);
    	glClear (GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
    	glLoadIdentity();
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
     
    	glViewport(0,0,WIN_W/2,WIN_H);
    	gluPerspective(45.0,1.0* WIN_W/WIN_H,1.0,100.0);
    	glTranslatef(0.0,0.0,-10.0);
    	drawTeapot();
     
     
    	glLoadIdentity();
    	glOrtho(0.0,WIN_W,0.0,WIN_H,0.0,0.0);
    	glMatrixMode(GL_MODELVIEW);
    	glViewport(WIN_W/2,0,WIN_W/2,WIN_H);
    	drawTeapot();
    	glFlush();
    }
     
    void keyboard (unsigned char key, int x, int y) {
     
    if (key=='q')
    {
    exit(1);
    }
     
    if(key == 'x')
    {
    	xAngle = 0.0;
    	yAngle = 0.0;
     
    	glutPostRedisplay();
    }
     
    if(key == 'y')
    {
     
    	xAngle = 90.0;
    	yAngle = 0.0;
     
    	glutPostRedisplay();
    }
    if(key == 'z')
    {
    	xAngle = 0.0;
    	yAngle = 120.0;
     
    	glutPostRedisplay();
     
    }
     
    }
     
    int main(int argc, char* argv[])
    {	
     
       glutInit(&amp;argc,argv);
       glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
       glutInitWindowSize(WIN_W,WIN_H);
       glutInitWindowPosition(WIN_POS_X, WIN_POS_Y);
       glutCreateWindow("OPENGL PROGRAM");
     
     
       glutDisplayFunc(display); 
       glutKeyboardFunc(keyboard);
       glutMainLoop();
    	return 0;
    }

    help plz

  2. #2
    Junior Member Newbie
    Join Date
    Feb 2009
    Posts
    2

    Re: Viewport and other help needed please

    nevermind, fixed it myslef lol

Similar Threads

  1. Viewport/image help needed
    By smokin123 in forum OpenGL: Basic Coding
    Replies: 10
    Last Post: 02-09-2011, 08:01 AM
  2. Viewport
    By in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 09-17-2006, 06:15 PM
  3. Replies: 2
    Last Post: 05-27-2002, 02:59 AM
  4. More than one viewport
    By glbeginner in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 02-07-2001, 04:28 AM
  5. Viewport or multiple viewport in a window!
    By Boubou in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 11-30-2000, 05:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean