Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Hobobo

Need some help getting started

This topic is 6728 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Could someone show me some code that I can copy and paste into my compiler that moves a little circle across the screen or something very simple? - Hobobo

Share this post


Link to post
Share on other sites
Advertisement
No offense or anything, but why don''t you try to do it yourself? If you just copied and pasted code, you wouldn''t feel that you''ve accomplished anything and you would know that you didn''t learn anything. Find a Directdraw tutorial and learn the basics. Find out how to draw a circle (or a bitmap of a circle, whichever) on the screen and manipulate it by changing the coordinates when bouncing of the sides of the screen, etc. Believe me, even when you get this simple effect, you''ll feel happy that you figured it out after a long time of learning.

Hope I helped at all,
Martin

Share this post


Link to post
Share on other sites
I know, I''ve tried that. However, after a weekend of searching what I basicly found was that with most tutorials, I can understand most of the code, but I don''t know what it''s supposed to look like.

- Hobobo

Share this post


Link to post
Share on other sites
This code is for VC++ 6.0 and uses opengl for rendering, to compile it make sure you link to opengl32.lib, glut32.lib, and glut32.lib

#include
#include

GLfloat xstep = 1.0f;
GLfloat ystep = 2.0f;

GLfloat windowWidth;
GLfloat windowHeight;

GLfloat x1 = 100.0f;
GLfloat y1 = 150.0f;

void SetupRC(void)
{
glClearColor(0.0f,0.0f,1.0f,1.0f);

glShadeModel(GL_FLAT);
glFrontFace(GL_CCW);

glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
}

void RenderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT / GL_DEPTH_BUFFER_BIT);

glColor3f(0.0f,0.0f,0.0f);

glBegin(GL_TRIANGLE_FAN);
glVertex2f(x1+5,y1+10);
glVertex2f(x1,y1);
glVertex2f(x1+10,y1);

glColor3f(1.0f,1.0f,0.0f);
glVertex2f(x1+15,y1+10);

glColor3f(0.0f,0.0f,0.0f);
glVertex2f(x1+10,y1+20);

glColor3f(1.0f,1.0f,0.0f);
glVertex2f(x1,y1+20);

glColor3f(0.0f,0.0f,0.0f);
glVertex2f(x1-5,y1+10);

glColor3f(1.0f,1.0f,0.0f);
glVertex2f(x1,y1);
glEnd();

glutSwapBuffers();
}

void ChangeSize(GLsizei w, GLsizei h)
{
if(h == 0)
h = 1;

glViewport(0,0,w,h);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

if(w <= h)
{
windowHeight = 250.0f * h/w;
windowWidth = 250.0f;
}
else
{
windowWidth = 250.0f * w/h;
windowHeight = 250.0f;
}

glOrtho(0.0f,windowWidth,0.0f,windowHeight, 1.0f,-1.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void TimerFunc(int value)
{


if( (x1+15) > windowWidth // x1 - 5 < 0)
xstep = -xstep;
if( (y1+20) > windowHeight // y1 < 0)
ystep = -ystep;

if(x1 > windowWidth)
x1 = windowWidth - 1;
if(y1 > windowHeight )
y1 = windowHeight - 1;

x1 += xstep;
y1 += ystep;

glutPostRedisplay();

glutTimerFunc(40,TimerFunc,1);
}

void main(void)
{
glutInitDisplayMode(GLUT_DOUBLE / GLUT_RGB);
glutCreateWindow("Radioactive");
glutInitWindowPosition(100,100);

glutDisplayFunc(RenderScene);
glutReshapeFunc(ChangeSize);
glutTimerFunc(40,TimerFunc,1);

SetupRC();

glutMainLoop();
}

xDS4Lx

Share this post


Link to post
Share on other sites
I recommend a book such as Andre LaMothe''s Tricks of the windows gam programming Guru''s. It''s got everything you shouldneed to know about making games with directX and the logic (collision detection, AI, etc) can be aplied to any API (such as openGL) meaning all you have to do is learn the graphics functions after that to use other than DX. It''s a very good book

Hargle

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!