Moving Sun behind Mountains

Hello there
i use Graphic library and draw mountains and sun. i want move sun behind mountains and come out. but i have prob for that, because sun come front of mountains and i don't know what i must do!!
please help me.
Make sure the sun is drawn before the mountains?

-Albatross
yea did it.first: saved moutanis in "*buffer_Mountains" by GetImage And Sun in "*buffer_sun".
finally by Putimage and For ... printing on screen. but i had that prob!!!
Help me plz. i'm waiting
Is the sun nearer than the moutains?

turn off depth buffer writes, draw the sun. turn on depth buffer writes, draw the rest of the scene.

just guessing - you are not providing much information
yea.
u can see my draw at here:

http://www.mediafire.com/?zobum24kagh1x8n

plz dl and reply me.i'm waiting
That site is blocked by my works fanatical web-police!

Here's is how the proposed fix works.

At the beginning of drawing a frame you clear the buffers (image to background colour, depth buffer to farthest distance)

You turn off depth buffer writes and draw the sun. This puts the pixels in the image buffer but the depth buffer remains at farthest distance.

Then turn depth buffer writes back on and draw the rest - they should all be in front of the sun.

I don't know the syntax details of the system you are using for doing this - thats up to you
Last edited on
The code for those of you unable to download:

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
#include<dos.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<alloc.h>
#include<graphics.h>
int main()
{
clrscr();
  int driver=DETECT,mode=0;
  int i,j=30,k=40,p;
  unsigned size;
  void *buffer;
  char shape[]={0,255,253,1,4,10,255,100};
  char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x25, 0x27, 0x04, 0x04};
  int a[6]={400,100,420,120,400,150};
  initgraph(&driver,&mode,"");
  setbkcolor(CYAN);
  //jade
  setcolor(8);
  setfillstyle(1,8);
  rectangle(0,300,800,460);
  floodfill(2,352,8);
  // Khatkeshi
  setcolor(WHITE);
  setfillstyle(1,WHITE);
  rectangle(30,375,110,385);
  rectangle(160,375,240,385);
  rectangle(290,375,370,385);
  rectangle(420,375,500,385);
  rectangle(550,375,630,385);
  floodfill(31,376,WHITE);
  floodfill(161,376,WHITE);
  floodfill(291,376,WHITE);
  floodfill(421,376,WHITE);
  floodfill(552,376,WHITE);
  //Tablo ha
   setcolor(WHITE);
   setfillstyle(1,WHITE);
   bar3d(490,270,500,295,3,2);
   setfillstyle(1,2);
   bar3d(430,270,560,250,4,3);
   setcolor(WHITE);
   settextstyle(20,HORIZ_DIR,1);
   outtextxy(433,255,"Jahrom--> 120km");
   //koh
   setcolor(BROWN);
   setfillstyle(1,BROWN);
      pieslice(0,21,210,332,57);
      pieslice(190,21,210,332,57);
      pieslice(490,21,210,332,57);
      pieslice(90,21,210,332,57);
      pieslice(290,21,210,332,57);
      pieslice(390,21,210,332,57);
      pieslice(590,21,210,332,57);
//barf
      setfillstyle(1,WHITE);
       pieslice(90,21,210,332,15);
      setfillstyle(1,WHITE);
       pieslice(490,21,210,332,15);
       pieslice(190,21,210,332,15);
  //Sun
  setcolor(YELLOW);
  setfillstyle(1,YELLOW);
//  pieslice(440,60,33,360,20);
  circle(440,50,20);
  floodfill(440,49,YELLOW);

/*size=imagesize(30,250,250,400);
buffer=malloc(size);
for(i=1;i<=550;i++)
{
getimage(0+i,316,249+i,365,buffer);
putimage(0+i+1,316,buffer,0);
}*/

getch();
}



Personally I wouldn't touch this code with a 10 foot pole. dos.h? graphics.h? Is this 1994?

If you want to do graphics, get a graphic lib. You're just making things hard on yourself by doing this. Obligatory link:

http://cplusplus.com/forum/articles/28558/
Topic archived. No new replies allowed.