Jump to content
  • Advertisement


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


Writing Tetris in C --Graphics?

This topic is 5774 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

Hello people, I''m a new guy here I''ve been studying C and M68k ASM the past year (Created "Snake" in ASCII-mode for a terminal using M68k-CPU, coooool ) Anyway, I just started on writing Tetris in C, so I think it''s time for me to start learning some Graphics-programming in order to make a decent tetris-game. OpenGL is what I have in mind, as I''ve heard this would be the smartest way to go. I don''t have that much spare time at the moment, but I''ve had the time to read a bit about OpenGL, and it''s all still quite blurry for me, as I''m not used to all the Window-handles etc, as I haven''t been working with Win32API and such that much. As said, the game that I''m writing is so far completely in C (had an OOP-course, examples in Java, so I''m not that used to C++ yet), and I''m wondering if the implementation of OpenGL would affect (m)any parts of the current code, except for moving everything into an Win32-app? (Working with MSVS6, so no probs there). So I''m thinking that the changes that needs to be done are the following: Setting the init-code for OpenGL, putting an OpenGL call into the current while(player != DEAD); Write that very OpenGL-function: drawGraphics(&matrix); And then I''m all set? I''ve heard of a framework for OpenGL called "Glut" which appearently makes it easier to use OpenGL for purposes like this. I wonder if anybody could help me implement this to the game when I reach this stage, ie. finalizing the game together, as I think this is the best way for me to learn the most important parts of OpenGL the easiest way (I don''t have that much spare time, and reading something that you just have to "accept" isn''t fun). This way I''d learn how everything in the application works, and why. It would be fantastic, thanks It''s midnight here, so I''m off to bed, goodnight /Caminman

Share this post

Link to post
Share on other sites
If you are going to make Tetris, I think that you would really enjoy Simple DirectMedia Layer (SDL). It is a C API that works on Windows, Linux, MacOS, and other platforms. It is very simple and straight forward. SDL is mainly a library for 2D applications, but it can do audio and input among other things.

When you are ready to move up to OpenGL but do not want to deal with the complex Windows API and WGL, then you can use SDL to setup OpenGL, kind of like GLUT. The difference between GLUT and SDL for setting up OpenGL is that GLUT is mainly for beginners: it doesn''t have much flexibility, where SDL is easy for beginners and is also great for industrial-strength programs.

SDL is very simple, and you should be able to get the hang of it within a few hours (or minutes). It is a great portable library for 2D graphics, sound, music, input, and setting up OpenGL. Good luck.

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
if u want to learn OpenGL I suggest the tutorials at http://nehe.gamedev.net

Share this post

Link to post
Share on other sites
People doesn't seem to be able to agree on SDL/Allegro. What are the differences, and which one should I start out with, and why?


[edited by - Caminman on January 25, 2003 8:17:35 PM]

Share this post

Link to post
Share on other sites
Tetris with DirextX by Pouya:

/* Super-compressed Tetris. Copyright 2001 Pouya Larjani. Please don't remove.*/
#include <ddraw.h>
#define B(x,y,r,p) (p&1<<(((x^(r+1&2?3:0))<<(r*2&2))+((y^(r&2?3:0))*(r&1?1:4))))
#define F(x,y,w,h,c) {RECT R={x,y,x+w,y+h};b.dwFillColor=c;_->Blt(&R,0,0,k,&b);}
typedef int E;char*m="TetrisBy Pouya LarjaniScore:Next:GAME OVER",z[9];E L=16,k=
HWND W;LOGFONT l={96,48};MSG g;DDSURFACEDESC S={108,33,0,0,0,1,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0,0,{536}};HFONT f=CreateFontIndirect(&l);DDSCAPS c={4};K(E v
){return GetAsyncKeyState(v)&32768;}X(){for(i=1;i<30;i++){a=1;for(I=0;I<20&&a;a=
1;}}return 0;}M(E p){return(++p<<21&1<<23|p<<14&1<<15|p<<7&1<<7)+8355711;}O(E x,
E y,E r,E p){for(I=0;I<L;I++)if(B(I%4,I/4,r,P[p])&&(x+I%4<0||x+I%4>19||y+I/4<0||
y+I/4>29||s[y+I/4][x+I%4]))return 0;return 1;}void G(){DispatchMessage(&g);v=r;t
,u,v,p))x=t,y=u,r=v;else if(u-y){for(I=0;I<L;I++)if(B(I%4,I/4,r,P[p]))s[y+I/4][x
]=1<<23;y?p=n,y=0,n=rand()%7,x=9,r=0:Q=0;while(X());}}void R(){F(0,0,640,480
);V->Flip(0,1);}WINAPI WinMain(HINSTANCE h,HINSTANCE,char*,E){srand(timeGetTime(
));WNDCLASS w={0,DefWindowProc,0,0,h,0,0,0,0,m};RegisterClass(&w);W=CreateWindow
18)PeekMessage(&g,0,0,0,1)?G():R();DestroyWindow(W);DeleteObject(f);return I=0;}

[edited by - elcrazon on January 25, 2003 11:29:29 PM]

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!