So my task is to create a subwindow system which I give the coordinates (xmin,ymin,xmax,ymax) by the glui system I create when I push the start button, to draw a rectangle on each side, but it seems not working the draw?
here is my attempt:
#include <stdio.h>
#include <stdlib.h>
#include <GL\glut.h>
#include "glui.h"
#define WINDOW_WIDTH 1000
#define WINDOW_HEIGHT 600
#define RESET 100
#define SET 101
#define SIZE 10.0
int getcode(int x, int y);
void draw_line(int x1, int y1, int x2, int y2);
void draw_rect();
void init_val();
void button_cb( GLUI_Control *control);
void myGlutIdle();
void init_glui();
void disp_main();
void myDisplay_sub_1();
void myDisplay_sub_2();
int main_window,subwindow_1,subwindow_2;
int xmin_1,ymin_1,xmax_1,ymax_1,numlines_1,xmin,ymin,xmax,ymax,numlines,acc;
GLUI *glui_h_subwindow, *glui_v_subwindow, *glui_r_subwindow;
GLUI_Panel *projection_panel;
GLUI_EditText *xmin_f,*ymin_f,*xmax_f,*ymax_f,*numlines_f;
GLUI_Button *ok;
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitWindowPosition(100, 100);
glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
glutInitDisplayMode( GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA );
main_window = glutCreateWindow(" C_s_&_L_b_clip ");
glutDisplayFunc(disp_main);
gluOrtho2D(-WINDOW_WIDTH, WINDOW_WIDTH, -WINDOW_HEIGHT, WINDOW_HEIGHT);
init_val();
init_glui();
// printf("numlines = %d \n",numlines);
// printf("xmax=%d , ymax=%d xmin=%d ymin=%d \n",xmax,ymax,xmin,ymin);
subwindow_1 = glutCreateSubWindow (main_window, 0,0 , WINDOW_WIDTH/2,WINDOW_HEIGHT);
glutDisplayFunc(myDisplay_sub_1);
subwindow_2 = glutCreateSubWindow (main_window,0,0,WINDOW_WIDTH,WINDOW_HEIGHT);
glutSetWindow(subwindow_2);
glutDisplayFunc(myDisplay_sub_2);
glutMainLoop();
}
I think the problem is here on the main system and the windows size maybe but it's a guess I think!
void disp_main() {
glutSetWindow(main_window);
glClear(GL_COLOR_BUFFER_BIT);
}
void myDisplay_sub_1()
{
glutSetWindow(subwindow_1);
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.0,0.1,0.0,0.0);
glColor3f(1.0, 0.0, 0.0);
draw_rect();
glutSwapBuffers();
}
void myDisplay_sub_2()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0.0, 0.0);
draw_rect();
glutSwapBuffers();
}
void draw_line(int x1, int y1, int x2, int y2)
{
glBegin(GL_LINES);
glVertex2i(x1, y1);
glVertex2i(x2, y2);
glEnd();
}
void draw_rect()
{
glBegin(GL_LINES);
glVertex2i(xmin, ymax);
glVertex2i(xmax, ymax);
glVertex2i(xmax, ymin);
glVertex2i(xmin, ymin);
glVertex2i(xmin, ymax);
glVertex2i(xmin, ymin);
glVertex2i(xmax, ymax);
glVertex2i(xmax, ymin);
glEnd();
}