<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[C++ QT4 OpenGL]]></title><description><![CDATA[<p>Hallo,<br />
ich bin neu in dem Forum und muss gleich mal um Hilfe rufen!<br />
Hab seit längerem nicht mehr programmiert und wollte mir jetzt mal OpenGL ansehen...<br />
Dummerweise funktioniert das momentan nicht ganz so wie ich will.<br />
Hab den Code von nem tut etwas abgeändert und ich weiß nicht wieso dieser Fehler auftritt!!!</p>
<p>Compiler:</p>
<pre><code>tetrahedron.cpp: In function &quot;void berechne_eckpunkte(float, float, float)&quot;:
tetrahedron.cpp:39: error: &quot;hinten&quot; was not declared in this scope
tetrahedron.cpp:43: error: &quot;vorne_links&quot; was not declared in this scope
tetrahedron.cpp:47: error: &quot;vorne_rechts&quot; was not declared in this scope
tetrahedron.cpp:51: error: &quot;oben&quot; was not declared in this scope
</code></pre>
<p>Aber in der Headerdatei steht es doch unter public Zeile 11!!!!!!!<br />
Also was zum Teufel geht hier ab?!</p>
<p>Tetrahedron.h:</p>
<pre><code class="language-cpp">#ifndef TETRAHEDRON_H
#define TETRAHEDRON_H

#include &lt;QGLWidget&gt;

class Tetrahedron : public QGLWidget
{
	Q_OBJECT
	public:
		Tetrahedron(QWidget *parent = 0);
		float hinten[3], vorne_links[3], vorne_rechts[3], oben[3];
		void berechne_eckpunkte(float ursprungX, float ursprungY, float ursprungZ);

	protected:
		void initializeGL();
		void resizeGL(int width, int height);
		void paintGL();
		void mousePressEvent(QMouseEvent *event);
		void mouseMoveEvent(QMouseEvent *event);
		void mouseDoubleClickEvent(QMouseEvent *event);

	private:
		void draw();
		int faceAtPosition(const QPoint &amp;pos);
		GLfloat rotationX;
		GLfloat rotationY;
		GLfloat rotationZ;
		QColor faceColors[4];
		QPoint lastPos;
};

#endif
</code></pre>
<p>Tetrahedron.cpp:</p>
<pre><code class="language-cpp">#include &lt;QtGui&gt;
#include &lt;QtOpenGL&gt;
#include &lt;cmath&gt;

#include &quot;tetrahedron.h&quot;

Tetrahedron::Tetrahedron(QWidget *parent)
	: QGLWidget(parent)
{
	setFormat(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer));
}

void Tetrahedron::initializeGL()
{
	qglClearColor(Qt::black);
	glShadeModel(GL_FLAT);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
}

void Tetrahedron::resizeGL(int width, int height)
{
	glViewport(0, 0, width, height);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	GLfloat x = GLfloat(width) / height;
	glFrustum(-x, x, -1.0, 1.0, 4.0, 15.0);
	glMatrixMode(GL_MODELVIEW);
}

void Tetrahedron::paintGL()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	draw();
}

void berechne_eckpunkte(float ursprungX, float ursprungY, float ursprungZ)
{
	hinten[0] = ursprungX;
	hinten[1] = ursprungY;
	hinten[2] = ursprungZ;

	vorne_links[0] = ursprungX - 0.5;
	vorne_links[1] = ursprungY;
	vorne_links[2] = ursprungZ + (sqrt(3.0)/2.0);

	vorne_rechts[0] = ursprungX + 0.5;
	vorne_rechts[1] = ursprungY;
	vorne_rechts[2] = ursprungZ + (sqrt(3.0)/2.0);

	oben[0] = ursprungX;
	oben[1] = ursprungY + (sqrt(6.0)/3.0);
	oben[2] = ursprungZ + (sqrt(3.0)/3.0);
}

void Tetrahedron::draw()
{
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	berechne_eckpunkte(0.0, 0.0, 0.0);
	glBegin(GL_POLYGON);

	glVertex3f(hinten[0],hinten[1],hinten[2]);
	glVertex3f(vorne_links[0],vorne_links[1],vorne_links[2]);
	glVertex3f(oben[0],oben[1],oben[2]);

	glVertex3f(vorne_links[0],vorne_links[1],vorne_links[2]);
	glVertex3f(vorne_rechts[0],vorne_rechts[1],vorne_rechts[2]);
	glVertex3f(oben[0],oben[1],oben[2]);

	glVertex3f(vorne_rechts[0],vorne_rechts[1],vorne_rechts[2]);
	glVertex3f(hinten[0],hinten[1],hinten[2]);
	glVertex3f(oben[0],oben[1],oben[2]);

	glVertex3f(hinten[0],hinten[1],hinten[2]);
	glVertex3f(vorne_links[0],vorne_links[1],vorne_links[2]);
	glVertex3f(vorne_rechts[0],vorne_rechts[1],vorne_rechts[2]);

	glEnd();
}

void Tetrahedron::mousePressEvent(QMouseEvent *event)
{
	lastPos = event-&gt;pos();
}

void Tetrahedron::mouseMoveEvent(QMouseEvent *event)
{
	GLfloat dx = GLfloat(event-&gt;x() - lastPos.x()) / width();
	GLfloat dy = GLfloat(event-&gt;y() - lastPos.y()) / height();

	if (event-&gt;buttons() &amp; Qt::LeftButton)
	{
		rotationX += 180*dy;
		rotationY += 180*dx;
		updateGL();
	}
	else
	{
		if (event-&gt;buttons() &amp; Qt::RightButton)
		{
			rotationX += 180*dy;
			rotationZ += 180*dx;
			updateGL();
		}
	}
	lastPos = event-&gt;pos();
}

void Tetrahedron::mouseDoubleClickEvent(QMouseEvent *event)
{
	int face = faceAtPosition(event-&gt;pos());
	if (face != -1)
	{
		QColor color = QColorDialog::getColor(faceColors[face], this);
		if (color.isValid())
		{
			faceColors[face] = color;
			updateGL();
		}
	}
}

int Tetrahedron::faceAtPosition(const QPoint &amp;pos)
{
	const int MaxSize = 512;
	GLuint buffer[MaxSize];
	GLint viewport[4];

	makeCurrent();

	glGetIntegerv(GL_VIEWPORT, viewport);
	glSelectBuffer(MaxSize, buffer);
	glRenderMode(GL_SELECT);

	glInitNames();
	glPushName(0);

	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	gluPickMatrix(GLdouble(pos.x()), GLdouble(viewport[3] - pos.y()), 5.0, 5.0, viewport);
	GLfloat x = GLfloat(width()) / height();
	glFrustum(-x, x, -1.0, 1.0, 4.0, 15.0);
	draw();
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();

	if (!glRenderMode(GL_RENDER))
	{
		return -1;
	}
	return buffer[3];
}
</code></pre>
<p>Main.cpp:</p>
<pre><code class="language-cpp">#include &lt;QApplication&gt;
#include &lt;iostream&gt;

#include &quot;tetrahedron.h&quot;

int main(int argc, char *argv[])
{
	QApplication app(argc, argv);

	if (!QGLFormat::hasOpenGL())
	{
		std::cerr &lt;&lt; &quot;Geht nicht&quot; &lt;&lt; std::endl;
		return 1;
	}

	Tetrahedron tetrahedron;
	tetrahedron.setWindowTitle(&quot;Tetrahedron&quot;);
	tetrahedron.resize(300, 300);
	tetrahedron.show();

	return app.exec();
}
</code></pre>
<p>Danke an alle, die versuchen mir zu helfen und sorry für so viel Code!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/264524/c-qt4-opengl</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Sep 2026 16:50:08 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/264524.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 08 Apr 2010 19:30:20 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to C++ QT4 OpenGL on Thu, 08 Apr 2010 19:30:20 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich bin neu in dem Forum und muss gleich mal um Hilfe rufen!<br />
Hab seit längerem nicht mehr programmiert und wollte mir jetzt mal OpenGL ansehen...<br />
Dummerweise funktioniert das momentan nicht ganz so wie ich will.<br />
Hab den Code von nem tut etwas abgeändert und ich weiß nicht wieso dieser Fehler auftritt!!!</p>
<p>Compiler:</p>
<pre><code>tetrahedron.cpp: In function &quot;void berechne_eckpunkte(float, float, float)&quot;:
tetrahedron.cpp:39: error: &quot;hinten&quot; was not declared in this scope
tetrahedron.cpp:43: error: &quot;vorne_links&quot; was not declared in this scope
tetrahedron.cpp:47: error: &quot;vorne_rechts&quot; was not declared in this scope
tetrahedron.cpp:51: error: &quot;oben&quot; was not declared in this scope
</code></pre>
<p>Aber in der Headerdatei steht es doch unter public Zeile 11!!!!!!!<br />
Also was zum Teufel geht hier ab?!</p>
<p>Tetrahedron.h:</p>
<pre><code class="language-cpp">#ifndef TETRAHEDRON_H
#define TETRAHEDRON_H

#include &lt;QGLWidget&gt;

class Tetrahedron : public QGLWidget
{
	Q_OBJECT
	public:
		Tetrahedron(QWidget *parent = 0);
		float hinten[3], vorne_links[3], vorne_rechts[3], oben[3];
		void berechne_eckpunkte(float ursprungX, float ursprungY, float ursprungZ);

	protected:
		void initializeGL();
		void resizeGL(int width, int height);
		void paintGL();
		void mousePressEvent(QMouseEvent *event);
		void mouseMoveEvent(QMouseEvent *event);
		void mouseDoubleClickEvent(QMouseEvent *event);

	private:
		void draw();
		int faceAtPosition(const QPoint &amp;pos);
		GLfloat rotationX;
		GLfloat rotationY;
		GLfloat rotationZ;
		QColor faceColors[4];
		QPoint lastPos;
};

#endif
</code></pre>
<p>Tetrahedron.cpp:</p>
<pre><code class="language-cpp">#include &lt;QtGui&gt;
#include &lt;QtOpenGL&gt;
#include &lt;cmath&gt;

#include &quot;tetrahedron.h&quot;

Tetrahedron::Tetrahedron(QWidget *parent)
	: QGLWidget(parent)
{
	setFormat(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer));
}

void Tetrahedron::initializeGL()
{
	qglClearColor(Qt::black);
	glShadeModel(GL_FLAT);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
}

void Tetrahedron::resizeGL(int width, int height)
{
	glViewport(0, 0, width, height);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	GLfloat x = GLfloat(width) / height;
	glFrustum(-x, x, -1.0, 1.0, 4.0, 15.0);
	glMatrixMode(GL_MODELVIEW);
}

void Tetrahedron::paintGL()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	draw();
}

void berechne_eckpunkte(float ursprungX, float ursprungY, float ursprungZ)
{
	hinten[0] = ursprungX;
	hinten[1] = ursprungY;
	hinten[2] = ursprungZ;

	vorne_links[0] = ursprungX - 0.5;
	vorne_links[1] = ursprungY;
	vorne_links[2] = ursprungZ + (sqrt(3.0)/2.0);

	vorne_rechts[0] = ursprungX + 0.5;
	vorne_rechts[1] = ursprungY;
	vorne_rechts[2] = ursprungZ + (sqrt(3.0)/2.0);

	oben[0] = ursprungX;
	oben[1] = ursprungY + (sqrt(6.0)/3.0);
	oben[2] = ursprungZ + (sqrt(3.0)/3.0);
}

void Tetrahedron::draw()
{
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	berechne_eckpunkte(0.0, 0.0, 0.0);
	glBegin(GL_POLYGON);

	glVertex3f(hinten[0],hinten[1],hinten[2]);
	glVertex3f(vorne_links[0],vorne_links[1],vorne_links[2]);
	glVertex3f(oben[0],oben[1],oben[2]);

	glVertex3f(vorne_links[0],vorne_links[1],vorne_links[2]);
	glVertex3f(vorne_rechts[0],vorne_rechts[1],vorne_rechts[2]);
	glVertex3f(oben[0],oben[1],oben[2]);

	glVertex3f(vorne_rechts[0],vorne_rechts[1],vorne_rechts[2]);
	glVertex3f(hinten[0],hinten[1],hinten[2]);
	glVertex3f(oben[0],oben[1],oben[2]);

	glVertex3f(hinten[0],hinten[1],hinten[2]);
	glVertex3f(vorne_links[0],vorne_links[1],vorne_links[2]);
	glVertex3f(vorne_rechts[0],vorne_rechts[1],vorne_rechts[2]);

	glEnd();
}

void Tetrahedron::mousePressEvent(QMouseEvent *event)
{
	lastPos = event-&gt;pos();
}

void Tetrahedron::mouseMoveEvent(QMouseEvent *event)
{
	GLfloat dx = GLfloat(event-&gt;x() - lastPos.x()) / width();
	GLfloat dy = GLfloat(event-&gt;y() - lastPos.y()) / height();

	if (event-&gt;buttons() &amp; Qt::LeftButton)
	{
		rotationX += 180*dy;
		rotationY += 180*dx;
		updateGL();
	}
	else
	{
		if (event-&gt;buttons() &amp; Qt::RightButton)
		{
			rotationX += 180*dy;
			rotationZ += 180*dx;
			updateGL();
		}
	}
	lastPos = event-&gt;pos();
}

void Tetrahedron::mouseDoubleClickEvent(QMouseEvent *event)
{
	int face = faceAtPosition(event-&gt;pos());
	if (face != -1)
	{
		QColor color = QColorDialog::getColor(faceColors[face], this);
		if (color.isValid())
		{
			faceColors[face] = color;
			updateGL();
		}
	}
}

int Tetrahedron::faceAtPosition(const QPoint &amp;pos)
{
	const int MaxSize = 512;
	GLuint buffer[MaxSize];
	GLint viewport[4];

	makeCurrent();

	glGetIntegerv(GL_VIEWPORT, viewport);
	glSelectBuffer(MaxSize, buffer);
	glRenderMode(GL_SELECT);

	glInitNames();
	glPushName(0);

	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	gluPickMatrix(GLdouble(pos.x()), GLdouble(viewport[3] - pos.y()), 5.0, 5.0, viewport);
	GLfloat x = GLfloat(width()) / height();
	glFrustum(-x, x, -1.0, 1.0, 4.0, 15.0);
	draw();
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();

	if (!glRenderMode(GL_RENDER))
	{
		return -1;
	}
	return buffer[3];
}
</code></pre>
<p>Main.cpp:</p>
<pre><code class="language-cpp">#include &lt;QApplication&gt;
#include &lt;iostream&gt;

#include &quot;tetrahedron.h&quot;

int main(int argc, char *argv[])
{
	QApplication app(argc, argv);

	if (!QGLFormat::hasOpenGL())
	{
		std::cerr &lt;&lt; &quot;Geht nicht&quot; &lt;&lt; std::endl;
		return 1;
	}

	Tetrahedron tetrahedron;
	tetrahedron.setWindowTitle(&quot;Tetrahedron&quot;);
	tetrahedron.resize(300, 300);
	tetrahedron.show();

	return app.exec();
}
</code></pre>
<p>Danke an alle, die versuchen mir zu helfen und sorry für so viel Code!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1879640</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1879640</guid><dc:creator><![CDATA[sudo rm -rf]]></dc:creator><pubDate>Thu, 08 Apr 2010 19:30:20 GMT</pubDate></item><item><title><![CDATA[Reply to C++ QT4 OpenGL on Thu, 08 Apr 2010 19:40:37 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">void berechne_eckpunkte(float ursprungX, float ursprungY, float ursprungZ)
</code></pre>
<p>=&gt;</p>
<pre><code class="language-cpp">void Tetrahedron::berechne_eckpunkte(float ursprungX, float ursprungY, float ursprungZ)
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1879647</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1879647</guid><dc:creator><![CDATA[jokester]]></dc:creator><pubDate>Thu, 08 Apr 2010 19:40:37 GMT</pubDate></item><item><title><![CDATA[Reply to C++ QT4 OpenGL on Thu, 08 Apr 2010 19:42:58 GMT]]></title><description><![CDATA[<p>ohhhhhh!!!!!<br />
*eigenen schädel einkloppen*</p>
<p>DANKE!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1879649</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1879649</guid><dc:creator><![CDATA[sudo rm -rf]]></dc:creator><pubDate>Thu, 08 Apr 2010 19:42:58 GMT</pubDate></item><item><title><![CDATA[Reply to C++ QT4 OpenGL on Thu, 08 Apr 2010 20:31:16 GMT]]></title><description><![CDATA[<p>mhh, weiß jemand, wie ich die pyramide bei linksklick drehen kann?<br />
btw: wie kann ich die &quot;kamera&quot; bewegen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1879670</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1879670</guid><dc:creator><![CDATA[sudo rm -rf]]></dc:creator><pubDate>Thu, 08 Apr 2010 20:31:16 GMT</pubDate></item></channel></rss>