السلام عليكم
السلام عليكم بتمنى تساعدوني اريد مشروع لعبة tic tac toi باستخدام open gl
شكرا
السلام عليكم
السلام عليكم بتمنى تساعدوني اريد مشروع لعبة tic tac toi باستخدام open gl
شكرا
اقتباسالسلام عليكم بتمنى تساعدوني اريد مشروع لعبة tic tac toi باستخدام open glشكرا
فيما تريد المساعدة حدد نوع المساعدة التي تريدها
ما هي المشكلة التي تواجهك .؟
bilal2005 كتب:فيما تريد المساعدة حدد نوع المساعدة التي تريدها
ما هي المشكلة التي تواجهك .؟
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <math.h>
int Matrix[3][3]={
{-1, -1, -1},
{-1, -1, -1},
{-1, -1, -1}
};
int nWidth;
int nHeight;
bool bXorO=false;
void DrawX(int x,int y);
void DrawO(int x,int y);
void reshape(int w,int h)
{
nWidth=w;
nHeight=h;
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glOrtho(0,800,800,0,800,0);
glViewport(0,0,w,h);
}
void display()
{
}
COORD GetMatrixIndex(int x,int y)
{
COORD point;
point.X=-1;
point.Y=-1;
int nBasePos=nWidth*1.0/8.0;
int XDis=(nWidth-2*nBasePos)/3;
int YDis=(nHeight-2*nBasePos)/3;
if(x>=nBasePos && x<=nBasePos+XDis)
point.X=0;
else if(x>=nBasePos+XDis && x<=nBasePos+2*XDis)
point.X=1;
else if(x>=nBasePos+2*XDis && x<=nBasePos+3*XDis)
point.X=2;
if(y>=nBasePos && y<=nBasePos+YDis)
point.Y=0;
else if(y>=nBasePos+YDis && y<=nBasePos+2*YDis)
point.Y=1;
else if(y>=nBasePos+2*YDis && y<=nBasePos+3*YDis)
point.Y=2;
return point;
}
void MouseFunction(int button, int state,int x, int y)
{
if(button== GLUT_LEFT_BUTTON)
{
if(state==GLUT_DOWN)
{
COORD coord= GetMatrixIndex(x,y);
if(coord.X==-1&&coord.Y==-1)
return;
if(Matrix[coord.X][coord.Y]==-1)
{
Matrix[coord.X][coord.Y]=bXorO;
bXorO=!bXorO;
}
}
}
}
void movie()
{
glClearColor(255,255,255,255);
glClear(GL_COLOR_BUFFER_BIT);//white background
glColor3f(1,0,0);
glLineWidth(3);
glBegin(GL_LINE_LOOP);
glVertex2i(100,100);
glVertex2i(700,100);
glVertex2i(700,700);
glVertex2i(100,700);
glEnd();
glBegin(GL_LINES);
glVertex2i(100,300);
glVertex2i(700,300);
glVertex2i(100,500);
glVertex2i(700,500);
glVertex2i(300,100);
glVertex2i(300,700);
glVertex2i(500,100);
glVertex2i(500,700);
glEnd();
for(int x=0;x<3;x++)
for(int y=0;y<3;y++)
{
if(Matrix[x][y]==0)
DrawX((x+1)*200,(y+1)*200);
else if(Matrix[x][y]==1)
DrawO((x+1)*200,(y+1)*200);
}
glutSwapBuffers();
}
void DrawX(int x,int y)
{
glColor3f(0,0,1);
glBegin(GL_LINES);
glVertex2i(x-70,y-70);
glVertex2i(x+70,y+70);
glVertex2i(x+70,y-70);
glVertex2i(x-70,y+70);
glEnd();
}
void DrawO(int x,int y)
{
glColor3f(0,0,1);
glBegin(GL_LINE_LOOP);
for(float f=0;f<3.14*2;f+=0.1)
glVertex2i(x+70*cos(f),y+70*sin(f));
glEnd();
}
void main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE);
glutInitWindowSize(600,600);
glutInitWindowPosition(0,0);
glutCreateWindow("glut window");
glutReshapeFunc(reshape);
glutMouseFunc(MouseFunction);
glutDisplayFunc(display);
glutIdleFunc(movie);
glutMainLoop();
}شكرا الك كتير بس هاد الكود بمثل اللعبه انا بصراحه مبتدأ على opengl بدي اعرف كيف بستخدم هيك استدعاءات وكيف بقدر اتواصل معك خاص؟وشكرا يا مبدع
حقيقتاً تعلم ال OpenGL ليس بالامر الصعب ولكنه يحتاج لان تدرس اساسيات هذه المكتبه (ليس بالضروره تعلم المكتبات المساعده glut او glaux يكفي قرائه القليل عنها).
اذا عندك اي استفسار يمكنك ارسال رسال لي حول الموضوع
الأخ الكريم/الأخت الكريمة
السلام عليكم ورحمة الله وبركاته
مرحباً بكم في منتدى الفريق العربي للبرمجة
نود تنبيهك أن العنوان غير مناسب.
الرجاء اختيار عنوان مناسب أكثر في مواضيعك القادمة، وهذا بمثابة إشعار للأهمية.
وفي حال التكرار سيتعرض موضوعك للإغلاق والحذف!!!
قواعد المشاركة
شاكرين لكم حُسن تعاونكم
hazzoom كتب:الأخ الكريم/الأخت الكريمة
السلام عليكم ورحمة الله وبركاته
مرحباً بكم في منتدى الفريق العربي للبرمجة
نود تنبيهك أن العنوان غير مناسب.
الرجاء اختيار عنوان مناسب أكثر في مواضيعك القادمة، وهذا بمثابة إشعار للأهمية.
وفي حال التكرار سيتعرض موضوعك للإغلاق والحذف!!!
قواعد المشاركة
شاكرين لكم حُسن تعاونكم
void display()
{
}
COORD GetMatrixIndex(int x,int y)
{
COORD point;
point.X=-1;
point.Y=-1;
int nBasePos=nWidth*1.0/8.0;
int XDis=(nWidth-2*nBasePos)/3;
int YDis=(nHeight-2*nBasePos)/3;
if(x>=nBasePos && x<=nBasePos+XDis)
point.X=0;
else if(x>=nBasePos+XDis && x<=nBasePos+2*XDis)
point.X=1;
else if(x>=nBasePos+2*XDis && x<=nBasePos+3*XDis)
point.X=2;
if(y>=nBasePos && y<=nBasePos+YDis)
point.Y=0;
else if(y>=nBasePos+YDis && y<=nBasePos+2*YDis)
point.Y=1;
else if(y>=nBasePos+2*YDis && y<=nBasePos+3*YDis)
point.Y=2;
return point;
بس بدي اعرف ليش استخدمت هاد الكود وايش تفسيراته
الهدف من هذه ال function هو معرفه مكان وضع ال x او ال o من خلال تحويل قيمه ضغطه الماوس ال قيمتين تعيدان موقع ال x او ال o
مثلاً لو ضغطنا في النقطه 100,326 ستحولها هذه الفنكشن مثلاً الى 2,2 اي ضع x في السطر الثاني العامود الثاني
وهذه الفنكشن تعتمد علو حجم شاشه ال opengl التي نستخدمها
شكرا كتير الك بس بصراحه لساتني مش فاهمته في ارقام مش عرف ليش استخدمها وفي فنكشن مش فاهميتها ممكن تساعدني اكتر
int nBasePos=nWidth*1.0/8.0;
int XDis=(nWidth-2*nBasePos)/3;
int YDis=(nHeight-2*nBasePos)/3;
تم تعديل هذه المشاركة بواسطة هبوش الرمثا في 25 ديسمبر 2010 في 16:57
هذا البرنامج بعد تصحيح بعض المشاكل
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <math.h>
int Matrix[3][3]={
{-1, -1, -1},
{-1, -1, -1},
{-1, -1, -1}
};
int nWidth;
int nHeight;
bool bXorO=false;
void DrawX(int x,int y);
void DrawO(int x,int y);
void reshape(int w,int h)
{
nWidth=w;
nHeight=h;
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glOrtho(0,800,800,0,800,0);
glViewport(0,0,w,h);
}
void display()
{
}
COORD GetMatrixIndex(int x,int y)
{
COORD point;
point.X=-1;
point.Y=-1;
int nXBasePos=nWidth*1.0/8.0;
int nYBasePos=nHeight*1.0/8.0;
int XDis=(nWidth-2*nXBasePos)/3;
int YDis=(nHeight-2*nYBasePos)/3;
if(x>=nXBasePos && x<=nXBasePos+XDis)
point.X=0;
else if(x>=nXBasePos+XDis && x<=nXBasePos+2*XDis)
point.X=1;
else if(x>=nXBasePos+2*XDis && x<=nXBasePos+3*XDis)
point.X=2;
if(y>=nYBasePos && y<=nYBasePos+YDis)
point.Y=0;
else if(y>=nYBasePos+YDis && y<=nYBasePos+2*YDis)
point.Y=1;
else if(y>=nYBasePos+2*YDis && y<=nYBasePos+3*YDis)
point.Y=2;
return point;
}
void MouseFunction(int button, int state,int x, int y)
{
if(button== GLUT_LEFT_BUTTON)
{
if(state==GLUT_DOWN)
{
COORD coord= GetMatrixIndex(x,y);
if(coord.X==-1&&coord.Y==-1)
return;
if(Matrix[coord.X][coord.Y]==-1)
{
Matrix[coord.X][coord.Y]=bXorO;
bXorO=!bXorO;
}
}
}
}
void movie()
{
glClearColor(255,255,255,255);
glClear(GL_COLOR_BUFFER_BIT);//white background
glColor3f(1,0,0);
glLineWidth(3);
glBegin(GL_LINE_LOOP);
glVertex2i(100,100);
glVertex2i(700,100);
glVertex2i(700,700);
glVertex2i(100,700);
glEnd();
glBegin(GL_LINES);
glVertex2i(100,300);
glVertex2i(700,300);
glVertex2i(100,500);
glVertex2i(700,500);
glVertex2i(300,100);
glVertex2i(300,700);
glVertex2i(500,100);
glVertex2i(500,700);
glEnd();
for(int x=0;x<3;x++)
for(int y=0;y<3;y++)
{
if(Matrix[x][y]==0)
DrawX((x+1)*200,(y+1)*200);
else if(Matrix[x][y]==1)
DrawO((x+1)*200,(y+1)*200);
}
glutSwapBuffers();
}
void DrawX(int x,int y)
{
glColor3f(0,0,1);
glBegin(GL_LINES);
glVertex2i(x-70,y-70);
glVertex2i(x+70,y+70);
glVertex2i(x+70,y-70);
glVertex2i(x-70,y+70);
glEnd();
}
void DrawO(int x,int y)
{
glColor3f(0,0,1);
glBegin(GL_LINE_LOOP);
for(float f=0;f<3.14*2;f+=0.1)
glVertex2i(x+70*cos(f),y+70*sin(f));
glEnd();
}
void main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE);
glutInitWindowSize(600,600);
glutInitWindowPosition(0,0);
glutCreateWindow("glut window");
glutReshapeFunc(reshape);
glutMouseFunc(MouseFunction);
glutDisplayFunc(display);
glutIdleFunc(movie);
glutMainLoop();
}المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية
جارٍ التحقق من المتواجدين…