<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: IshaqKassam</title>
    <description>The latest articles on DEV Community by IshaqKassam (@ishaqkassam).</description>
    <link>https://dev.to/ishaqkassam</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F579544%2F72804330-8149-4a2f-b70a-28604e997d43.jpg</url>
      <title>DEV Community: IshaqKassam</title>
      <link>https://dev.to/ishaqkassam</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ishaqkassam"/>
    <language>en</language>
    <item>
      <title>Drawing a Crescent Moon with OpenGL - GLFW/GLEW C++</title>
      <dc:creator>IshaqKassam</dc:creator>
      <pubDate>Wed, 10 Nov 2021 11:27:26 +0000</pubDate>
      <link>https://dev.to/ishaqkassam/drawing-a-crescent-moon-with-opengl-glfwglew-c-4fki</link>
      <guid>https://dev.to/ishaqkassam/drawing-a-crescent-moon-with-opengl-glfwglew-c-4fki</guid>
      <description>&lt;p&gt;This is the 3rd article on OpenGL, drawing 2D objects in OpenGL using c++. If you haven't been following through, here is the first article where we started drawing a circle in OpenGL:&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/ishaqkassam" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F579544%2F72804330-8149-4a2f-b70a-28604e997d43.jpg" alt="ishaqkassam"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/ishaqkassam/drawing-a-circle-using-opengl-glfwglew-c-1247" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Drawing a Circle using OpenGL - glfw/glew c++&lt;/h2&gt;
      &lt;h3&gt;IshaqKassam ・ Nov 8 '21&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#cpp&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#opengl&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#glfw&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#glew&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;In this article, we are going to draw a Crescent Moon using the concepts of circle. We'll be using 2 Circles, with different fill colors, to give us the Crescent moon effect. Let's look at the code for circle:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
void drawCircleFill(float cx, float cy, float r, int num_segments)
{
    float theta = 3.1415926 * 2 / float(num_segments);
    float tangetial_factor = tanf(theta);//calculate the tangential factor 
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    float radial_factor = cosf(theta);//calculate the radial factor 

    float x = r;//we start at angle = 0 

    float y = 0;

    glBegin(GL_POLYGON);
    for (int ii = 0; ii &amp;lt; num_segments; ii++)
    {
        glVertex2f(x + cx, y + cy);//output vertex 

        float tx = -y;
        float ty = x;

        x += tx * tangetial_factor;
        y += ty * tangetial_factor;

        x *= radial_factor;
        y *= radial_factor;
    }
    glEnd();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We'll call the method twice, to give us 2 circles, giving them different positions and color, to give us the desired crescent.&lt;/p&gt;

&lt;p&gt;Let's call the function in the &lt;code&gt;main()&lt;/code&gt; as below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;glColor3f(0.8f, 0.6f, 0.2f);//golden color
drawCircleFill(500, 400, 40, 360);

glColor3f(1.0f, 1.0f, 1.0f); //white
drawCircleFill(525, 410, 40, 360);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice how the &lt;code&gt;glColor3f&lt;/code&gt; method works. If defined, the method implements the color to all the renders below the line, until reset. So the first Circle drawn takes the golden color, and the second Circle takes the color white. You can change the color of the second Circle to match the background, to attain the desired Crescent figure.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3na1j6vehl7jllu10h53.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3na1j6vehl7jllu10h53.png" alt=" " width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's it for this article, see you in the upcoming!&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>opengl</category>
      <category>2dgraphics</category>
      <category>glfw</category>
    </item>
    <item>
      <title>Drawing a Semi-Circle using OpenGL - glfw/glew c++</title>
      <dc:creator>IshaqKassam</dc:creator>
      <pubDate>Mon, 08 Nov 2021 15:39:31 +0000</pubDate>
      <link>https://dev.to/ishaqkassam/drawing-a-semi-circle-using-opengl-glfwglew-c-1pmi</link>
      <guid>https://dev.to/ishaqkassam/drawing-a-semi-circle-using-opengl-glfwglew-c-1pmi</guid>
      <description>&lt;p&gt;In this article, we are going to draw a semi-circle using OpenGL, glfw - c++.&lt;/p&gt;

&lt;p&gt;I'll be referring back to the previous tutorial: link here:&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/ishaqkassam" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F579544%2F72804330-8149-4a2f-b70a-28604e997d43.jpg" alt="ishaqkassam"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/ishaqkassam/drawing-a-circle-using-opengl-glfwglew-c-1247" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Drawing a Circle using OpenGL - glfw/glew c++&lt;/h2&gt;
      &lt;h3&gt;IshaqKassam ・ Nov 8 '21&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#cpp&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#opengl&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#glfw&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#glew&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;Before going in to the details, locate the first line in the &lt;code&gt;drawCircle&lt;/code&gt; function and remove the &lt;code&gt;* 2&lt;/code&gt; so that you have this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;float theta = 3.1415926 / float(num_segments);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In mathematics, a full circle, having 360 degrees, can be represented in Radian measure as &lt;code&gt;2 PI&lt;/code&gt;. Simple logic then tells us that 180 degrees is simply &lt;code&gt;PI&lt;/code&gt;. Hence, in the code, to convert the full circle into a semi circle, all we did was to remove the &lt;code&gt;* 2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Reading more on Radian measure and deeper concepts might help, but I hope this simplistic explanation helped.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>cpp</category>
      <category>opengl</category>
      <category>glfw</category>
    </item>
    <item>
      <title>Drawing a Circle using OpenGL - glfw/glew c++</title>
      <dc:creator>IshaqKassam</dc:creator>
      <pubDate>Mon, 08 Nov 2021 11:44:42 +0000</pubDate>
      <link>https://dev.to/ishaqkassam/drawing-a-circle-using-opengl-glfwglew-c-1247</link>
      <guid>https://dev.to/ishaqkassam/drawing-a-circle-using-opengl-glfwglew-c-1247</guid>
      <description>&lt;p&gt;Hoping that you have already setup glfw &amp;amp; glew, and are ready to learn how to draw 2D shapes, let's dive straight into this. In this article we are going to learn how to draw a circle in openGL using glfw, c++ language. &lt;/p&gt;

&lt;p&gt;Here is the code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
void drawCircle(float cx, float cy, float r, int num_segments)
{
    float theta = 3.1415926 * 2 / float(num_segments);
    float tangetial_factor = tanf(theta);//calculate the tangential factor 

    float radial_factor = cosf(theta);//calculate the radial factor 

    float x = r;//we start at angle = 0 

    float y = 0;
    glLineWidth(2);
    glBegin(GL_LINE_LOOP);
    for (int ii = 0; ii &amp;lt; num_segments; ii++)
    {
        glVertex2f(x + cx, y + cy);//output vertex 

        //calculate the tangential vector 
        //remember, the radial vector is (x, y) 
        //to get the tangential vector we flip those coordinates and negate one of them 

        float tx = -y;
        float ty = x;

        //add the tangential vector 

        x += tx * tangetial_factor;
        y += ty * tangetial_factor;

        //correct using the radial factor 

        x *= radial_factor;
        y *= radial_factor;
    }
    glEnd();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function above can then be called in the main() function as such:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;drawCircle(250, 250, 100, 360);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To change the circle color, you can use the glColor3f() method which takes in 3 parameters, for the RGB values. &lt;/p&gt;

&lt;p&gt;Add this line before calling the &lt;code&gt;drawCircle&lt;/code&gt;  function&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;glColor3f(0.0, 0.5, 0.5);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo9rhdc4pahcr1zfq7oa1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo9rhdc4pahcr1zfq7oa1.png" alt=" " width="613" height="448"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>opengl</category>
      <category>glfw</category>
      <category>glew</category>
    </item>
  </channel>
</rss>
