Note that there are some explanatory texts on larger screens.

plurals
  1. POcan't draw item after I get it from queue
    primarykey
    data
    text
    <p>I've got three <code>CustomPixel</code> objects - when I draw it directly in draw function <code>draw</code> - it works normal.</p> <p>But when I put them into <code>queue</code> and draw them one after another with <code>while</code> loop - there are not any rectangles on the screen.</p> <p>Here is my code</p> <pre><code>#include &lt;gl\glew.h&gt; #include &lt;gl\freeglut.h&gt; #include &lt;iostream&gt; #include "OpenGL.h" #include "Constants.h" #include "Geometrics.h" #include &lt;queue&gt; std::queue&lt;CustomPixel*&gt; queue; CustomPixel *pixel1 = new CustomPixel(0.0, 250.0, 100.0); CustomPixel *pixel2 = new CustomPixel(101.0, 250.0, 100.0); CustomPixel *pixel3 = new CustomPixel(202.0, 250.0, 100.0); void draw() { glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POINTS); pixel1-&gt;drawRectangle(1.0, 0.0, 0.0); //it works! if (!queue.empty()) { while(!queue.empty()) { CustomPixel *item = queue.front(); //doesn't work -&gt; but //in debugger it enters this method with correct CustomPixel //attributes(x1, x2...etc) item-&gt;drawRectangle(1.0, 0.0, 0.0); queue.pop(); } } glEnd(); glFlush(); }; int main(int iArgc, char** cppArgv) { //console for debug OpenGL *opengl = new OpenGL(iArgc, cppArgv); opengl-&gt;setSize(WIDTH, HEIGHT); opengl-&gt;setWindowPosition(200, 200); opengl-&gt;create(); //after OpenGL object created -&gt; fill the queue with objects and the draw it queue.push(pixel1); queue.push(pixel2); queue.push(pixel3); opengl-&gt;run(draw);//&lt;- can be any draw function //clean all garbage delete pixel1; delete pixel2; delete pixel3; delete opengl; return 0; } </code></pre> <p>P.S it has been a long time since I used c++. Maybe I forgot something?</p> <p>Here drawRectangle method</p> <pre><code>void CustomPixel::drawRectangle(float r, float g, float b) { glColor3f(r, g, b); CustomLine::drawLine(this-&gt;x1, this-&gt;y1, this-&gt;x1, this-&gt;y2); CustomLine::drawLine(this-&gt;x1, this-&gt;y1, this-&gt;x2, this-&gt;y1); CustomLine::drawLine(this-&gt;x2, this-&gt;y1, this-&gt;x2, this-&gt;y2); CustomLine::drawLine(this-&gt;x2, this-&gt;y2, this-&gt;x1, this-&gt;y2); }; </code></pre> <p>and drawLine</p> <pre><code>void CustomLine::drawLine(float x1, float y1, float x2, float y2) { float dx = (x2 - x1) / STEP; float dy = (y2 - y1) / STEP; float vX = x1 / WIDTH; float vY = y1 / HEIGHT; for(int i = 0; i &lt; STEP; i++) { glVertex2f(vX + dx * i / WIDTH, vY + dy * i / HEIGHT); } }; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload