PDA

View Full Version : chckn crossin d road



angel111
04-20-2011, 07:58 AM
hi frenz...m a beginner wid opengl doin my projct...game'"chckn crossin d road"

1.hav writtn code for road,cars,chckn n worm
2.bt unable to bring thm on same screen



pls help me:(:(((((

angel111
04-20-2011, 08:05 AM
here s my code for road



#include<stdio.h>
#include<GL/glut.h>
#include<windows.h>
#include<fstream.h>
#include<iostream.h>
#include<stdlib.h>




void Init()
{
glClearColor(0.0,0.8,0.0,0.0);
gluOrtho2D(0.0,50.0,0.0,50.0);
glEnable(GL_BLEND);
}


void drawPL(char * f1)
{
fstream inStream;
inStream.open(f1,ios::in);
if(inStream.fail())
return;
glClear(GL_COLOR_BUFFER_BIT);
GLfloat numpolys,numLines,x,y;
inStream>>numpolys;
for(int j=0;j<numpolys;j++)
{
inStream>>numLines;
glColor3f(1.0,0.5,0.0);
glBegin(GL_LINE_STRIP);
for(int i=0;i<numLines;i++)
{
inStream>>x>>y;
glVertex2f(x,y);
}
glEnd();
}
glFlush();
inStream.close();
}




void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glLineWidth(4);
drawPL("f2.dat");
glPointSize(6.0);
glBegin(GL_POINTS);
glColor3f(1.0,1.0,1.0);
glVertex2f(32.5,45);
glVertex2f(34,45);
glEnd();
glPointSize(4.0);
glBegin(GL_POINTS);
glColor3f(0.0,0.0,0.0);
glVertex2f(32.5,45);
glVertex2f(34,45);
glEnd();


glBegin(GL_POLYGON);


glColor3f(0.5,0.5,0.5);

glVertex2i(0,12);
glVertex2i(50,12);
glVertex2i(50,38);
glVertex2i(0,38);
glEnd();

glBegin(GL_POLYGON);
glColor3f(1.0,1.0,0.0);
glVertex2i(0,25);
glVertex2i(50,25);
glVertex2i(50,24);
glVertex2i(0,24);
glEnd();



glColor3f (1.0, 1.0, 1.0);
glEnable (GL_LINE_STIPPLE);
glLineWidth (6.0);
glLineStipple (4, 0x00FF); /* dotted */

glBegin(GL_LINES);
glColor3f(1.0,1.0,1.0);
glVertex2f (0.0,18.5);
glVertex2f (50.0,18.5);
glVertex2f(0.0,31.5);
glVertex2f(50.0,31.5);
glEnd();
glFlush();
glutSwapBuffers();
}




void main(int argc,char **argv)
{
glutInit(&amp;argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("CRAZY CHICKEN");
glutDisplayFunc(display);
Init();
glutMainLoop();
}

BionicBytes
04-20-2011, 08:14 AM
Rather than just posting "please help" or "please do my home work for me", why not actually take the time to describe what is not working for you, and try and pin down where in your code you think the problem lies.
Thinking for yourself in this way often helps you debug your code and you don't actually need to post any questions.

As it stands we can't or won't help because your question is to general.

angel111
04-20-2011, 08:16 AM
f3.dat

7
5
2 18
9 18
9 21
2 21
2 18

5
3 19
8 19
8 20
3 20
3 19

2
2 18
3 19


2
9 18
8 19

2
9 21
8 20

2
2 21
3 20

4
9 18
10 19
10 20
9 21

angel111
04-20-2011, 08:17 AM
d problm s.... file f3.dat has points for a car shape....it works wen calld in a seperate progrm bt its nt being displayd on d road wen included in my program...

BionicBytes
04-20-2011, 08:22 AM
...and you think the contents of f3.dat is going to mean anything to anyone here?

I think you are making all sorts of assumptions about what system you are devoping on and assume everyone else is using the same.

_arts_
04-20-2011, 08:26 AM
glUnseparateProgram ("car.exe", "road.exe", "chicken.exe");
glCompile();
glRunChickenOnTheRoad();
glBeCarefulOfTheCarPoorChicken();
glDestroyBloodyChicken();
...

angel111
04-20-2011, 08:30 AM
m clearly tellin...m unable to display car on d road....

angel111
04-20-2011, 08:34 AM
OMG!! dat f3.dat file has coordinates of a car....
m workin wid MSvisualstudioC++......copy f3.dat n execute d main program....u vl knw my problem

angel111
04-20-2011, 08:36 AM
#include<stdio.h>
#include<GL/glut.h>
#include<windows.h>
#include<fstream.h>
#include<iostream.h>
#include<stdlib.h>




void Init()
{
glClearColor(0.5,0.5,0.5,0.0);
gluOrtho2D(0.0,50.0,0.0,50.0);
glEnable(GL_BLEND);

}









void drawcar(char * f1)
{
fstream inStream;
inStream.open(f1,ios::in);
if(inStream.fail())
return;
glClear(GL_COLOR_BUFFER_BIT);
GLfloat numpolys,numLines,x,y;
inStream>>numpolys;
for(int j=0;j<numpolys;j++)
{
inStream>>numLines;
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINE_STRIP);
for(int i=0;i<numLines;i++)
{
inStream>>x>>y;
glVertex2f(x,y);
}
glEnd();
}
glFlush();
inStream.close();
}



void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glLineWidth(4);
drawcar("f3.dat");
glColor3f(1.0,1.0,0.0);
glPointSize(4.0);
glBegin(GL_POINTS);
glVertex2f(10,19);
glVertex2f(10,20);
glEnd();
glColor3f(0.0,0.0,0.0);
glPointSize(8.0);
glBegin(GL_POINTS);
glVertex2f(3,18);
glVertex2f(7,18);
glVertex2f(3,21);
glVertex2f(7,21);
glEnd();
glFlush();
}




void main(int argc,char **argv)
{
glutInit(&amp;argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(1024,768);
glutInitWindowPosition(0,0);
glutCreateWindow(" crazy chicken");
glutDisplayFunc(display);

Init();
glutMainLoop();
}

angel111
04-20-2011, 08:37 AM
hey bionicbytes........execute d above prog once

BionicBytes
04-20-2011, 08:42 AM
....and what happened?

angel111
04-20-2011, 08:44 AM
i want to include dis car with d road program which i hav posted earlier...wht shud i do??

BionicBytes
04-20-2011, 09:00 AM
read the files for each model as you did. Encapsulate each bunch of glVertex2f commands into a display list (google that if you don't know how).
Now you can draw many chickens and many cars since each is drawn with a single glCallLists command.

Looks like you are trying to run before you can walk. try a OpenGL tutorial site like HeNE (google it) and learn by example.

angel111
04-20-2011, 09:04 AM
ok thank u BB