Reputation: 798
I'm learning OpenGL, and I am reading a book to help me a long. I've followed it through half way and have decided to go off on my own path now that I'm familiar with the basics. I've started to develop an application, the intention is to just show a grid.
I've pretty much nailed it, but when I run my application, part of the grid is cut off. I've attached a condensed version of the code (which has the same result) - does anyone know what I am doing wrong to make it cut off part of the screen? I've tinkered about a lot and I've run through a few values but I just cannot get this thing sorted. Any help or a nudge in the right direction is much appreciated.
Code:
#include <Windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "deps\glut\glut.h"
void display();
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(800, 600);
glutCreateWindow("");
glutDisplayFunc(display);
glClearColor(1.0, 1.0, 1.0, 1.0);
glColor3f(0.0, 0.0, 0.0);
// Init
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-8.0, 8.0, -8.0, 8.0, -8.0, 8.0);
glutMainLoop();
return 0;
}
void display() {
float f;
// Clear the screen
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0);
// This next bit of code just creates the grid
glColor3f(0.0f, 0.0f, 0.0f);
glPointSize(1.0);
for(f=-10.0f;f<10.0f;f++) {
glBegin(GL_LINES);
glVertex3f(f, 0.0f, -10.0f);
glVertex3f(f, 0.0f, 10.0f);
glEnd();
}
glRotatef(90, 0.0, 1.0, 0.0);
for(f=-10.0f;f<10.0f;f++) {
glBegin(GL_LINES);
glVertex3f(f, 0.0f, -10.0f);
glVertex3f(f, 0.0f, 10.0f);
glEnd();
}
// Swap the buffers
glutSwapBuffers();
}
Upvotes: 1
Views: 1728
Reputation: 162164
You're hitting the Z limits due to the diagonal of a unit cube being sqrt(3)
longer than the side. So I suggest you use -14…14 ( = ± round( 8*sqrt(3) )
) as limits for the near and far plane.
Upvotes: 1
Reputation: 283624
You can't draw outside the unit cube.
Your glOrtho
call scales the coordinates so that you can use the range -8...8
for x, y, and z coordinates, but your for loop then tries to use -10...10
, which exceeds the range and will be clipped.
Upvotes: 3