• Advertisement
Sign in to follow this  

Resize function for 3D and 2D

This topic is 1924 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I posted here my code for switching fullscreen/window, but main problem I have is Resize function, which I haven't, because I'm using 3D and 2D objects and I don't know how can I resize both (3d is OK, but both is complicated for me).

Dispaly function:

// Display Function
void Display(void) {
glClearColor(0.3f, 0.5f, 0.9f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Set 3D
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, (int)width, (int)height);
gluPerspective(30, width/height, 0.1, 10000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Set camera
gluLookAt(cam1,27,130, 5,11,0, 0,1,0);
glutPostRedisplay();
// Light and Z-buffer
glPushAttrib(GL_ALL_ATTRIB_BITS);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmb);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiff);
// Draw Map and Car
glPushMatrix();
// load map obj
glPushMatrix();
glTranslatef(x,y,z);
glRotatef(-180, 0.0, 1.0, 0.0);
glmDraw(map, GLM_SMOOTH | GLM_MATERIAL);
glPopMatrix();
// load car obj
glPushMatrix();
glTranslatef(x+carx, y+cary, z+carz);
glRotatef(-180, 0.0, 1.0, 0.0);
glmDraw(car, GLM_SMOOTH | GLM_MATERIAL);
glPopMatrix();
glPopMatrix();
glPopAttrib();
glFlush();
// Set 2D
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,width,height,0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
// Draw text
glPushMatrix();
glColor3f(1, 1, 1);
renderBitmapString(10,20,(void *)font2,"Press 'H' for show/hide help");
glEnd();
glPopMatrix();
// Show help menu
if(h1==true) {
glTranslatef((float)((width-500)/2),(float)(500+((height-500)/2)),0);
glPushMatrix();
glColor3f(1, 1, 1);
glBegin(GL_QUADS);
glVertex3f(0.0f, -500.0f, 0.0f); // The bottom left corner
glVertex3f(0.0f, 0.0f, 0.0f); // The top left corner
glVertex3f(500.0f, 0.0f, 0.0f); // The top right corner
glVertex3f(500.0f, -500.0f, 0.0f); // The bottom right corner
glEnd();
glPopMatrix();
glPushMatrix();
glColor3f(0, 0, 0);
renderBitmapString(130,-440,(void *)font1,"P H Y S X C A R S I M U L A T O R");
renderBitmapString(190,-410,(void *)font2,"HELP MENU:");
renderBitmapString(60,-350,(void *)font2,"'K' = change to left-side camera");
renderBitmapString(60,-320,(void *)font2,"'L' = change to right-side camera");
renderBitmapString(60,-290,(void *)font2,"'ESC' = exit program");
renderBitmapString(60,-50,(void *)font1,"Author: Son Nguyen (NGU0013) Version: 1.0 , 2012");
glEnd();
glPopMatrix();
}


I want Resize function that Set 2D and Set 3D block will be in it. Thanks

Share this post


Link to post
Share on other sites
Advertisement
I found the solution, I look like an idi*t right now, it's really simple:

static float width=1366.0, height=768.0;
void Resize (int x, int y)
{
width=(float)x;
height=(float)y;
}

Then in Main method i'm using glutReshapeWindow(Resize) :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement