Reputation: 1
I am attempting to tile an image on the screen using menus. My menu works-tiling in the appropriate way-properly until I move my mouse then the tiling design disappears?
#include <GL/glut.h>
#include <fstream>
#include <cstdlib>
#include "TUGL.h"
#include <glui.h>
//Global variables
class GLintPoint
{
public:
GLint x;
GLint y;
};
GLint numpoints;
GLintPoint P[10];
window Win(800,600);
frame Frame;
GLUI *glui;
int mainwindow;
//Function prototypes
void readinpoints();
void drawline(GLint from, GLint to);
void display(void);
void init (void);
void keyboard(unsigned char key, int x, int y);
void tile1(void);
void tile4(void);
void tile9(void);
void tile16(void);
void myReshape(GLsizei W, GLsizei H);
void define_glui_window();
void choice_selected(int value);
void drawImage(void);
//Main
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (Win.width, Win.height);
glutInitWindowPosition (100, 100);
mainwindow = glutCreateWindow ("*star*");
init();
define_glui_window();
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutReshapeFunc(myReshape);
readinpoints();
glutMainLoop();
return 0;
}
//Functions
void init (void)
{
glClearColor (0.0, 0.0, 0.0, 0.0); //set background color
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 200, 0.0, 249, -1.0, 1.0);
}
void readinpoints()
{
ifstream infile("polyline.pts");
numpoints=0;
infile>>P[numpoints].x>>P[numpoints].y;
while (!infile.eof())
{
numpoints++;
infile>>P[numpoints].x>>P[numpoints].y;
}
numpoints=numpoints-1;
}
void drawline(GLint from, GLint to)
{
glBegin(GL_LINES);
{
glVertex2i(P[from].x, P[from].y);
glVertex2i(P[to].x, P[to].y);
}
glEnd();
}
void drawImage(void);
{
glClear (GL_COLOR_BUFFER_BIT)
glColor3f (1.0, 0.0, 1.0);
glLineWidth(3);
drawline(0,1);
drawline(1,2);
drawline(2,3);
drawline(3,4);
drawline(4,5);
drawline(5,6);
drawline(6,7);
drawline(7,8);
drawline(8,9);
drawline(9,0);
glFlush();
}
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
//autoViewPort(Frame, Win);
drawImage();
}
void tile1(void)
{ glClear (GL_COLOR_BUFFER_BIT);
for(int i=0; i < 1; i++)
for(int j=0; j < 1; j++)
{
//autoViewPort(Frame, Win);
glViewport(i * 800, j * 600, 800, 600);
drawImage();
glFlush();
}
}
void tile4(void)
{ glClear (GL_COLOR_BUFFER_BIT);
for(int i=0; i < 2; i++)
for(int j=0; j < 2; j++)
{
// autoViewPort(400, 300);
glViewport(i * 400, j * 300, 400, 300);
drawImage();
glFlush();
}
}
void tile9(void)
{
glClear (GL_COLOR_BUFFER_BIT);
for(int i=0; i < 3; i++)
for(int j=0; j < 3; j++)
{
// autoViewPort(267, 200);
glViewport(i * 267, j * 200, 267, 200);
drawImage();
glFlush();
}
}
void tile16(void)
{
glClear (GL_COLOR_BUFFER_BIT);
for(int i=0; i < 4; i++)
for(int j=0; j < 4; j++)
{
// autoViewPort(200, 150);
glViewport(i * 200, j * 150, 200, 150);
drawImage();
glFlush();
}
}
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
case 'f':
tile4();
break;
case 'n':
tile9();
break;
case 's':
tile16();
break;
case 'o':
tile1();
break;
}
}
void myReshape(GLsizei W, GLsizei H)
{
Win.set(W,H);
autoViewPort(Frame, Win);
}
void choice_selected(int value)
{
switch (value)
{
case 1:
tile1();
break;
case 2:
tile4();
break;
case 3:
tile9();
break;
case 4:
tile16();
break;
}
}
void define_glui_window()
{
glui = GLUI_Master.create_glui("OPTIONS", 0, 560, 50);
GLUI_StaticText *message1 = glui->add_statictext(" BACKGROUND COLOR ");
glui->add_button("Tile-1", 1, choice_selected);
glui->add_button("Tile-4", 2, choice_selected);
glui->add_button("Tile-9", 3, choice_selected);
glui->add_button("Tile-16", 4, choice_selected);
glui->set_main_gfx_window(mainwindow);
GLUI_Master.sync_live_all();
}
Upvotes: 0
Views: 364
Reputation: 22591
Check for errors with glError()
after each OpenGL call. The point which is failing will return an error. Then you can also look up the error code for extra information on what went wrong.
Upvotes: 2