Reputation: 81
I have to display an object in opengl(it's a homework) and I found a good code on the internet,but the size of the displayed object is very small,and I don't know how to change it to display the object in bigger size.
I think that I have to modify reshape, drawObject and display functions, but I don't know opengl and it's functions so I don't know that which part of the code should I modify.
#include<stdio.h>
#include"glut.h"
GLuint object;
float objectrot;
char ch = '1';
void loadObj(const char* fname)
{
FILE* fp;
int read;
GLfloat x, y, z;
char ch;
object = glGenLists(1);
fp = fopen(fname, "r");
if (!fp)
{
printf("can't open file %s\n", fname);
exit(1);
}
glPointSize(2.0);
glNewList(object, GL_COMPILE);
{
glPushMatrix();
glBegin(GL_POINTS);
while (!(feof(fp)))
{
read = fscanf(fp, "%c %f %f %f", &ch, &x, &y, &z);
if (read == 4 && ch == 'v')
{
glVertex3f(x, y, z);
}
}
glEnd();
}
glPopMatrix();
glEndList();
fclose(fp);
}
void reshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (GLfloat)w / (GLfloat)h, 0.1, 1000.0);
glMatrixMode(GL_MODELVIEW);
}
void drawObject()
{
glPushMatrix();
glTranslatef(0, -40.00, -105);
glColor3f(255, 255, 255);
glScalef(0.1, 0.1, 0.1);
glRotatef(objectrot, 0, 1, 0);
glCallList(object);
glPopMatrix();
objectrot += 0.001;
if (objectrot > 360)objectrot -= 360;
}
void display(void)
{
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
drawObject();
glutSwapBuffers();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(800, 450);
glutInitWindowPosition(20, 20);
glutCreateWindow("ObjLoader");
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutIdleFunc(display);
loadObj("cat.obj");
glutMainLoop();
return 0;
}
I expect a larger object in the window,but it is very small
Upvotes: 2
Views: 2830
Reputation: 1041
You need to increase the scale factor.
void drawObject()
{
glPushMatrix();
glTranslatef(0, -40.00, -105);
glColor3f(255, 255, 255);
glScalef(1.0, 1.0, 1.0);
glRotatef(objectrot, 0, 1, 0);
glCallList(object);
glPopMatrix();
objectrot += 0.001;
if (objectrot > 360)objectrot -= 360;
}
You should pass in a larger number to glScalef()
. Try 1.0 and see if that works.
Upvotes: 2