Jump to content
  • Advertisement
Sign in to follow this  
GRAPHIC GEEK

OpenGL OpenGL LineStipple Problem

This topic is 2399 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 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 -----------------------------------------

#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

Share this post


Link to post
Share on other sites
Advertisement
Resizing alters the size of the window, invalidates the content, and invokes your routines to redraw the content. Resizing does not mean that the size is altered and the content is scaled (or whatever automatic effect you expect). If you want to have such a behaviour you need to implement it yourself.

BTW: Please avoid using names like wndw_clr_tst and clr_wndow. It is confusing, there is a chance that words are used inconsistently (see "wndw" and "wndow"), and doesn't save you much keystrokes in the end.

Share this post


Link to post
Share on other sites
haegarr,
Thanks a lot for replying, so what you were saying is apart from what you write in RESIZE callback function, all the methods that are even called after RESIZE function are recalled is that it?

then how can i avoid my above problem of each time when i resize the glutDisplayFunc(dashed_lines) getting called repeatedly?

and I am really sorry for the inconvenience i have created for you, i see that i wont repeat it again..

please shed some light on me
Thanks in advance
GG

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!