Hi,
I want to draw a rectangle with vertices (200,200),(200,250),(250,250),(250,200).I have fixed the frustum to be (0,480,0,640).
The rectangle is drawn outside .How do i fix the code?
//#define GLFW_DLL
//#pragma comment (lib,"glew32.lib")
#define GLEW_STATIC
#include <stdio.h>
#include <gl/glew.h>
#include <glfw.h>
#define BUFFER_OFFSET(offset)((char*)NULL+offset)
void init(void)
{
int glewinitialize;
//float aspect_ratio;
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_FLAT);
glewinitialize=glewInit();
if(glewinitialize==GLEW_OK)
{
printf("GLEW is available
");
}
}
void GLFWCALL reshape(int width,int height)
{
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// gluOrtho2D(0.0,(GLdouble)width,0.0,(GLdouble)height);
glFrustum(0.0,(GLdouble)width,0.0,(GLdouble)height,0.0,20.0);
// gluPerspective(270.0,2.0,0.0,20.0);
glMatrixMode(GL_MODELVIEW);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
glLoadIdentity();
gluLookAt(0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0);
//glTranslatef(0.0,0.0,-1.0);
//glScalef(1.0,2.0,1.0);
/*glPointSize(5.0);
glBegin(GL_POINTS);
glVertex3f(200.0,200.0,0.0);
glEnd();*/
glBegin(GL_QUADS);
glVertex3f(200.0,200.0,0.0);
glVertex3f(200.0,250.0,0.0);
glVertex3f(250.0,250.0,0.0);
glVertex3f(250.0,200.0,0.0);
glEnd();
glfwSwapBuffers();
}
int main(int argc,char** argv)
{
int wndstate,wndopenstate;
wndstate=glfwInit();
if(wndstate==1)
{
wndopenstate=glfwOpenWindow(640,480,0,0,0,0,4,0,GLFW_WINDOW);
if(wndopenstate==0)
{
glfwTerminate();
}
else
{
glfwSetWindowTitle("Hello Opengl");
glfwSetWindowPos(30,30);
init();
glfwSetWindowSizeCallback(reshape);
while(1)
{
display();
if(glfwGetKey(GLFW_KEY_ESC))
{
glfwTerminate();
}
}
}
}
glfwTerminate();
return 0;
}