Original Post
Hi everyone,
I am a newbie to OpenGL programming, i have written a small program of LineStipple in OpenGL, but when i get the output when i try to resize the window, it is not getting resized properly, the function which implements LineStipple gets called again and again, even though i wrote the RESIZE function seperately, unable to figure out what exactly is the problem,
I am posting the code below,
--------------------------- LINE STIPPLE IMPLEMENTATION -----------------------------------------
---------------------------------------------------- MAIN FUNCTION -------------------------------------------------
Please help me
thanks in advance
GG
I am a newbie to OpenGL programming, i have written a small program of LineStipple in OpenGL, but when i get the output when i try to resize the window, it is not getting resized properly, the function which implements LineStipple gets called again and again, even though i wrote the RESIZE function seperately, unable to figure out what exactly is the problem,
I am posting the code below,
--------------------------- LINE STIPPLE IMPLEMENTATION -----------------------------------------
#include<GL/gl.h>
#include<GL/glu.h>
#include<GL/glut.h>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.1415926535898
#define drawline(x1,y1,x2,y2) glBegin(GL_LINES); glVertex2f(x1,y1); glVertex2f(x2,y2); glEnd(); glFlush();
void clr_wndow()
{
GLfloat v1[2] = {0.25,0.25};
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.8, 0.5, 0.0);
glPointSize(5.0f); //setting the size of the points
//printf("The glPoint size range is:%d",glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE));
glBegin(GL_LINES);
glVertex2fv(v1);
glVertex2f(0.75,0.25);
glVertex2f(0.85,0.50);
glVertex2f(0.75,0.75);
glVertex2f(0.25,0.75);
glVertex2f(0.15,0.50);
glEnd();
glFlush();
}
void dashed_lines()
{
glEnable(GL_LINE_STIPPLE);
glLineStipple(1,0x1);
glBegin(GL_LINE_LOOP);
drawline(0.25,0.25,0.75,0.25);
drawline(0.85,0.50,0.75,0.75);
drawline(0.25,0.75,0.15,0.50);
drawline(0.15,0.50,0.25,0.25);
glEnd();
glFlush();
}
void draw_rect()
{
GLfloat cords[4]={0.25,0.25,0.75,0.75};
glVertex4fv(cords);
}
void draw_circle()
{
glColor3f(1.0,1.0,1.0);
glVertex2f(0.73,0.73);
}
---------------------------------------------------- MAIN FUNCTION -------------------------------------------------
#include "wndw_clr_tst.h"
void display1()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_POLYGON);
glVertex3f(0.25,0.25,0.0);
glVertex3f(0.75,0.25,0.0);
glVertex3f(0.75,0.75,0.0);
glVertex3f(0.25,0.75,0.0);
glEnd();
glFlush();
}
void display2()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 0.0);
glBegin(GL_LINE);
glVertex3f(0.0,0.0,0.0);
glVertex3f(1.0,0.0,0.0);
glVertex3f(1.0,1.0,0.0);
glVertex3f(0.0,1.0,0.0);
glEnd();
glFlush();
}
void display3()
{
glColor3f(0.0,1.0,1.0);
glBegin(GL_TRIANGLES);
glVertex2f(0.25,0.25);
glVertex2f(0.75,0.25);
glVertex2f(0.75,0.75);
glEnd();
//glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
void resize(int w, int h)
{
printf("\nThe size of width and height is:%d,%d",w,h);
glViewport(0,0,(GLsizei)w,(GLsizei)h); //the object will not be visible because viewport is not viewing over the object placement
glClearColor(0.0,0.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,1.0,0.0,1.0);
}
int main(int argc,char *argv[])
{
char t[] = "true";
char f[] = "false";
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500 , 500);
glutCreateWindow("My First OpenGL program");
glutReshapeFunc(resize);
//glutDisplayFunc(display1);
//glutDisplayFunc(display2);
//glutDisplayFunc(display3);
//glutDisplayFunc(clr_wndow);
glutDisplayFunc(dashed_lines);
//printf("The blend is enabled?:%s",glIsEnabled(GL_BLEND) ? "true" : "false" );
glutMainLoop();
return 0;
}
Please help me
thanks in advance
GG