1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
| //M1AIN FILE
//BitMap Structure
struct A{
char type[2]; /* Magic identifier */
unsigned long size; /* File size in bytes */
unsigned short int reserved1, reserved2;
unsigned long offset; /* Offset to image data, bytes */
};
A HEADER,HEADER1;
struct B{
unsigned long size; /* Header size in bytes */
unsigned long width,height; /* Width and height of image */
unsigned short int planes; /* Number of colour planes */
unsigned short int bits; /* Bits per pixel */
unsigned long compression; /* Compression type */
unsigned long imagesize; /* Image size in bytes */
unsigned long xresolution,yresolution; /* Pixels per meter */
unsigned long ncolours; /* Number of colours */
unsigned long importantcolours; /* Important colours */
};
B INFOHEADER,INFOHEADER1;
#include<iostream.h>
#include<graphics.h>
#include<fstream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
// This Global Function is used for the resolution of the bitmap. You can set the return value either 1,2 or 3. For me 3 is the best combination.
int XCor=0;
int YCor=0;
huge DetectSvga()
{
return 3;
}
void Show()
{
fstream File;
//Here you have to define the path of the bitmap file. Like according to this example i have to open one Board1.bmp file. So write you bitmap file path here.
File.open("C:\\bitmaps\\1-4\\1st.bmp",ios::in);
unsigned char Ch;
File.read((char*)&HEADER,14); //This is the header part of the Bitmap. It always looks like same. Don't change the content hear. The value remains 14 here.
File.read((char*)&INFOHEADER,40); //This is another part of the bitmap, here also the value remains same like 40 here.
unsigned int i;
char ColorBytes[4];
char*PaletteData;
PaletteData=new char[256*3];
if(PaletteData)//if memory allocated successfully
{
//read color data
for(i=0;i<256;i++)
{
//Don't change the code here because i have done some shifting here. Its working fine.
File.read(ColorBytes,4);
PaletteData[(int)(i*3+2)]=ColorBytes[0]>>2;
PaletteData[(int)(i*3+1)]=ColorBytes[1]>>2;
PaletteData[(int)(i*3+0)]=ColorBytes[2]>>2;
}
outp(0x03c8,0); //tell DAC that data is coming
for(i=0;i<256*3;i++) //send data to SVGA DAC
{
outp(0x03c9,PaletteData[i]);
}
delete[]PaletteData;
}
for(i=0;i<INFOHEADER.height;i++) //This for loop is used to display the bitmap.
{
for(int j=0;j<INFOHEADER.width;)
{
File.read(&Ch,1); // Here Ch reads the color of your bitmap.
putpixel(XCor+j++,YCor+INFOHEADER.height-i-1,Ch); //XCor and YCor are the X and Y cordinates. It depends upon you.
}
}
File.close();
}
#include <graphics.h>
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <dos.h>
#include <stdio.h>
void Menu (int x, int y)
{
rectangle (x + 30, y + 30, x + 160, y + 80);
}
void paint_menu (int x, int y, int count)
{
setcolor(3);
for (int i = 0; i < count; i++)
{
Menu (x + i * 100, y - 100);
}
}
void paint_menu_name_game (int x, int y, char *name_game[])
{
setcolor (15);
settextstyle (10, 0, 8);
for (int i = 0; i < 1; i++)
{
outtextxy (x + i * 100 + 45, y + 20, name_game[i]);
}
}
void paint_menu_text (int x, int y, char *PLAY[], char *HELP[], char *QUIT[])
{
setcolor (4);
settextstyle (10, 0, 4);
for (int i = 0; i < 1; i++)
{
outtextxy (x + i * 150 + 330, y + 250, PLAY[i]);
outtextxy (x + i * 160 + 334, y + 350, HELP[i]);
outtextxy (x + i * 170 + 337, y + 450, QUIT[i]);
}
}
int move_menu (int x, int y, int count)
{
int count_menu = 0;
char c = 0;
count--;
setcolor(7);
{Menu(x + 295, y + 235);
setcolor(0);}
while (c != 13)
{
c = getch();
if (!c) c += getch();
switch (c)
{
case 80:
{
if (count_menu == count) count_menu = 0;
else count_menu++;
setcolor (7);
y = count_menu * 100 + 10;
Menu (x + 295, y + 226);
if (count_menu > 0)
{
setcolor (0);
Menu (x + 295, y + 126);
}
else
{
setcolor (0);
Menu (x + 295, y + 426);
}
break;
} // move down
}
}
return count_menu;
}
int main()
{
int x = 1;
int y = 1;
int count = 3;
char *PLAY[] = {"PLAY\0"};
char *HELP[] = {"HELP\0"};
char *EXIT[] = {"QUIT\0"};
char *name_game[] = {"NU,POGODI!\0"};
int gd = DETECT, md, a;
installuserdriver("SVGA256",&DetectSvga);
initgraph(&gd,&md,"C:\\TC\\BGI"); //Path may be different in your computer.
int count_menu;
paint_menu (x, y, count);
paint_menu_name_game (x, y, name_game);
paint_menu_text (x, y, PLAY, HELP, EXIT);
count_menu = move_menu (x, y, count);
Show();
setcolor (4);
settextstyle (1, 0, 3);
char *s;
sprintf (s, "%d", count_menu);
outtextxy (200, 200, s); //outtext(0,1,2)
setcolor (6);
getch();
closegraph();
return 0;
} |