Need some help getting started
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
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
Hope I helped at all,
Martin
______________Martin EstevaolpSoftware
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
- Hobobo
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
#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
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
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

Hargle
Hargle
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement