Solved

a trinagle in  3D

Posted on 2010-09-22
15
314 Views
Last Modified: 2012-05-10
Hi,
I need to render a triangle in 3D in Qt . I need any example code to start from it . or easy guide to do that a triangle.

Thanks in advance
0
Comment
Question by:obad62
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
15 Comments
 
LVL 33

Accepted Solution

by:
pgnatyuk earned 400 total points
ID: 33739029
QPainter painter;
QPen pen( red, 2 );
painter.begin( this );   // if it is in void in the paintEvent
painter.setPen( pen );
painter.drawLine(  40,  30,  240,130 );
painter.drawLine( 240,130, 140,80 );
painter.drawLine( 140,  80,   40,30 );
painter.end();

Basic Drawing Example
http://www.greyc.ensicaen.fr/ensicaen/Docs/Qt4/painting-basicdrawing.html
0
 
LVL 33

Assisted Solution

by:pgnatyuk
pgnatyuk earned 400 total points
ID: 33739270
Now I see '3D' in your question - sorry. I think you ask about OpenGL. So it will be something like that:
void GLWidget::paintGL()
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glLoadIdentity();
  glTranslatef(-1.5f,0.0f,-6.0f);
  glBegin(GL_TRIANGLES);
    glVertex3f( 0.0f, 1.0f, 0.0f);
    glVertex3f(-1.0f,-1.0f, 0.0f);
    glVertex3f( 1.0f,-1.0f, 0.0f);
  glEnd();
}

Here is an example
Hello GL Example
http://doc.trolltech.com/4.5/opengl-hellogl.html

2D Painting Example
http://doc.trolltech.com/4.5/opengl-2dpainting.html

Overpainting Example
http://doc.trolltech.com/4.5/opengl-overpainting.html

OpenGL:
Qt for Embedded Linux and OpenGL
http://doc.trolltech.com/4.5/qt-embedded-opengl.html

Here is a simple tutorial:
http://www.digitalfanatics.org/projects/qt_tutorial/chapter14.html

TUTORIAL: Setting up a basic OpenGL application using Qt
http://episteme.hin.no/wiki/index.php/TUTORIAL:_Setting_up_a_basic_OpenGL_application_using_Qt

0
 

Author Comment

by:obad62
ID: 33739530
I know that in 2D i need it in 3D. By the way, thank you for your post
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:obad62
ID: 33739541
and I am sorry after post my above replay I see your post
0
 

Author Comment

by:obad62
ID: 33739574
To declare that : void GLWidget::paintGL() do you know which library should I include i use to include that :

#include <QtOpenGL/QtOpenGL>
but still wrong
0
 

Author Comment

by:obad62
ID: 33739580
To declare that : void GLWidget::paintGL() do you know which library should I include i use to include that :

#include <QtOpenGL/QtOpenGL>
but still wrong
0
 

Author Comment

by:obad62
ID: 33739630
I have received this error message :
6: error: 'GLWidget' has not been declared
0
 
LVL 33

Assisted Solution

by:pgnatyuk
pgnatyuk earned 400 total points
ID: 33741163
Why you don't want to take these two tutorials first?
TUTORIAL: Setting up a basic OpenGL application using Qt
http://episteme.hin.no/wiki/index.php/TUTORIAL:_Setting_up_a_basic_OpenGL_application_using_Qt

OpenGL
http://www.digitalfanatics.org/projects/qt_tutorial/chapter14.html

The last one has the a source code for download ("here" in the end of the page).

Class GLWidget is from the first tutorial. In the end there is a link to download the source code.
class GLWidget : public QGLWidget, public GMWindow {
public:
  GLWidget( QWidget *parent = 0 );
  ~GLWidget();

  void          clear();
  void          initCameras();

protected:
  // ********************
  // Derived QT functions
  void          glDraw();
  void	        initializeGL();
  void          paintEvent( QPaintEvent* e );
  void          paintGL();
  void          resizeGL( int w, int h );
  void	        timerEvent( QTimerEvent *qte );

  // *********************************
  // Derived GMlib::GMWindow functions
  void	        swapBuffers();
  bool	        toggleRun();

private:
  int           _timerID;
};

Open in new window

GLWidget.cpp
GLWidget.h
Application.h
Application.cpp
main.cpp
0
 
LVL 33

Assisted Solution

by:pgnatyuk
pgnatyuk earned 400 total points
ID: 33741194
In the previous comment I took the source code from
TUTORIAL: Setting up a basic OpenGL application using Qt
http://episteme.hin.no/wiki/index.php/TUTORIAL:_Setting_up_a_basic_OpenGL_application_using_Qt

It uses GMLib.

If you don't want this library, take another tutorial and source code from there:
OpenGL
http://www.digitalfanatics.org/projects/qt_tutorial/chapter14.html

OpenGL tutorials are here:
http://nehe.gamedev.net/


nehewidget.h
nehewidget.cpp
ch11.h
main.cpp
0
 

Author Comment

by:obad62
ID: 33742048
Hi pgnatyuk,

I am realy glad for your posts and many thanks for that effort I will try to apply that tutorials and if I found any stack I will post it, but can you please tell me what is the correct section of this tech. I use to post like this question on Qt section , c++ and graphics as well.
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33742124
You need to pass these first tutorials. Then you will see that the questions are about OpenGL. C++, Qt, ... help you to wrap the OpenGL code. There is an OpenGL zone here on EE, you will meet very strong experts there.
0
 
LVL 12

Assisted Solution

by:HappyCactus
HappyCactus earned 100 total points
ID: 33742158
You must enable the OpenGL in your .pro file.

QT += opengl

With that directive, the correct include path to Qt+OpenGl headers are appended to your makefile. Then, include  should work.
But again, see the tutorials. Since you are working with GMLib, that already support QT+OpenGL, maybe the GLWidget is already included or a GMWindow is already derived from a QGLWidget, so maybe you are wrong with a multiple inheritance.
 
0
 

Author Comment

by:obad62
ID: 33752347
Thanks for all and Thanks for ikework
I will post a specific question in OpenGl zone. and I have got a massive help from these zone
0
 

Author Closing Comment

by:obad62
ID: 33752352
Thank you
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
c++ getting the first 10 characters of a char* string 11 111
bunnyEars2 challenge 6 182
count7 challenge 12 138
Starcraft 2 - how do I expand without gas? 8 40
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question