inigraph2.pp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. Program inigraph2;
  2. { Program to demonstrate dynamic graphics mode selection }
  3. uses graph;
  4. const
  5. TheLine = 'We are now in 640 x 480 x 256 colors!'+
  6. ' (press <Return> to continue)';
  7. var
  8. th,tw,gd, gm, lo, hi, error: integer;
  9. found: boolean;
  10. begin
  11. { We want an 8 bit mode }
  12. gd := D8bit;
  13. { Get all available resolutions for this bitdepth }
  14. getmoderange(gd,lo,hi);
  15. { If the highest available mode number is -1,
  16. no resolutions are supported for this bitdepth }
  17. if hi = -1 then
  18. begin
  19. writeln('no 8 bit modes supported!');
  20. halt
  21. end;
  22. found := false;
  23. { Search all resolutions for 640x480 }
  24. for gm := lo to hi do
  25. begin
  26. initgraph(gd,gm,'');
  27. { Make sure you always check graphresult! }
  28. error := graphResult;
  29. if (error = grOk) and
  30. (getmaxx = 639) and (getmaxy = 479) then
  31. begin
  32. found := true;
  33. break;
  34. end;
  35. end;
  36. if not found then
  37. begin
  38. writeln('640x480x256 is not supported!');
  39. halt(1)
  40. end;
  41. { We are now in 640x480x256 }
  42. setColor(cyan);
  43. rectangle(0,0,getmaxx,getmaxy);
  44. { Write a nice message in the center of the screen }
  45. setTextStyle(defaultFont,horizDir,1);
  46. TW:=TextWidth(TheLine);
  47. TH:=TextHeight(TheLine);
  48. outTextXY((getMaxX - TW) div 2,
  49. (getMaxY - TH) div 2,TheLine);
  50. { Wait for return }
  51. readln;
  52. { Back to text mode }
  53. closegraph;
  54. end.