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

عندي إشكاليه في رسم الدائره في open GL

مغلق
بدأه had في 23 مارس 2007 · 1 رد · 1,297 مشاهدة · في OpenGL
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

لو سمحتوا انا عندي إشكاليه في رسم الدائره في open GL

هذا البرنامج ولكن يعملي error

ممكن تكملوا البرنامج وتفهموني خطأي

ممكن تعجلوا من فضلكم لأني احتاجه ضروري

وجزاكم الله كل خير

وهذا البرنامج

#include <GL/glut.h>
class screenpt
{
private:
	GLint x,y;

public:
	screenpt() {
		x = y = 0;
	}


	void setCoords(GLint xCoordValue, GLint yCoordValue){
		x = xCoordValue;
		y = yCoordValue;
	}


	GLint getx() const {
		return x;
	}

	GLint gety() const {
		return y;
	}

	void incrementx() {
		x++;
	}

	void decrementy() {
		y--;
	}

};


void setpixel (GLint xCoord , GLint yCoord)
{
	glBegin(GL_POINTS);
	glVertex2i(xCoord ,yCoord);
	glEnd ();
}

/***************************************/

void circleMidpoint (GLint xc, GLint yc,GLint radius )
{
	screenpt circpt;

	GLint p = 1 - radius;

	circpt.setCoords(0,radius);

	void circlePlotPoints (GLint , GLint ,screenpt);
	circlePlotPoints (xc , yc ,circpt);
	while (circpt.getx() < circpt.gety()){
		circpt.incrementx();
		if (p <0)
			p +=2 * circpt.getx() +1;
		else {
			circpt.decrementy();
			p += 2 *(circpt.getx() - circpt.gety())+1;

		}

		circlePlotPoints(xc,yc,circpt);
	}
}

/************************************************************/

void circelPlotPoints(GLint xc,GLint yc,screenpt circpt)
{
	setpixel(xc + circpt.getx() , yc + circpt.gety());
	setpixel(xc - circpt.getx() , yc + circpt.gety());
	setpixel(xc + circpt.getx() , yc - circpt.gety());
	setpixel(xc - circpt.getx() , yc - circpt.gety());
	setpixel(xc + circpt.gety() , yc + circpt.getx());
	setpixel(xc - circpt.gety() , yc + circpt.getx());
	setpixel(xc - circpt.gety() , yc - circpt.getx());
	setpixel(xc + circpt.gety() , yc - circpt.getx());
}
#2

أنت تستخدم Midpoint Circle Algorithm

لقد عدلت في الكود و ستعرف أخطائك من قرائته:

#include <windows.h>
#include <GL/gl.h>
#include <GL/glut.h>

class ScreenPoint{
private:
	GLint x,y;

public:
	ScreenPoint() {
		x = y = 0;
	}

	void setCoords(GLint xCoordValue, GLint yCoordValue){
		x = xCoordValue;
		y = yCoordValue;
	}

	GLint getX() const {
		return x;
	}

	GLint getY() const {
		return y;
	}

	void incrementx() {
		x++;
	}

	void decrementy() {
		y--;
	}
};


void setPixel(GLint xCoord , GLint yCoord){
	glBegin(GL_POINTS);
		glVertex2i(xCoord ,yCoord);
	glEnd ();
}

/************************************************************/

void circelPlotPoints(GLint xc,GLint yc,ScreenPoint circpt){
	setPixel(xc + circpt.getX() , yc + circpt.getY());
	setPixel(xc - circpt.getX() , yc + circpt.getY());
	setPixel(xc + circpt.getX() , yc - circpt.getY());
	setPixel(xc - circpt.getX() , yc - circpt.getY());
	setPixel(xc + circpt.getY() , yc + circpt.getX());
	setPixel(xc - circpt.getY() , yc + circpt.getX());
	setPixel(xc - circpt.getY() , yc - circpt.getX());
	setPixel(xc + circpt.getY() , yc - circpt.getX());
}

/***************************************/

void circleMidpoint (GLint xc, GLint yc,GLint radius ){
	ScreenPoint circpt;

	GLint p = 1 - radius;

	circpt.setCoords(0,radius);

	while (circpt.getX() < circpt.getY()){
		circelPlotPoints(xc,yc,circpt);
		if (p <0)
			p +=2 * circpt.getX() +3;
		else {
			p += 2 *(circpt.getX() - circpt.getY())+5;
			circpt.decrementy();
		}
		circpt.incrementx();
	}
}
void myInit(void)
{
	glClearColor(1.0,1.0,1.0,0.0);	   // set white background color
	glColor3f(0.0f, 0.0f, 0.0f);		  // set the drawing color 
	glPointSize(4.0);			   // a ‘dot’ is 4 by 4 pixels
	glMatrixMode(GL_PROJECTION); 
	glLoadIdentity();
	gluOrtho2D(0.0, 640.0, 0.0, 480.0);
}
//<<<<<<<<<<<<<<<<<<<<<<<< myDisplay >>>>>>>>>>>>>>>>>
void myDisplay(void)
{
	glClear(GL_COLOR_BUFFER_BIT);	 // clear the screen 
	glBegin(GL_POINTS);
	circleMidpoint(320,240,100);
	glFlush();						 // send all output to display 
}

void main(int argc, char** argv){
	glutInit(&argc, argv);		  // initialize the toolkit
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // set display mode
	glutInitWindowSize(640,480);	 // set window size
	glutInitWindowPosition(100, 150); // set window position on screen
	glutCreateWindow("my first attempt"); // open the screen window
	glutDisplayFunc(myDisplay);	 // register redraw function
	myInit(); 
	glutMainLoop(); 		
}

و كن فتى في ذرى العلياء همّته

يسمو بغاياته حتى على زحل

موقع خاص بي

My Website

قمت بتصميم لعبة بسيطة بإستخدام اللغة الجميلة الجافا

Plane Fighter Game

برنامج جميل بلغة الجافا يساعد على تنظيم المشاكل

The TS Organizer

هذا الموضوع مغلق.

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