Jump to content

  • Log In with Google      Sign In   
  • Create Account


drawing 2D very basic shapes


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 leagal4ever   Members   -  Reputation: 489

Like
0Likes
Like

Posted 14 January 2013 - 01:08 PM

Hello, im having problem with drawing 2D very basic shapes.

Questions:
1. How draw Quad just with lines, corner should be sharp.
2. Quad with border and filled color, each with different color.
3. Triangle is again not sharp also bottom line seems to be thiner.
4. Position in code is set to 100, 100 (quad) in window position does not match(y only?) its more like on half so on 300px.
Edit: just saw problem there are many width and height to set, forgot one


I have added code since its very small and have many mistakes inside.

Thanks for help.

qqqqqqqqqqqqqqqf.png

#include "sdl.h"
#include "sdl_opengl.h"
#include <iostream>
#include <SDL_image.h>
#include <string>
#include <vector>

using std::vector;
using std::cout;
using std::endl;

vector < vector <int> >  points_vec;

int WIDTH = 800;
int HEIGHT = 600;

int main(int argc, char* argv[])
{
    //initialize SDL
    SDL_Init(SDL_INIT_EVERYTHING);

    //Set OpenGL memory usage
    SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8);
    SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8);
    SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8);
    SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8);
    SDL_GL_SetAttribute( SDL_GL_BUFFER_SIZE, 32);
    SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16);
    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1);

    //Caption of the window
    SDL_WM_SetCaption("Our first game", NULL);

    //Size of the window
    SDL_SetVideoMode(WIDTH, HEIGHT, 32, SDL_OPENGL);

    //Specific the clear color
    glClearColor(1, 1, 1, 1);// RED, GREEN, BLUE, ALPHA

    //What portion of the screen we will display
    glViewport(0, 0, WIDTH, HEIGHT);

    //Shader model - use this
    glShadeModel(GL_SMOOTH);

    //2D rendering
    glMatrixMode(GL_PROJECTION | GL_MODELVIEW);

    //"Save it"
    glLoadIdentity();

    // Disable depth test
    glDisable(GL_DEPTH_TEST);

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    //Handle the main loop
    bool isRunning = true;

    //For handling with event
    SDL_Event event;

    // Main game loop
    while(isRunning)
    {
        // events
        while( SDL_PollEvent(&event) )
        {
            if( event.type == SDL_QUIT )
            {
                isRunning = false;
            }
        }

        //RENDERING to the screen
        glClear(GL_COLOR_BUFFER_BIT);

        glPushMatrix();
            glOrtho(0, WIDTH, HEIGHT, 0, -1, 1);//Set the matrix
            glColor4ub(0, 0, 0, 255);     

            glLineWidth(10);

            // quad with lines
            glBegin(GL_LINES);
                glVertex2d(100, 100);
                glVertex2d(200, 100);

                glVertex2d(200, 100);
                glVertex2d(200, 200);

                glVertex2d(200, 200);
                glVertex2d(100, 200);

                glVertex2d(100, 200);
                glVertex2d(100, 100);           
            glEnd();   

            // triangle with lines
            glBegin(GL_LINES);
                glVertex2d(300, 300);
                glVertex2d(400, 400);

                glVertex2d(400, 400);
                glVertex2d(200, 400);

                glVertex2d(200, 400);
                glVertex2d(300, 300);         
            glEnd();

        glPopMatrix();

        SDL_GL_SwapBuffers();
    }

    SDL_Quit();

    return 0;
}.h>


Sponsor:

#2 Brother Bob   Moderators   -  Reputation: 8088

Like
0Likes
Like

Posted 14 January 2013 - 01:54 PM

OpenGL is not meant to handle such high-level concepts as shapes by itself. Even a single basic line, except one pixel thick lines, are quite unspecified and unpredictable, and especially when you need control of the joints. You need a higher-level API to handle the geometry that can control the desired aspects of the geometry you want to draw, such as Cairo, Anti-Grain or FreeType.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS