I want graphic a point in c++ with SDL, I want to draw a pixel, what is my error? the window does not draw anything because?
I only want to use SDL for the creation of the window and the drawing of the putpixel, the line, the circumference and I will create it with the bresemham algorithm
I need the Point class to have its own class
#include "SDL.h"
#include <iostream>
#include "Point.h"
using namespace std;
int main(int argc, char* argv[])
{
if (SDL_Init(SDL_INIT_VIDEO) == 0) {
SDL_Window* window = NULL;
Point point (100,100);//100 100 default values
SDL_Renderer* renderer = point.getRender();
if (SDL_CreateWindowAndRenderer(640, 480, 0, &window, &renderer) == 0) {
SDL_bool done = SDL_FALSE;
SDL_CreateRenderer(window,0,1);
while (!done) {
SDL_Event event;
SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
SDL_RenderClear(renderer);
SDL_SetRenderDrawColor(renderer, 255, 255, 255, SDL_ALPHA_OPAQUE);
SDL_RenderDrawLine(renderer, 320, 200, 300, 240);
point.putPixel(20,30);
SDL_RenderPresent(renderer);
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
done = SDL_TRUE;
}
}
}
}
if (renderer) {
SDL_DestroyRenderer(renderer);
}
if (window) {
SDL_DestroyWindow(window);
}
}
SDL_Quit();
return 0;
}
and file .cpp
#include "Point.h"
#include "SDL.h"
Point::Point(int x, int y): point(x) {
}
SDL_Renderer* renderer = NULL;
void Point::putPixel(int x,int y){
SDL_SetRenderDrawColor(renderer, 100, 100, 100, SDL_ALPHA_OPAQUE);
SDL_RenderDrawPoint(renderer, x, y);
}
SDL_Renderer* Point::getRender(){
return renderer;
}
and file .h
#include "SDL.h"
class Point
{
private:
int point;
public:
Point(int x,int y);
void putPixel(int x, int y);
SDL_Renderer* getRender();
};
the window shows blank.
Comments
Post a Comment