Beispiel #1
0
void
piglit_init(int argc, char **argv)
{
	GLint maxColorTextureSamples;

	/* glClearTexture is either in the GL_ARB_clear_texture
	 * extension or in core in GL 4.4
	 */
	if (piglit_get_gl_version() < 44 &&
	    !piglit_is_extension_supported("GL_ARB_clear_texture")) {
		printf("OpenGL 4.4 or GL_ARB_clear_texture is required.\n");
		piglit_report_result(PIGLIT_SKIP);
	}

	piglit_require_extension("GL_ARB_texture_multisample");
	piglit_require_GLSL_version(130);

	/* We need to support multisample textures with at least 4
	 * samples */
	glGetIntegerv(GL_MAX_COLOR_TEXTURE_SAMPLES, &maxColorTextureSamples);
	if (maxColorTextureSamples < TEX_SAMPLES) {
		printf("At least %i texture samples are required\n",
		       TEX_SAMPLES);
		piglit_report_result(PIGLIT_SKIP);
	}

	init_program();
}
Beispiel #2
0
Datei: viewer.cpp Projekt: foo/ii
void viewer::init()
{
  map.load();

  init_program();
  init_vbo();

  glGenVertexArrays(1, &vao);
  glBindVertexArray(vao);
}
sph_model::sph_model(sph_cache& cache,
                     const char *vert,
                     const char *frag, int n, int d, int s) :
    cache(cache), depth(d), size(s), time(1), status(cube_size(d), s_halt)
{
    init_program(vert, frag);
    init_arrays(n);
    
    zoomv[0] =  0;
    zoomv[1] =  0;
    zoomv[2] = -1;
    zoomk    =  1;
}
Beispiel #4
0
void init(void)
{
	int ship, bull;	

	ship = init_program(4, "vshader.glsl", GL_VERTEX_SHADER,"fshader.glsl", GL_FRAGMENT_SHADER);
	if (ship < 0) {
		fprintf(stderr,"Error: could not initialize program, bailing...\n");
		exit(1);
	}
	
	bull = init_program(4, "vbullets.glsl", GL_VERTEX_SHADER, "fbullets.glsl", GL_FRAGMENT_SHADER);
	if (bull < 0) {
		fprintf(stderr,"Error: could not initialize program, bailing...\n");
		exit(1);
	}

	init_renderer(ship, bull);

	players[0] = genShip();
	players[1] = genShip();


	// Set player colors
	players[0]->color[0] = 1.0f;
	players[0]->color[1] = 0.0f;
	players[0]->color[2] = 0.0f;
	players[0]->color[3] = 1.0f;

	players[1]->color[0] = 0.0f;
	players[1]->color[1] = 1.0f;
	players[1]->color[2] = 0.0f;
	players[1]->color[3] = 1.0f;

	// Set intial positions	
	players[0]->pos = {-WINDOW_X/2,WINDOW_Y/2};
	players[1]->pos = {-WINDOW_X/2,-WINDOW_Y/2};


}
Beispiel #5
0
void init(void)
{
	prog = init_program(4, "vshader.glsl", GL_VERTEX_SHADER , "fshader.glsl", GL_FRAGMENT_SHADER);
	if (prog < 0) {
		fprintf(stderr,"Error: could not initialize program, bailing...\n");
		NOPE(1);
	}

	glUseProgram(prog);
	glEnable(GL_DEPTH_TEST);

//	pos.x = 0.5f;
//	pos.y = 0.5f;
}
Beispiel #6
0
void
piglit_init(int argc, char **argv)
{
	/* glClearTexture is either in the GL_ARB_clear_texture
	 * extension or in core in GL 4.4
	 */
	if (piglit_get_gl_version() < 44 &&
	    !piglit_is_extension_supported("GL_ARB_clear_texture")) {
		printf("OpenGL 4.4 or GL_ARB_clear_texture is required.\n");
		piglit_report_result(PIGLIT_SKIP);
	}

	init_program();
}
Beispiel #7
0
ogl::binding::binding(std::string name) :
    name(name),
    depth_program(0),
    color_program(0)
{
    std::string path = "material/" + name + ".xml";

    app::file file(path);

    // Load the local material bindings.

    if (app::node p = file.get_root().find("material"))
    {
        // Load the depth-mode bindings.

        if (app::node n = p.find("program", "mode", "depth"))
            depth_program = init_program(n, depth_texture);

        // Load the color-mode bindings.

        if (app::node n = p.find("program", "mode", "color"))
            color_program = init_program(n, color_texture);
    }
}
Beispiel #8
0
int		vsh(int ac, char **av, char **env)
{
  t_shell	shell;
  char		*str;

  (void)ac;
  (void)av;
  init_program(&shell, env);
  while ((shell.flag & SH_EXIT) &&
	 (str = my_readline(&shell, generate_prompt())))
    {
      lexor_and_parsor(str, &shell);
      main_execution(&shell);
    }
  exit_42sh(&shell);
  return (EXIT_SUCCESS);
}
Beispiel #9
0
main (int argc, char *argv[])
{
  
  init_program();  
  
  signal(SIGTERM,signal_handler_main);
  signal(SIGKILL,signal_handler_main);
  signal(SIGINT,signal_handler_main);
  signal(SIGPIPE,signal_brokenpipe_client);
  pthread_t t_server, t_upload,t_forward;
  pthread_create(&t_upload, NULL, &data_uploading_thread, NULL);
  pthread_create(&t_forward, NULL, &ticket_forwarder_thread, NULL);
  pthread_create(&t_server, NULL, &connection_manager_thread, NULL);
  pthread_join(t_upload, NULL);
  pthread_join(t_forward, NULL);
  pthread_join(t_server, NULL);
 

  exit(0);
}
Beispiel #10
0
void main(int argc, char** argv)
{
	glutInit(&argc,argv);
	glutCreateWindow("GLSL Texture Mapping Demo");
	glutDisplayFunc(&redraw);
	glutTimerFunc(20,&update,0);
	glutKeyboardFunc(&key_down);
	glutReshapeWindow(600,600);
	gl3wInit();                   // must initialize OpenGL 3.0 or else crashy crashy!

	init_program();
	init_vertex_buffer();
	texid = gl_loadtexture("checker.png");

	//texid = gl_loadtexture("checker_small.png");
	//glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
	//glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);

	glutMainLoop();
}
Beispiel #11
0
void
init_OGL() {
	//Vars for whiteTexture
	ImageFormat format;
	unsigned char data;

	program = malloc(sizeof(Program));
	fragShader = malloc(sizeof(Shader));
	vertexShader = malloc(sizeof(Shader));

	vertPosAttrib = malloc(sizeof(Attribute));
	texCoordAttrib = malloc(sizeof(Attribute));
	
	colorUni = malloc(sizeof(Uniform));
	diffuseSamplerUni = malloc(sizeof(Uniform));

	init_shader_from_file(fragShader, FRAGMENT_SHADER, FRAGMENT_SHADER_LOC);
	init_shader_from_file(vertexShader, VERTEX_SHADER, VERTEX_SHADER_LOC);
	init_program(program, fragShader, vertexShader);
	init_attribute(vertPosAttrib, program, SVAR_VEC2, "vertPos");
	init_attribute(texCoordAttrib, program, SVAR_VEC2, "texCoord");
	init_uniform(colorUni, program, SVAR_VEC4, "color");
	init_uniform(diffuseSamplerUni, program, SVAR_SAMPLER2D, "diffuse");
	

	//Create white texture
	whiteTexture = malloc(sizeof(Texture));
	format = TEX_FMT_RED;
	data = 0xFF; //White
	init_texture(whiteTexture, format, 1, 1, &data);


	//Set default color to white
	colorRed = 1;
	colorGreen = 1;
	colorBlue = 1;
	colorAlpha = 1;
}
Beispiel #12
0
void main(int argc,char **argv)
{
  int i,nowait=FALSE;

  setup_struct();

  if(argc != 1)
  {
    for(i=1;i<argc;i++)
    {
      if(strcmp(argv[i],"-map") == 0) sm->mapdraw = TRUE;
      else if((strcmp(argv[i],"-server") == 0) || (strcmp(argv[i],"-s") == 0))
      {
        i++;
        sm->sologame = FALSE;
        if(strlen(argv[i]) > 255)
        {
          fprintf(stderr,"Hostname too int!!\n");
          exit(1);
        }
        strcpy(sm->hostname,argv[i]);
      }
      else if((strcmp(argv[i],"-help") == 0) || (strcmp(argv[i],"-h") == 0))
      {
        usage(stdout);
        exit(0);
      }
      else if(strcmp(argv[i],"-name") == 0)
      {
        i++;
        if(strlen(argv[i]) >= MAXNAME)
        {
          fprintf(stderr,"Name too int. Maximum is %d character.\n",MAXNAME-1);
          exit(1);
        }
        strcpy(sm->ownname,argv[i]);
      }
      else if(strcmp(argv[i],"-tiny") == 0)
        sm->outputsize = 14;
      else if(strcmp(argv[i],"-small") == 0)
        sm->outputsize = 13;
      else if(strcmp(argv[i],"-huge") == 0)
        sm->outputsize = 11;
      else if(strcmp(argv[i],"-big") == 0)
        sm->outputsize = -1;
      else if(strcmp(argv[i],"-mono") == 0)
        sm->monomode = TRUE;
      else if((strcmp(argv[i],"-gray") == 0) || (strcmp(argv[i],"-grey") == 0))
        sm->graymode = TRUE;
      else if(strcmp(argv[i],"-dither") == 0)
        sm->dithermode = TRUE;
      else if(strcmp(argv[i],"-nowait") == 0)
        nowait = TRUE;
      else if(strcmp(argv[i],"-camera") == 0)
        sm->camera = TRUE;
      else if(strcmp(argv[i],"-direct") == 0)
        sm->directdraw = TRUE;
      else if(strcmp(argv[i],"-sound") == 0)
        sm->usesound = TRUE;
      else if(!strcmp(argv[i],"-privatecmap"))
        sm->privatecmap = TRUE;
      else if(!strcmp(argv[i],"-noshmem"))
        sm->noshmem = TRUE;
      else if(!strcmp(argv[i],"-texture"))
      {
        sm->texturemode = TRUE;
        sm->privatecmap = TRUE;
      }
      else if(strcmp(argv[i],"-comment") == 0)
      {
        i++;
        if(strlen(argv[i]) >= MAXCOMMENT)
        {
          fprintf(stderr,"Comment too int. Maximum is %d character.\n",MAXCOMMENT-1);
          exit(1);
        }
        strcpy(sm->owncomment,argv[i]);
      }
      else
      {
        usage(stderr);
        exit(1);
      }
    }
  }
#ifndef USE_SOUND
  if(sm->usesound)
    fprintf(stderr,"You haven't compiled netmaze with USE_SOUND.\n");
#endif

  if(sm->sologame && sm->usesound)
  {
    sm->usesound = FALSE;
    fprintf(stderr,"It's not possible to use sound in the solo testmode.\n");
  }

  if( (sm->monomode + sm->graymode + sm->dithermode) > 2 )
  {
    fprintf(stderr,"Sorry .. only -mono OR -gray OR -dither is allowed\n");
    exit(1);
  }
  if( sm->texturemode && (sm->monomode || sm->graymode || sm->dithermode))
  {
    fprintf(stderr,"Warning: Textures only usefull in colormode yet.\n");
  }

    /* init Default-Maze */
  create_maze(&(sm->std_maze));
    /* Signals,Gfx,Network,(IPC:fork),keyboard initialisieren */
  init_program(argc,argv);

  if(sm->sologame)
  {
    printf("Press '1' to start game!\n");
  }
  else
  {
    printf("OK .. now wait for serverstart\n");
  }

  /**** beginning of the mainloop (endless) ****/

  while(!sm->exitprg)
  {
    int waitselect;

#ifdef USE_IPC
   if(sm->sologame) x11_cntrl();
#else
   x11_cntrl();
#endif

    if(nowait)
      waitselect = FALSE;
    else
      waitselect = TRUE;

    if(sm->bgdraw)
    {
      draw_info();
      sm->bgdraw = FALSE;
      x11_flush();
    }

    if((sm->screendraw) && (sm->redraw))
    {
      if(sm->drawwait >= DRAWWAIT)
      {
        sm->redraw = FALSE;
        sm->drawwait = 0;
        draw_screen();
        waitselect = FALSE;
      }
    }

    if((sm->winnerdraw) && (sm->redraw))
    {
      sm->redraw = FALSE;
      draw_end(sm->playfeld,sm->winner); /* does XSync() */
    }

    if((sm->statchg2) && (!sm->gameflag)) /*update Screen after the Gameover*/
    {
      sm->statchg  = TRUE;
      sm->statchg2 = FALSE;
      draw_status(-1,sm->playfeld);
      x11_flush();
    }

    if((sm->killchg) && (!sm->gameflag)) /*update Screen after the Gameover*/
    {
      draw_kills(sm->shownumber,sm->playfeld);
      x11_flush();
    }

    if(waitselect) /* test! only a timeout-wait yet */
    {              /* this reduces the load enormous :) */
      struct timeval timeout;
#ifdef USE_IPC
      if(sm->gameflag)
      {
        timeout.tv_sec = 0;
        timeout.tv_usec = 1000; /* lower than the minval on most machines */
      }
      else
      {
#endif
        timeout.tv_sec = 0;         /* in NON-IPC versions, the SIGIO-Signal */
        timeout.tv_usec = 100000;   /* also exits the select-command */
#ifdef USE_IPC
      }
#endif
      select(0,NULL,NULL,NULL,&timeout);
    }
  }

  XCloseDisplay(sm->grafix.display);
}
Beispiel #13
0
bool init(void)
{
	SGE_ASSERT(details::g_window == NULL);
	SGE_ASSERT(details::g_gl_context == NULL);

	SGE_LOGD("Creating OpenGL window...\n");

	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
	SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);

#ifdef SGE_DEBUG
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
#endif

	details::g_window = SDL_CreateWindow("SGE",
		SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600,
		SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_ALLOW_HIGHDPI);

	if (details::g_window == NULL)
		return false;

	details::g_window_id = SDL_GetWindowID(details::g_window);
	SDL_GetWindowPosition(details::g_window, &details::g_window_rect[0], &details::g_window_rect[1]);
	SDL_GetWindowSize(details::g_window, &details::g_window_rect[2], &details::g_window_rect[3]);

	SGE_LOGD("Initializing OpenGL...\n");

	details::g_gl_context = SDL_GL_CreateContext(details::g_window);
	if (details::g_gl_context == NULL) {
		SGE_LOGE("Failed to create OpenGL context.\n");
		SDL_DestroyWindow(details::g_window);
		details::g_window = NULL;
		return false;
	}

	SDL_GL_MakeCurrent(details::g_window, details::g_gl_context);

	glewExperimental = GL_TRUE;

	if (glewInit() != GLEW_OK) {
		SGE_LOGE("Failed to initialize GLEW.\n");
		SDL_GL_DeleteContext(details::g_gl_context);
		details::g_gl_context = NULL;
		SDL_DestroyWindow(details::g_window);
		details::g_window = NULL;
		return false;
	}

#ifdef SGE_DEBUG
	if (GL_KHR_debug) {
		SGE_LOGD("Enable OpenGL debug output.\n");
		glDebugMessageCallback(gl_debug_output, NULL);
	}
#endif

	SGE_LOGI("GLEW: %s\n", glewGetString(GLEW_VERSION));
	SGE_LOGI("OpenGL: %s\n", glGetString(GL_VERSION));

	IMGUI_CHECKVERSION();

    s_imgui_context = ImGui::CreateContext();
	if (s_imgui_context == NULL) {
		SGE_LOGE("Failed to initialize ImGui.\n");
		SDL_GL_DeleteContext(details::g_gl_context);
		details::g_gl_context = NULL;
		SDL_DestroyWindow(details::g_window);
		details::g_window = NULL;
		return false;
	}

	ImGui::SetCurrentContext(s_imgui_context);

    ImGuiIO &io = ImGui::GetIO();
	io.IniFilename = NULL;

	SGE_LOGI("ImGui: %s\n", ImGui::GetVersion());

    ImGui::StyleColorsDark();

	ImGuiStyle &style = ImGui::GetStyle();
	style.Alpha = 1.1f;
	style.WindowRounding = 0.0f;
	style.WindowBorderSize = 1.0f;
	style.ChildRounding = 0.0f;
	style.ChildBorderSize = 0.0f;
	style.PopupRounding = 0.0f;
	style.PopupBorderSize = 0.0f;

    ImGui_ImplSDL2_InitForOpenGL(details::g_window, details::g_gl_context);
    ImGui_ImplOpenGL3_Init("#version 130");

	if (!init_program()) {
		SGE_LOGE("Failed to initialize ImGui.\n");
		SDL_GL_DeleteContext(details::g_gl_context);
		details::g_gl_context = NULL;
		SDL_DestroyWindow(details::g_window);
		details::g_window = NULL;
		return false;
	}

	s_uniform_mat4[UNIFORM_MODEL_MATRIX] = glm::mat4(1.0f);
	s_uniform_mat4[UNIFORM_VIEW_MATRIX] = glm::mat4(1.0f);
	s_uniform_mat4[UNIFORM_PROJECTION_MATRIX] = glm::frustum(-1.0f, 1.0f, -1.0f, 1.0f, 0.5f, 999.0f);

	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

	init_test();

	return true;
}
Beispiel #14
0
static int
draw_init(struct render_command * __rcmd)
{
	struct rcmd_draw * rcmd =
		container_of(__rcmd, struct rcmd_draw, base);
	FORCE(SYSTEM, "Draw init\n");

	rcmd->vertex_shader = compile_shader(GL_VERTEX_SHADER,
			sizeof(vertex_shader) / sizeof(char*), vertex_shader);
	rcmd->fragment_shader = compile_shader(GL_FRAGMENT_SHADER,
			sizeof(fragment_shader) / sizeof(char*), fragment_shader);
	rcmd->program = init_program(
			rcmd->vertex_shader,
			rcmd->fragment_shader);

	GL_POP_ERROR();
	rcmd->idx_mv = glGetUniformLocation(rcmd->program, "iModelView");
	GL_POP_ERROR();
	rcmd->idx_tex = glGetUniformLocation(rcmd->program, "inTex");
	GL_POP_ERROR();
	rcmd->idx_position = glGetAttribLocation(rcmd->program, "iPosition");
	GL_POP_ERROR();
	rcmd->idx_texcoord = glGetAttribLocation(rcmd->program, "texCoord");
	GL_POP_ERROR();

//	rcmd->idx_color = glGetAttribLocation(rcmd->program, "iColor");
//	GL_POP_ERROR();
//	glVertexAttrib3f(rcmd->idx_color, 1.0f, 0.0f, 0.1f);
//	GL_POP_ERROR();

	load_identity(&rcmd->modelview);


	glGenBuffers(1, &rcmd->buffer);
	glBindBuffer(GL_ARRAY_BUFFER, rcmd->buffer);

	const GLfloat varray[] = {
		0.0, 0.0, 0.0, 0.0, 0.0,
		0.0, 1.0, 0.0, 0.0, 1.0,
		1.0, 1.0, 0.0, 1.0, 1.0,
		1.0, 0.0, 0.0, 1.0, 0.0,

		0.0, 0.0, 0.0, 0.0, 0.0,
		0.0, 1.0, 0.0, 0.0, 1.0,
		1.0, 1.0, 1.0, 1.0, 1.0,
		1.0, 0.0, 1.0, 1.0, 0.0,
	};

	glBufferData(GL_ARRAY_BUFFER, sizeof(varray), varray, GL_STATIC_DRAW);

	GL_POP_ERROR();

	res_id_t texres;
	char * fn = "common/rgb.png";
	texres = (uint64_t)(uint32_t)fn;
	struct rectangle rect = {
		0, 0, 64, 64
	};

	struct texture_params params = TEXTURE_PARAM_INIT;
	params.pin = TRUE;

	rcmd->tex = texgl_create(texres, rect, &params, NULL);
	GL_POP_ERROR();

	WARNING(SYSTEM, "tex->bitmap=%p\n", rcmd->tex->base.bitmap);
	if (rcmd->tex->base.bitmap != NULL)
		WARNING(SYSTEM, "tex->bitmap.refcount=%d\n", rcmd->tex->base.bitmap->base.ref_count);


	res_id_t texres2;
	char * fn2 = "common/rgb.png";
	texres2 = (uint64_t)(uint32_t)fn2;
	struct rectangle rect2 = {
		0, 0, 64, 64
	};
	struct texture_params params2 = TEXTURE_PARAM_INIT;
	struct texture_gl_params gl_params = TEXTURE_GL_PARAM_INIT;
	gl_params.mag_filter = GL_NEAREST;
	gl_params.min_filter = GL_NEAREST;
	rcmd->tex2 = texgl_create(texres, rect2, &params, &gl_params);
	GL_POP_ERROR();
	WARNING(SYSTEM, "tex2->bitmap=%p\n", rcmd->tex2->base.bitmap);
	if (rcmd->tex2->base.bitmap != NULL)
		WARNING(SYSTEM, "tex2->bitmap.refcount=%d\n", rcmd->tex2->base.bitmap->base.ref_count);
	return 0;
}
Beispiel #15
0
int main(int argc, char **argv)
{
  ROBOT_SPECIFICATIONS     robot_specifications_data;
  PROGRAM_STATE            program_state_data;
  ROBOT_STATE              robot_state_data;
  ACTION                   action_data;
  SENSATION                sensation_data;

  ROBOT_SPECIFICATIONS_PTR robot_specifications = &robot_specifications_data;
  PROGRAM_STATE_PTR        program_state        = &program_state_data;
  ROBOT_STATE_PTR          robot_state          = &robot_state_data;
  ACTION_PTR               action               = &action_data;
  SENSATION_PTR            sensation            = &sensation_data;

  struct timeval TCX_waiting_time = {0, 0};

  robot_specifications->is_initialized = 0;
  program_state->is_initialized        = 0;
  robot_state->is_initialized          = 0;
  action->is_initialized               = 0;
  sensation->is_initialized            = 0;
  allGlobal.is_initialized             = 0;

  signal(SIGTERM, &interrupt_handler); /* kill interupt handler */
  signal(SIGINT,  &interrupt_handler); /* control-C interupt handler */
#if 0
  signal(SIGALRM, &alarm_handler);	/* handler for regular interrupts */
#endif  

  bParamList = bParametersAddEntry(bParamList, "robot", "name", "B21");
  bParamList = bParametersAddEntry(bParamList, "", "TCXHOST", "localhost");
  bParamList  = bParametersAddEntry(bParamList, "", "fork", "yes");

  /* add some parameter files */
  bParamList = bParametersAddFile (bParamList, "etc/beeSoft.ini");

  /* add some enviroment variables */
  bParamList = bParametersAddEnv(bParamList, "", "TCXHOST");

  bParamList = bParametersAddArray(bParamList, "", argc, argv);

  bParametersFillParams(bParamList);

  check_commandline_parameters(argc, argv, ALL);
  init_program(ALL);
  if (!load_parameters(RHINO_INIT_NAME, ALL))
    exit(-1);
  allocate_memory(ALL);
  /*save_parameters(RHINO_INIT_NAME, ALL);*/
  init_graphics(ALL);
  connect_to_tcx(ALL);
  G_display_switch(TITLE_BUTTON, 1);
#if 0
  alarm((unsigned) robot_specifications->alarm_interval); /* set up alarm */
#endif
  tcx_reset_joystick(ALL); 


  for (;!program_state->quit;){
    program_state->something_happened = 0;
    
    if (program_state->tcx_autoconnect)
      connect_to_tcx(ALL);

    if (test_mouse(ALL))       program_state->something_happened = 1;
    
    if (refresh_action(ALL))   program_state->something_happened = 1;

    if (initiate_action(ALL))  program_state->something_happened = 1;

    /* if (terminate_action(ALL)) program_state->something_happened = 1; */
    

    if (program_state->tcx_initialized){
      TCX_waiting_time.tv_sec   = 0;
      TCX_waiting_time.tv_usec  = 0;
      tcxRecvLoop((void *) &TCX_waiting_time);
    }

    if (!program_state->something_happened){
      block_waiting_time.tv_sec  = 1;
      block_waiting_time.tv_usec = 0;
      block_wait(&block_waiting_time, program_state->tcx_initialized,
		 program_state->graphics_initialized);  
    }

#ifdef TOURGUIDE_VERSION
    tourguide_check_for_timeout(ALL);
#endif /* TOURGUIDE_VERSION */

  }



  /* close_log_file(ALL);*/
  /*  if (program_state->tcx_initialized)
      tcxCloseAll();*/
  G_display_switch(TITLE_BUTTON, 2);
  fprintf(stderr, "\nGood-bye.\n");
  sleep(1);
  exit(0);

}
DFBResult
gles2_init_shader_programs(GLES2DeviceData *dev)
{
     int i;
     GLuint prog;
     DFBBoolean status;

     D_DEBUG_AT(GLES2__2D, "%s()\n", __FUNCTION__);

     /*
      * First initialize program info slots to invalid values.
      */
     for (i = 0; i < GLES2_NUM_PROGRAMS; i++) {
          dev->progs[i].obj          =  0;
          dev->progs[i].dfbScale     = -1;
          dev->progs[i].dfbROMatrix  = -1;
          dev->progs[i].dfbMVPMatrix = -1;
          dev->progs[i].dfbColor     = -1;
          dev->progs[i].dfbColorkey  = -1;
          dev->progs[i].dfbTexScale  = -1;
          dev->progs[i].dfbSampler   = -1;
          dev->progs[i].v_flags      =  0;
          dev->progs[i].name         = "invalid program";
     }

     /*
      * draw_program transforms a vertex by the current model-view-projection
      * matrix and applies a constant color to all fragments.
      */
     prog = glCreateProgram();
     status = init_program(prog, "draw_vert", draw_vert_src,
                           "draw_frag", draw_frag_src, DFB_FALSE);
     if (status) {
          dev->progs[GLES2_DRAW].obj = prog;
          dev->progs[GLES2_DRAW].name = "draw";

          GET_UNIFORM_LOCATION(dev, GLES2_DRAW, dfbColor);
          GET_UNIFORM_LOCATION(dev, GLES2_DRAW, dfbScale);

          D_DEBUG_AT(GLES2__2D, "-> created draw_program\n");
     }
     else {
          D_ERROR("GLES2/Driver: draw_program init failed!\n");
          goto fail;
     }

     prog = glCreateProgram();
     status = init_program(prog, "draw_vert_mat", draw_vert_mat_src,
                           "draw_frag", draw_frag_src, DFB_FALSE);
     if (status) {
          dev->progs[GLES2_DRAW_MAT].obj = prog;
          dev->progs[GLES2_DRAW_MAT].name = "draw_mat";

          GET_UNIFORM_LOCATION(dev, GLES2_DRAW_MAT, dfbColor);
          GET_UNIFORM_LOCATION(dev, GLES2_DRAW_MAT, dfbROMatrix);
          GET_UNIFORM_LOCATION(dev, GLES2_DRAW_MAT, dfbMVPMatrix);

          D_DEBUG_AT(GLES2__2D, "-> created draw_mat_program\n");
     }
     else {
          D_ERROR("GLES2/Driver: draw_mat_program init failed!\n");
          goto fail;
     }

     /*
      * blit_program transforms a vertex by the current model-view-projection
      * matrix, applies texture sample colors to fragments.
      */
     prog = glCreateProgram();
     status = init_program(prog, "blit_vert", blit_vert_src,
                           "blit_frag", blit_frag_src, DFB_TRUE);
     if (status) {
          dev->progs[GLES2_BLIT].obj = prog;
          dev->progs[GLES2_BLIT].name = "blit";

          GET_UNIFORM_LOCATION(dev, GLES2_BLIT, dfbScale);
          GET_UNIFORM_LOCATION(dev, GLES2_BLIT, dfbTexScale);
          GET_UNIFORM_LOCATION(dev, GLES2_BLIT, dfbSampler);

          // For now we always use texture unit 0 (GL_TEXTURE0).
          glUniform1i(dev->progs[GLES2_BLIT].dfbSampler, 0);

          D_DEBUG_AT(GLES2__2D, "-> created blit_program\n");
     }
     else {
          D_ERROR("GLES2/Driver: blit_program init failed!\n");
          goto fail;
     }

     prog = glCreateProgram();
     status = init_program(prog, "blit_vert_mat", blit_vert_mat_src,
                           "blit_frag", blit_frag_src, DFB_TRUE);
     if (status) {
          dev->progs[GLES2_BLIT_MAT].obj = prog;
          dev->progs[GLES2_BLIT_MAT].name = "blit_mat";

          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_MAT, dfbROMatrix);
          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_MAT, dfbMVPMatrix);
          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_MAT, dfbTexScale);
          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_MAT, dfbSampler);

          // For now we always use texture unit 0 (GL_TEXTURE0).
          glUniform1i(dev->progs[GLES2_BLIT_MAT].dfbSampler, 0);

          D_DEBUG_AT(GLES2__2D, "-> created blit_mat_program\n");
     }
     else {
          D_ERROR("GLES2/Driver: blit_mat_program init failed!\n");
          goto fail;
     }

     /*
      * blit_color_program transforms a vertex by the current model-view-projection
      * matrix, applies texture sample colors to fragments, and modulates the
      * colors with a static RGBA color.  Modulation is effectively disabled
      * by setting static color components to 1.0.
      */
     prog = glCreateProgram();
     status = init_program(prog, "blit_color_vert", blit_vert_src,
                           "blit_color_frag", blit_color_frag_src, DFB_TRUE);
     if (status) {
          dev->progs[GLES2_BLIT_COLOR].obj = prog;
          dev->progs[GLES2_BLIT_COLOR].name = "blit_color";

          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_COLOR, dfbColor);
          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_COLOR, dfbScale);
          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_COLOR, dfbTexScale);
          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_COLOR, dfbSampler);

          // For now we always use texture unit 0 (GL_TEXTURE0).
          glUniform1i(dev->progs[GLES2_BLIT_COLOR].dfbSampler, 0);

          D_DEBUG_AT(GLES2__2D, "-> created blit_color_program\n");
     }
     else {
          D_ERROR("GLES2/Driver: blit_color_program init failed!\n");
          goto fail;
     }

     prog = glCreateProgram();
     status = init_program(prog, "blit_color_vert_mat", blit_vert_mat_src,
                           "blit_color_frag", blit_color_frag_src, DFB_TRUE);
     if (status) {
          dev->progs[GLES2_BLIT_COLOR_MAT].obj = prog;
          dev->progs[GLES2_BLIT_COLOR_MAT].name = "blit_color_mat";

          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_COLOR_MAT, dfbColor);
          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_COLOR_MAT, dfbROMatrix);
          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_COLOR_MAT, dfbMVPMatrix);
          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_COLOR_MAT, dfbTexScale);
          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_COLOR_MAT, dfbSampler);

          // For now we always use texture unit 0 (GL_TEXTURE0).
          glUniform1i(dev->progs[GLES2_BLIT_COLOR_MAT].dfbSampler, 0);

          D_DEBUG_AT(GLES2__2D, "-> created blit_color_mat_program\n");
     }
     else {
          D_ERROR("GLES2/Driver: blit_color_mat_program init failed!\n");
          goto fail;
     }

     /*
      * blit_colorkey_program does the same as blit_program with the addition
      * of source color keying.  Shaders don't have access to destination
      * pixels so color keying can be on the source only.
      */
     prog = glCreateProgram();
     status = init_program(prog, "blit_vert", blit_vert_src,
                           "blit_colorkey_frag", blit_colorkey_frag_src,
                           DFB_TRUE);
     if (status) {
          dev->progs[GLES2_BLIT_COLORKEY].obj = prog;
          dev->progs[GLES2_BLIT_COLORKEY].name = "blit_colorkey";

          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_COLORKEY, dfbColor);
          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_COLORKEY, dfbScale);
          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_COLORKEY, dfbTexScale);
          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_COLORKEY, dfbSampler);
          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_COLORKEY, dfbColorkey);

          // For now we always use texture unit 0 (GL_TEXTURE0).
          glUniform1i(dev->progs[GLES2_BLIT_COLORKEY].dfbSampler, 0);

          D_DEBUG_AT(GLES2__2D, "-> created blit_colorkey_program\n");
     }
     else {
          D_ERROR("GLES2/Driver: blit_colorkey_program init failed!\n");
          goto fail;
     }

     prog = glCreateProgram();
     status = init_program(prog, "blit_vert_mat", blit_vert_mat_src,
                           "blit_colorkey_frag", blit_colorkey_frag_src,
                           DFB_TRUE);
     if (status) {
          dev->progs[GLES2_BLIT_COLORKEY_MAT].obj = prog;
          dev->progs[GLES2_BLIT_COLORKEY_MAT].name = "blit_colorkey_mat";

          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_COLORKEY_MAT, dfbColor);
          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_COLORKEY_MAT, dfbROMatrix);
          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_COLORKEY_MAT, dfbMVPMatrix);
          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_COLORKEY_MAT, dfbTexScale);
          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_COLORKEY_MAT, dfbSampler);
          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_COLORKEY_MAT, dfbColorkey);

          // For now we always use texture unit 0 (GL_TEXTURE0).
          glUniform1i(dev->progs[GLES2_BLIT_COLORKEY_MAT].dfbSampler, 0);

          D_DEBUG_AT(GLES2__2D, "-> created blit_colorkey_mat_program\n");
     }
     else {
          D_ERROR("GLES2/Driver: blit_colorkey_mat_program init failed!\n");
          goto fail;
     }

     /*
      * blit_premultiply_program does the same as blit_program with the
      * addition of pre-multiplication of the source frag color by the source
      * frag alpha.  Shaders don't have access to destination pixels so
      * pre-multiplication can be on the source only.
      */
     prog = glCreateProgram();
     status = init_program(prog, "blit_vert", blit_vert_src,
                           "blit_premultiply_frag", blit_premultiply_frag_src,
                           DFB_TRUE);
     if (status) {
          dev->progs[GLES2_BLIT_PREMULTIPLY].obj = prog;
          dev->progs[GLES2_BLIT_PREMULTIPLY].name = "blit_premultiply";

          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_PREMULTIPLY, dfbColor);
          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_PREMULTIPLY, dfbScale);
          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_PREMULTIPLY, dfbTexScale);
          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_PREMULTIPLY, dfbSampler);

          // For now we always use texture unit 0 (GL_TEXTURE0).
          glUniform1i(dev->progs[GLES2_BLIT_PREMULTIPLY].dfbSampler, 0);

          D_DEBUG_AT(GLES2__2D, "-> created blit_premultiply_program\n");
     }
     else {
          D_ERROR("GLES2/Driver: blit_premultiply_program init failed!\n");
          goto fail;
     }

     prog = glCreateProgram();
     status = init_program(prog, "blit_vert_mat", blit_vert_mat_src,
                           "blit_premultiply_frag", blit_premultiply_frag_src,
                           DFB_TRUE);
     if (status) {
          dev->progs[GLES2_BLIT_PREMULTIPLY_MAT].obj = prog;
          dev->progs[GLES2_BLIT_PREMULTIPLY_MAT].name = "blit_premultiply_mat";

          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_PREMULTIPLY_MAT, dfbColor);
          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_PREMULTIPLY_MAT, dfbROMatrix);
          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_PREMULTIPLY_MAT, dfbMVPMatrix);
          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_PREMULTIPLY_MAT, dfbTexScale);
          GET_UNIFORM_LOCATION(dev, GLES2_BLIT_PREMULTIPLY_MAT, dfbSampler);

          // For now we always use texture unit 0 (GL_TEXTURE0).
          glUniform1i(dev->progs[GLES2_BLIT_PREMULTIPLY_MAT].dfbSampler, 0);

          D_DEBUG_AT(GLES2__2D, "-> created blit_premultiply_mat_program\n");
     }
     else {
          D_ERROR("GLES2/Driver: blit_premultiply_mat_program init failed!\n");
          goto fail;
     }

     // No program is yet in use.
     dev->prog_index = GLES2_INVALID_PROGRAM;
     dev->prog_last  = GLES2_INVALID_PROGRAM;

     return DFB_OK;

     fail:
     // Delete all program objects.  glDeleteProgram() will ignore object id 0.
     for (i = 0; i < GLES2_NUM_PROGRAMS; i++)
          glDeleteProgram(dev->progs[i].obj);

     return DFB_INIT;
}