Results 1 to 2 of 2

Thread: converting program and functions fromVs2013 to qt

  1. #1
    Join Date
    Jun 2015
    Posts
    4
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default converting program and functions fromVs2013 to qt

    My dears ,
    I have a opengl c++ program that works fine in the vs2013 and draws tree.
    Now I want to use that program in the qt gui open gl project.
    I know how to make gui program and add classes and headers.
    But I do not know how the relevant functions are implemented in headers,classes and .pro files.
    Any one please take the program and implement it in such a way that it works with qt project for drawing opengl tree.
    Qt Code:
    1. [CODE]
    2. #include <stdafx.h>
    3. #include <Windows.h>
    4. #include <Mmsystem.h>
    5. #include <GL/glut.h>
    6. #include <stdlib.h>
    7. #include <fstream>
    8. #include <iostream>
    9. #include <vector>
    10. #include <string>
    11. #include <math.h>
    12. #include <time.h>;
    13.  
    14. using namespace std;
    15.  
    16. const float PI = 3.14, DEPTH = 4;
    17. // Start and end of camera movement
    18. const int ENDX = 10, STARTX = -400;
    19. // Angle of branches, and depth of tree
    20. float ANGLE = 20, depth = 0;
    21. vector<string> *trees = new vector<string>();
    22.  
    23. double lastTime = 0, elapsedTime = 0, lastElapsedTime = 0;
    24.  
    25. bool cam = false;
    26.  
    27. float eyeX, eyeY, eyeZ, lookX, lookY, lookZ,
    28. upX, upY, upZ, fieldOfView, length = 0.001, num = 0,
    29. incr = 0.1;
    30.  
    31. float lineWidth = 5;
    32. // L-System
    33. string str = "X";
    34.  
    35. void push(){
    36. glPushMatrix();
    37. if (lineWidth > 0)
    38. lineWidth -= 1;
    39.  
    40. }
    41.  
    42. void pop(){
    43. glPopMatrix();
    44. lineWidth += 1;
    45.  
    46. }
    47.  
    48. void rotL(){
    49. glRotatef(ANGLE, 1, 0, 0);
    50. glRotatef(ANGLE * 4, 0, 1, 0);
    51. glRotatef(ANGLE, 0, 0, 1);
    52. }
    53. void rotR(){
    54. glRotatef(-ANGLE, 1, 0, 0);
    55. glRotatef(ANGLE * 4, 0, 1, 0);
    56. glRotatef(-ANGLE, 0, 0, 1);
    57. }
    58. void leaf(){
    59. glPushAttrib(GL_LIGHTING_BIT);//saves current lighting stuff
    60. //glColor3f(0.50, 1.0, 0.0);
    61. GLfloat ambient[4] = { 0.50, 1.0, 0.0 }; // ambient reflection
    62. GLfloat specular[4] = { 0.55, 1.0, 0.0 }; // specular reflection
    63. GLfloat diffuse[4] = { 0.50, 0.9, 0.0 }; // diffuse reflection
    64.  
    65. // set the ambient reflection for the object
    66. glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient);
    67. // set the diffuse reflection for the object
    68. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
    69. // set the specular reflection for the object
    70. glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
    71. // set the size of the specular highlights
    72. glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 20.0);
    73.  
    74. //glutSolidCube(depth+1);
    75. glBegin(GL_TRIANGLES);
    76. glVertex3f(0, 0, 0);
    77. glVertex3f(0.2, 0, 0.3);
    78. glVertex3f(0, 1, 0);
    79. glVertex3f(0, 0, 0);
    80. glVertex3f(-0.2, 0, -0.3);
    81. glVertex3f(0, 1, 0);
    82. glEnd();
    83. glPopAttrib();
    84. }
    85.  
    86. void drawLine(){
    87. glPushAttrib(GL_LIGHTING_BIT);//saves current lighting stuff
    88.  
    89. //glColor3f(0.55, 0.27, 0.07);
    90. GLfloat ambient[4] = { 0.55, 0.27, 0.07 }; // ambient reflection
    91. GLfloat specular[4] = { 0.55, 0.27, 0.07 }; // specular reflection
    92. GLfloat diffuse[4] = { 0.55, 0.27, 0.07 }; // diffuse reflection
    93.  
    94.  
    95. // set the ambient reflection for the object
    96. glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient);
    97. // set the diffuse reflection for the object
    98. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
    99. // set the specular reflection for the object
    100. //glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
    101. glLineWidth(lineWidth);
    102.  
    103. glBegin(GL_LINES);
    104.  
    105. glVertex3f(0, 0, 0);
    106. glVertex3f(0, length, 0);
    107. glEnd();
    108.  
    109. glTranslatef(0, length, 0);
    110. glPopAttrib();
    111. }
    112.  
    113. void draw(){
    114.  
    115. string ch = "";
    116. string LSystem = trees->at(depth);
    117. for (int i = 0; i < LSystem.length(); i++){
    118. ch = LSystem.at(i);
    119.  
    120. if (ch.compare("D") == 0 || ch.compare("X") == 0){
    121. drawLine();
    122. }
    123.  
    124.  
    125. else if (ch.compare("[") == 0){
    126. push();
    127. }
    128. else if (ch.compare("]") == 0){
    129. pop();
    130. }
    131. else if (ch.compare("V") == 0){
    132. leaf();
    133. }
    134. else if (ch.compare("R") == 0){
    135. rotR();
    136. }
    137. else if (ch.compare("L") == 0){
    138. rotL();
    139. }
    140. }
    141. }
    142.  
    143. void expand(float num){
    144. string ch = "";
    145.  
    146. for (int i = 0; i < str.length(); i++){
    147. ch = str.at(i);
    148.  
    149. if (ch.compare("D") == 0){
    150. str.replace(i, 1, "DD");
    151. i = i + 1;
    152. }
    153. else if (ch.compare("X") == 0){
    154.  
    155. if (num < 0.4){
    156. //LSystem.replace(i, 1, "D[LX]D[RX]LX");
    157. str.replace(i, 1, "D[LXV]D[RXV]LX");
    158.  
    159. }
    160. else {
    161. //LSystem.replace(i, 1, "D[RX]D[LX]RX");
    162. str.replace(i, 1, "D[RXV]D[LXV]RX");
    163. }
    164. i = i + 13; //11
    165. }
    166.  
    167. }
    168. trees->push_back(str);
    169. }
    170.  
    171. void display(void){
    172. // start by clearing the screen and depth buffer
    173. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    174. glMatrixMode(GL_PROJECTION);
    175. glLoadIdentity();
    176. gluPerspective(fieldOfView, 1.0, 1, 2000);
    177. glMatrixMode(GL_MODELVIEW);
    178. glLoadIdentity();
    179. gluLookAt(eyeX, eyeY, eyeZ, lookX, lookY, lookZ, 0, 1, 0);
    180.  
    181. glPushMatrix();
    182.  
    183.  
    184. //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    185.  
    186. glPushAttrib(GL_LIGHTING_BIT); //saves current lighting stuff
    187. GLfloat ambient[4] = { 0.82, 0.41, 0.12 }; // ambient reflection
    188. GLfloat diffuse[4] = { 0.82, 0.41, 0.12 }; // diffuse reflection
    189. // set the ambient reflection for the object
    190. glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient);
    191. // set the diffuse reflection for the object
    192. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
    193.  
    194. glBegin(GL_TRIANGLES);
    195. glVertex3f(-10, 0, -10);
    196. glVertex3f(10, 0, -10);
    197. glVertex3f(10, 0, 10);
    198. glVertex3f(-10, 0, 10);
    199. glVertex3f(-10, 0, -10);
    200. glVertex3f(10, 0, 10);
    201.  
    202. glEnd();
    203. glPopMatrix();
    204. glPopAttrib();
    205.  
    206. draw();
    207. glutSwapBuffers();
    208. glutPostRedisplay();
    209. }
    210.  
    211. void animate(){
    212. if (lastTime == 0)
    213. lastTime = timeGetTime();
    214.  
    215. elapsedTime = timeGetTime() - lastTime;
    216.  
    217. // Change the angle to make it blow in the wind
    218. float numR = (float)rand() / RAND_MAX;
    219.  
    220.  
    221. if (ANGLE > 21.5){
    222. if (numR < 0.5){
    223. incr = -0.15;
    224. }
    225. else {
    226. incr = -0.1;
    227. }
    228. }
    229. else if (ANGLE < 18.5){
    230. if (numR > 0.5){
    231. incr = 0.15;
    232. }
    233. else {
    234. incr = 0.1;
    235. }
    236. }
    237. ANGLE += incr;
    238.  
    239. if (depth < DEPTH)
    240. length += 0.001;
    241.  
    242. if (elapsedTime - lastElapsedTime > 1000 && depth < DEPTH){
    243. depth++;
    244. lastElapsedTime = elapsedTime;
    245. cout << "a ";
    246.  
    247. }
    248. elapsedTime = elapsedTime / 2000;
    249. float t = (sin((elapsedTime*PI - PI / 2)) + 1) / 2;
    250. float p = (1 - t)*STARTX + t*ENDX;
    251.  
    252. if (cam)
    253. eyeX = p;
    254. glutPostRedisplay();
    255. }
    256.  
    257. void keyboard(unsigned char key, int x, int y)
    258. {
    259. switch (key) {
    260. case 113: // q - Exit the program
    261. exit(0);
    262. break;
    263. case 119: // w - Reset the camera
    264. fieldOfView = 45;
    265. eyeX = 10;
    266. eyeY = 10;
    267. eyeZ = 250;
    268. lookX = 10;
    269. lookY = 10;
    270. lookZ = 50;
    271. break;
    272. case 122: // z - Reduce the field of view of the camera
    273. fieldOfView -= 10;
    274. glutPostRedisplay();
    275. break;
    276. case 120: // x - Increase the field of view of the camera
    277. fieldOfView += 10;
    278. glutPostRedisplay();
    279. break;
    280. case 115: // s - Stop moving the camera
    281. cam = false;
    282. break;
    283. case 97: // a - Move the camera
    284. cam = true;
    285. break;
    286. case 100: // d - Increase camera X-coordinate
    287. eyeX++;
    288. break;
    289. case 102: // f - Decrease camera X-coordinate
    290. eyeX--;
    291. break;
    292. }
    293. }
    294.  
    295. int main(int argc, char** argv){
    296. glutInit(&argc, argv);
    297. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    298. glutInitWindowSize(1000, 1000);
    299. glutInitWindowPosition(0, 0);
    300. glutCreateWindow("Erik Paluka");
    301.  
    302. fieldOfView = 45;
    303. eyeX = 10;
    304. eyeY = 10;
    305. eyeZ = 250;
    306. lookX = 10;
    307. lookY = 10;
    308. lookZ = 40;
    309. srand(time(NULL));
    310. num = (float)rand() / RAND_MAX;
    311.  
    312.  
    313. // set the lighting
    314. glShadeModel(GL_SMOOTH);
    315. GLfloat lightP[4] = { 0.0, 800.0, 0.0, 1.0 };
    316. glLightfv(GL_LIGHT0, GL_POSITION, lightP);
    317.  
    318. // set the ambient light colour
    319. GLfloat lightA[4] = { 0.0, 0.9, 0.9, 1 };
    320. glLightfv(GL_LIGHT0, GL_AMBIENT, lightA);
    321.  
    322. // set the specular light colour
    323. GLfloat lightS[4] = { 0.9, 0.9, 0.9, 1.0 };
    324. glLightfv(GL_LIGHT0, GL_SPECULAR, lightS);
    325.  
    326. // set the diffuse light colour
    327. GLfloat lightD[4] = { 0.9, 0.9, 0.9, 1.0 };
    328. glLightfv(GL_LIGHT0, GL_DIFFUSE, lightD);
    329.  
    330. glEnable(GL_LIGHTING);
    331. glEnable(GL_LIGHT0);
    332.  
    333.  
    334. /* Use depth buffering for hidden surface elimination. */
    335. glEnable(GL_DEPTH_TEST);
    336.  
    337. glutDisplayFunc(display);
    338. glutKeyboardFunc(keyboard);
    339. glutIdleFunc(animate);
    340. trees = new vector<string>();
    341. for (int i = 0; i <= DEPTH; i++){
    342. expand(num);
    343. }
    344. glutMainLoop();
    345. return 0;
    346. }
    To copy to clipboard, switch view to plain text mode 
    [/CODE]

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: converting program and functions fromVs2013 to qt

    Have you looked at any of the OpenGL tutorials or examples that come with Qt? If you have working code already, you should be able to copy the example project and modify it by copying your code into the appropriate places in the example.

    Any one please take the program and implement it in such a way that it works with qt project for drawing opengl tree.
    You mean you want someone to do the job for you? Good luck with that.

Similar Threads

  1. Qt program with libtiff functions
    By dulan2010 in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 12th July 2011, 11:58
  2. Replies: 1
    Last Post: 30th April 2010, 14:25
  3. Converting a php program to Qt
    By srohit24 in forum Qt Programming
    Replies: 7
    Last Post: 19th March 2009, 20:33
  4. Replies: 7
    Last Post: 19th January 2008, 16:29
  5. Dynamically add functions to qt program
    By sincnarf in forum Qt Programming
    Replies: 31
    Last Post: 22nd September 2007, 04:55

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.