الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

كيف اعمل المنيو في بوتون...؟؟

بدأه شادن..}~ في 30 أبريل 2012 · 2 رد · 1,122 مشاهدة · في OpenGL
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ....

في ذا الكود المنيو تظهرلي لما اعمل كليك يمين وفي اي مكان , طيب لو ابغى اعمل بوتون بحيث انو مثلا Background تكون في بوتون اول

مااضغط عليه يطلعلي الوانو و الي هي السب منيو له و House color تكون برضو في بوتون ولما اضغط عليه يطلعلي السب منيو له

وزي كدا بدل مايكون لازم كليك يمين ....؟؟؟

#include <GL\glut.h>  // Note: this automatically includes other 
                      // required header files, including: 
                      //    glu.h      (GL utility functions) 
                      //    gl.h       (GL functions) 
                      //    windows.h  (Microsoft windows stuff) 
GLsizei wh = 500, ww = 500;
GLint menu,supmenue1,supmenue2,supmenue3;
GLint red=1,green=1,blue=1;
GLint redr=1,greenr=1,bluer=1;

void init(void)
{
  glClearColor(1.0, 1.0, 1.0, 0.0); // set the background to white


  glMatrixMode(GL_PROJECTION);		// set projection parameters
  glLoadIdentity();
  glOrtho(-70.0, 120.0, -100.0, 150.0, -80.0, 100.0);
}

void draw(int x,int y)
{
	  y=wh-y;

  glClear( GL_COLOR_BUFFER_BIT );	// Clear display window



//---------------------------------------------------------------------------

   //The Front side of the House
  glBegin(GL_QUADS);  
   glColor3f(red, green, blue);
    glVertex3i(-40,-50,70);
    glVertex3i(-40,20,40); 
    glVertex3i(20,20,-40);
    glVertex3i(20,-50,70);
  glEnd();

  glLineWidth(3);
  //The Front side borders of the House
  glBegin(GL_LINE_LOOP); 
    glColor3f(0, 0, 0);
    glVertex3i(-40,-50,70);
    glVertex3i(-40,20,40); 
    glVertex3i(20,20,-40);
    glVertex3i(20,-50,70);
  glEnd();
////---------------------------------------------------------------------------
//
  glColor3f(red, green, blue);
   //The right side of the House and roof
  glBegin(GL_QUADS); 

    glVertex3i(20,-50,70);
    glVertex3i(20,20,-40);

    glVertex3i(70,40,80);
	glVertex3i(70,-20,-40);
  glEnd();

  glLineWidth(3);
//The right side borders of the House and roof
  glBegin(GL_LINE_LOOP); 
    glColor3f(0, 0, 0);
    glVertex3i(20,-50,70);
    glVertex3i(20,20,-40);

    glVertex3i(70,40,80);
	glVertex3i(70,-20,-40);
  glEnd();

//---------------------------------------------------------------------------
  //The front side of the roof
   glColor3f(redr, greenr, bluer);
  glBegin(GL_QUADS); 

	glVertex3i(-40,20,20);
	glVertex3i(-10,69,-44);
    glVertex3i(44,74,45);
	glVertex3i(20,20,-22);
 glEnd();
 glLineWidth(3);
 //The front side borders of the roof
  glBegin(GL_LINE_LOOP); 
    glColor3f(0, 0, 0);
    glVertex3i(-40,20,20);
	glVertex3i(-10,69,-44);
   glVertex3i(44,74,45);
	glVertex3i(20,20,-22);
 glEnd();

 glBegin(GL_TRIANGLES); 
   glColor3f(redr,greenr,bluer);

    glVertex3i(44,74,60);
	glVertex3i(20,20,-40);
	glVertex3i(70,40,80);


  glEnd();
//The right side borders of  roof
  glLineWidth(3);
  glBegin(GL_LINE_LOOP); 
    glColor3f(0, 0, 0);
   glVertex3i(44,74,60);
	glVertex3i(20,20,-40);
	glVertex3i(70,40,80);
  glEnd();

 //---------------------------------------------------------------------------
//  //The door of the house
  glBegin(GL_QUADS); 
    glColor3f(red,green,blue);
	glVertex3i(-30,-50,70);
	glVertex3i(-30,-5,30);
    glVertex3i(-15,-5,10);
	glVertex3i(-15,-50,70);
 glEnd();

//The door borders of the house
 glLineWidth(3);
  glBegin(GL_LINE_LOOP); 
    glColor3f(0, 0, 0);

   glVertex3i(-30,-50,70);
	glVertex3i(-30,-5,30);
    glVertex3i(-15,-5,10);
	glVertex3i(-15,-50,70);
	glEnd();
//------point----
  glColor3f(0.0, 0.0, 0.0);
  glPointSize(10);
  glBegin(GL_POINTS);
  glVertex3i(-27,-30,30);
  glEnd();
////---------------------------------------------------------------------------
  //Chimney
  glBegin(GL_QUADS); 
    glColor3f(redr,greenr,bluer);
	glVertex3i(15,70,47);
	glVertex3i(15,80,60);
    glVertex3i(28,80,68);
	glVertex3i(28,70,57);
	glEnd();

  glBegin(GL_LINE_LOOP); 
    glColor3f(0, 0, 0);
   glVertex3i(15,70,47);
	glVertex3i(15,80,60);
    glVertex3i(28,80,68);
	glVertex3i(28,70,57);
glEnd();

	 glBegin(GL_QUADS); 
   glColor3f(redr,greenr,bluer);
	glVertex3i(28,70,57);
	glVertex3i(30,70,60);
    glVertex3i(35,75,65);
	glVertex3i(35,80,70);
	glVertex3i(28,80,68);
glEnd();
  glBegin(GL_LINE_LOOP); 
    glColor3f(0, 0, 0);
   glVertex3i(28,69,57);
	glVertex3i(30,70,60);
    glVertex3i(35,75,65);
	glVertex3i(35,80,70);
	glVertex3i(28,80,68);
glEnd();

	 glBegin(GL_QUADS); 
    glColor3f(redr,greenr,bluer);
	glVertex3i(28,69,68);
	glVertex3i(35,80,70);
    glVertex3i(37,85,70);
	glVertex3i(25,85,70);
glEnd();
  glBegin(GL_LINE_LOOP); 
    glColor3f(0, 0, 0);
   glVertex3i(28,80,68);
	glVertex3i(35,80,70);
    glVertex3i(37,85,70);
	glVertex3i(25,85,70);
glEnd();

 glBegin(GL_QUADS); 
  glColor3f(redr,greenr,bluer);
	glVertex3i(15,80,60);
	glVertex3i(28,80,60);
    glVertex3i(25,85,70);
	glVertex3i(13,85,65);
glEnd();
  glBegin(GL_LINE_LOOP); 
    glColor3f(0, 0, 0);
  glVertex3i(15,80,60);
	glVertex3i(28,80,60);
    glVertex3i(25,85,70);
	glVertex3i(13,85,65);
glEnd();
////----------------------------------------------------------------------
glBegin(GL_LINE_LOOP); //DRAWing front window(1)
    glColor3f(0, 0, 0);
    glVertex3i(-5,-20,18);
glVertex3i(-5,10,10);
    glVertex3i(10,10,13);
	glVertex3i(10,-20,-5);
  glEnd();

//  //-----------------------------------------------------------------
  glBegin(GL_QUADS); //DRAWing front window(2)R
    glColor3f(1, 1, 1);
	glVertex3i(10,-15,18);
	glVertex3i(15,-15,15);
    glVertex3i(15,5,2);
	glVertex3i(10,5,0);
  glEnd();
//  //-----------------------------------------------------------------
  glBegin(GL_LINE_LOOP); //DRAWing front window(2)R
    glColor3f(0, 0, 0);
    glVertex3i(10,-15,18);
	glVertex3i(15,-15,15);
    glVertex3i(15,5,2);
	glVertex3i(10,5,0);
  glEnd();
//  //-----------------------------------------------------------------
  glBegin(GL_QUADS); //DRAWing front window(2)L
    glColor3f(1, 1, 1);
	glVertex3i(-10,-15,10);
	glVertex3i(-5,-15,5);
    glVertex3i(-5,5,12);
	glVertex3i(-10,5,7);
  glEnd();
  //-----------------------------------------------------------------
  glBegin(GL_LINE_LOOP); //DRAWing front window(2)L
    glColor3f(0, 0, 0);
    glVertex3i(-10,-15,10);
	glVertex3i(-5,-15,5);
    glVertex3i(-5,5,12);
	glVertex3i(-10,5,7);
  glEnd();
 //-----------------------------------------------------------------
  //DRWing front window Top
  glBegin(GL_QUADS); 
    glColor3f(1, 1, 1);
	glVertex3i(-3,10,10);
	glVertex3i(-3,15,5);
    glVertex3i(8,15,12);
	glVertex3i(8,10,7);
  glEnd();
  //-----------------------------------------------------------------
  glBegin(GL_LINE_LOOP); 
    glColor3f(0, 0, 0);
    glVertex3i(-3,10,10);
	glVertex3i(-3,15,5);
    glVertex3i(8,15,12);
	glVertex3i(8,10,7);
  glEnd();
  //-----------------------------------------------------------------

  //DRWing front window bottom
  glBegin(GL_QUADS); 
    glColor3f(1, 1, 1);
	glVertex3i(-3,-25,10);
	glVertex3i(-3,-20,5);
    glVertex3i(8,-20,12);
	glVertex3i(8,-25,7);
  glEnd();
  //-----------------------------------------------------------------
  glBegin(GL_LINE_LOOP); 
    glColor3f(0, 0, 0);
    glVertex3i(-3,-25,10);
	glVertex3i(-3,-20,5);
    glVertex3i(8,-20,12);
	glVertex3i(8,-25,7);
  glEnd();
//-------------------------------------------------------

  glColor3f(0, 0, 0);
  glBegin(GL_LINES); 
    //horizental lines
    glVertex3i(-5,5,10);
	glVertex3i(10,5,5);

    glVertex3i(-5,3,12);
	glVertex3i(10,3,7);

    glVertex3i(-5,-10,10);
	glVertex3i(10,-10,5);

    glVertex3i(-5,-13,12);
	glVertex3i(10,-13,7);

	//vertical lines

	glVertex3i(0,10,10);
	glVertex3i(0,-20,5);

    glVertex3i(2,10,12);
	glVertex3i(2,-20,7);

	glVertex3i(4,10,12);
	glVertex3i(4,-20,7);
glEnd();
//------------------------------------------------------------------
glBegin(GL_LINE_LOOP); //DRAWing front window(2)
    glColor3f(0, 0, 0);
    glVertex3i(25,-20,18);
	glVertex3i(25,7,10);
    glVertex3i(40,12,13);
	glVertex3i(40,-15,-5);
  glEnd();
  //------------------------------------------------------------------
glBegin(GL_LINE_LOOP); //DRAWing front window(3)
    glColor3f(0, 0, 0);
    glVertex3i(50,-9,18);
	glVertex3i(50,17,10);
    glVertex3i(65,25,13);
	glVertex3i(65,-1,-5);
  glEnd();


  glFlush();						// send any buffered output to  
                                    // the OpenGL rendering process 
}




//Menu
void MenuEvents(int click)

{



switch (click)

{



case 1: glClearColor(0.0,0.0,0.0,0.0); break;



case 2: glClearColor(1.0,1.0,1.0,0.0); break;



case 3: red=1.0, blue=0.0, green=0.0; break;



case 4: red=0.0, blue=0.0, green=1.0; break;



case 5: red=0.0, blue=1.0, green=0.0; break;



case 6: red=0.0, blue=1.0, green=1.0; break;



case 7: red=1.0, blue=1.0, green=0.0; break;



case 8: red=1.0, blue=0.0, green=1.0; break;



case 9: redr=1.0,bluer=0.0,greenr=0.0; break;



case 10:redr=0.0,bluer=0.0,greenr=1.0; break;



case 11:redr=0.0,bluer=1.0,greenr=0.0; break;



case 12:redr=0.0,bluer=1.0,greenr=1.0; break;



case 13:redr=1.0,bluer=1.0, greenr=0.0;break;



case 14:redr=1.0,bluer=0.0, greenr=1.0;break;



case 15:glClear(GL_COLOR_BUFFER_BIT ); // Clean the screen and the depth buffer

glLoadIdentity(); 

// Reset The Projection Matrix

break;



case 16:exit(0); break;

}

glutPostRedisplay();

glFlush();

}

void mouse(int btn, int state, int x, int y)
{
    if(btn==GLUT_LEFT_BUTTON && state==GLUT_DOWN)  
		draw(x,y); 
}
//--------------------------------------------------------------------
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}

//-------------------------------------------------------------------


void main( int argc, char **argv)
{
  glutInit(&argc, argv);						// Initialize GLUT
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB ); // Set display mode
  glutInitWindowPosition(0,0);		// Set top-left display window position
  glutInitWindowSize(1000,1000);		// Set display window width and height
  glutCreateWindow("3D House");// Create display window
  init(); // Execute initialization procedure



    glutMouseFunc(mouse);
	   glutDisplayFunc(display);

  supmenue1=glutCreateMenu(MenuEvents);

glutAddMenuEntry("Black",1);

glutAddMenuEntry("Wihte",2);

supmenue2=glutCreateMenu(MenuEvents);

glutAddMenuEntry("red",3);

glutAddMenuEntry("green",4);

glutAddMenuEntry("blue",5);

glutAddMenuEntry("cyan",6);

glutAddMenuEntry("magenta",7);

glutAddMenuEntry("yallow",8);

supmenue3=glutCreateMenu(MenuEvents);

glutAddMenuEntry("red",9);

glutAddMenuEntry("green",10);

glutAddMenuEntry("blue",11);

glutAddMenuEntry("cyan",12);

glutAddMenuEntry("magenta",13);

glutAddMenuEntry("yallow",14);



// Creating the main menu 

menu = glutCreateMenu(MenuEvents);

// Adding items to the menu 

glutAddSubMenu("Background", supmenue1);

glutAddSubMenu("House Color", supmenue2);

glutAddSubMenu("Roof Color", supmenue3);

glutAddMenuEntry("Clear Screen",15);

glutAddMenuEntry("exit",16);

//Connecting the menu to the mouse right button


// Send graphics to display window

glutAttachMenu(GLUT_RIGHT_BUTTON);
  glutMainLoop();					// Display everything and wait

}
#2

السلام عليكم...

عموما الكلام غير واضح من ناحيتك , بالكاد إستطعت فهم بعض العبارات , إن كنت موفقا فإليك التفاصيل.

مكتبة "جي لوت" هي ليست مكتبة معتمدة على الأساس , بل من صمم المكتبة جعلها تناسب المبتدئين الأوائل. أظن أن الواجب عليك هو الإنتقال إلى مرحلة البرمجة الكائنية ( بالطبع هذه أمور مجربة ).

مستواك حسب ما لاحظته من الشيفرة التي أرفقتها مقبول .

المكتبة " جي لوت " لم تصمم لمعالجة تفاصيل معقد , كان من المفترض عليك إتباع منهجية المكتبة و لكنك و حسب ما رأيت كنت تريد أن تكون أنت المشرع للشيفرة .. هههه بالطبع هذا شيء مقبول ..

المكتبة تعتمد على إستدعاء خاص " كال باك " و هو إستدعاء قد تم هجره في كلا من نظام ويندوز و لينكس.

في مثالك , إما أن تجعل دالة الرسم "حراو " في دالة " ديسبلاي " ..

تم تعديل هذه المشاركة بواسطة 3ds max2010 في 30 أبريل 2012 في 16:59

تخيل, هل سيكون مستقبل الأوبن جي أل مع البشرية هكذا

future.jpg
#3

=======================================Origninal=================================

في ذا الكود المنيو تظهرلي لما اعمل كليك يمين وفي اي مكان , طيب لو ابغى اعمل بوتون بحيث انو مثلا Background تكون في بوتون اول

مااضغط عليه يطلعلي الوانو و الي هي السب منيو له و House color تكون برضو في بوتون ولما اضغط عليه يطلعلي السب منيو له

وزي كدا بدل مايكون لازم كليك يمين ....؟؟؟

=========================================Rephrased==============================

الكود المدرج ادناه يعمل على إظهار Context Menu عند عمل Right-Click في داخل الـ Client Area ...

المطلوب كيف يمكن إعادة برمجة الكود بحيث يظهر على شكل Color Selection Drop down (عدد اثنين) في الـ toolbar بدلا من كونها context Menu ... بحيث يتم تخصيص كل واحد منهما لوظيفة اختيار لون ( مثلا Foreground color, background color)??

==============================================================================

أرجو التأكيد على فهمي للموضوع.

سنوسي حواري

عمان - الأردن

المدونة

بريد الكتروني: sanousy.howari@gmail.com

سكايب: Sanousy.howari

فيسبوك : facebook

تويتر: Twitter

مواضيع مشابهة