![]() |
|
#1
|
|||
|
|||
OpenGL DrawScene helpO.K. So I've been learning a lot of OpenGL and I was messing around with drawing shapes when I got the idea of making a triangle, which could via the W,A,S,D keys have its vertices moved about the screen to reshape it.
I got it working with 1 vertex, just by making a GLfloat , and manipulating it with CPP / C++ / C Code:
The theory I came up with to make this possible, was to have multidimensional arrays which used a variable in the brackets to change the vertex every time the user hits enter.... Heres what I got. keep in mind this is just a small piece out of a simple OpenGL framework **My Variables** CPP / C++ / C Code:
CPP / C++ / C Code:
In theory, this should make it so you can cycle through the 3 vertices and moved the X position, positive or negative. I get no errors when I compile it, but when I run it theres no triangle... which makes sense considering all of the points on it are 0.0f . But when I push 'W' to bring the 1st vertex up, nothing happens. Thoughts? Thx in advance, Seraphis |
|
#2
|
|||
|
|||
Re: OpenGL DrawScene helpEh no takers? ;D
|
|
#3
|
|||
|
|||
Re: OpenGL DrawScene helpQuote:
In looking at your code, we see no initialization of the p1 global before being used in the 'W' key related code that you mention. What is the value of p1[stc] when you step through your code with the debugger? How can we possibly know based on the posted code? Maybe that's why no one cares to answer the post? How do we even know that the 'W' key code block is being executed? In your code, you're passing p1, p2, p3 into glVertex3f, but your code never modifies the p2 or p3 float arrays. In fact, your code seems only to attempt to modify p1[0..2], which one would think would be what you would want to pass into glVertex3f. You also declare each of these float arrays to be 10 elements deep. Why? ...if you plan only to use 3, why not declare it as such? I think that you're encountering an oversight in what you mean to do with the arrays, however, more importantly, I think that you're missing some rather obvious fundamentals of programming. You may want to review the basics of C programming before attempting a rather complex API like OpenGL. Since OpenGL gives the programmer direct access to the video hardware, it is not terribly difficult to lock-up the system with a few errant lines of code. Here is a thought. Write a piece of code that draws a known triangle based on variables that you've initialized in your array(s). Once successfully rendered, then modify the values in the array(s) using the "user interface" code. The idea of using known-good data first and then changing it is not something that I invented, but you may find it a practical choice in lieu of first gaining more experience in C programming. Also, start using a debugger everytime your code doesn't do what you expect. Know that your data members are being initialized to the values that you expect. Always initialize your variables before you use them. :davis: |
|
#4
|
|||
|
|||
Re: OpenGL DrawScene helpYeh, sorry for the short posting. I was just trying to not post a novel... I like the constructive criticism tho, it does help. I will try this again with a more in-depth look at it.
Thank you, Seraphis |
|
#5
|
|||
|
|||
Re: OpenGL DrawScene helpQuote:
Maybe this boiler-plate code will help some? CPP / C++ / C Code:
...use "r" to rotate and "s" to stop. :davis: |
Recent GIDBlog
2nd Week of IA Training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| OpenGL to clipboard | rodrigomorante | OpenGL Programming | 0 | 21-Dec-2005 19:41 |
| What is OpenGL? | Shrikharan | OpenGL Programming | 6 | 21-Dec-2005 17:47 |
| C++ game programming OpenGL | oozsakarya | OpenGL Programming | 2 | 13-Nov-2005 13:50 |
| nVidia & OpenGL Problems in windows XP | marjasin | Computer Hardware Forum | 21 | 30-Aug-2004 00:57 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The