Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualleagal4ever

Posted 14 January 2013 - 01:15 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>

#1leagal4ever

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.

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 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(800, 600, 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, 600, 400);

	//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, 800, 600, 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;
}

 


PARTNERS