Jump to content

  • Log In with Google      Sign In   
  • Create Account


DarkHorseKnight

Member Since 11 Jul 2011
Offline Last Active Nov 20 2012 11:34 AM

Topics I've Started

Left over garbage pixels from copying a pixel value to new location? C/SDL

31 October 2012 - 06:48 PM

Hi all I'm able to draw pixels in many ways and get pixel values and place them somewhere on the screen surface but when It happens the left over pixel is still there and I was hoping someone could show me code and explain how to remove it from the screen surface here is my code to draw and to get pixels :

#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <math.h>
#undef main
int y = 10;
int x = 10;
int x2 = 40;
int y2 = 40;
SDL_Surface *Screen = SDL_SetVideoMode(640,480,32,SDL_SWSURFACE),
*Image;
void pixeldraw(int x, int y , int color)
{
  unsigned int *ptr = static_cast <unsigned int *> (Screen->pixels);
  int offset = y * (Screen->pitch / sizeof(unsigned int));
  ptr[offset + x] = color;
}

unsigned int pixelget(int x, int y)
    {
  unsigned int *ptr = static_cast <unsigned int *> (Screen->pixels);
  int offset = y * (Screen->pitch / sizeof(unsigned int));
  return ptr[offset + x];
    }

int main(int argc , char *argv[])
{

SDL_WM_SetCaption("Image Pixel Manipulation", "PM");

Image = IMG_Load("image.png");


//unsigned int *src0 = (unsigned int *) Image->pixels + y * //Image->pitch;


SDL_FillRect(Screen,NULL,(0,0,0));

pixeldraw(10, 10, 0x0000FF);
   
 
unsigned int color = pixelget(10, 10);
   
pixeldraw(x2,y2, color);
	  
printf("%08x\n", color);

 
    //unsigned int *pixels = (unsigned int*) Screen->pixels;
	  
	   //unsigned int color = pixels[y * (Screen->pitch / /sizeof(unsigned int)) + x];
	  
	   // pixels[y2 * (Screen->pitch / sizeof(unsigned int) + x2] = color;

//src0[1] = 0;

bool done = false;

SDL_Event event;

while(!done)
{
  //SDL_BlitSurface(Image,NULL,Screen,NULL);

  while(SDL_PollEvent(&event))
  {
 
    switch(event.type)
    {
   
	  case SDL_QUIT:
	  return 0;
	  break;
   
    }
 
  }
 
  SDL_Flip(Screen);
}

return 0;
}





any tips and suggestions are also welcome although this was intended as a test case not a perfect example of coding grammatically and correctly per-say of my ability.

Thanks for anyone who reads this :D.

How to multiply Pixels on a PNG Loaded SDL Surface?

05 October 2012 - 07:30 PM

Hi!

I was hoping someone could tell me what is required to multiply the pixels on an PNG Loaded Surface

"What I mean is zoom the png file so its bigger then its orginal PNG Loaded size on a SDL Surface"

I'm able to manipulate just normal pixels and put them on the screen and make gradient rectangles with them

but I really don't understand how to do the multiplication on the PNG loaded Surface pixels

my thought was too :

get the surface->pixels member and then get the width and height store them all in separate variables then multiply them then load them back into surface->pixels member if that's even possible am I correct?
probably wrong ;/


any solutions? ;/

#include <SDL/SDL.h>
#include <SDL/SDL_Image.h>
#include <iostream>
#include <math.h>
#undef main

using namespace std;

SDL_Surface *Screen = SDL_SetVideoMode(640,480,32,SDL_SWSURFACE);
void pixeltest(int x, int y , int color)
{
unsigned int *poo = static_cast <unsigned int *> (Screen->pixels);
int offset = y * (Screen->pitch / sizeof(unsigned int));

for(x = 0; x <= 1000; x++)
poo[offset + x] = color;
}
int main(int argc, char *argv[])
{
SDL_Surface *PNG , *Imagetest;

SDL_Color WhiteColor={255,255,255};

PNG = IMG_Load("ChocoLeft1.png");
Uint8* keystate;

keystate = SDL_GetKeyState(NULL);
//SDL_LockSurface(PNG);
int pngy = 0;
int pngx = 0;
int pngcolor = 0;

unsigned int *pngptr = static_cast <unsigned int *> (PNG->pixels);
int pngoffset = pngy * (PNG->pitch / sizeof(unsigned int));
bool done = false;

SDL_Event event;

keystate = SDL_GetKeyState(0);
while(!done)
{
  SDL_FillRect(Screen,NULL,0xffff26);

  SDL_BlitSurface(PNG,NULL,Screen,NULL);

  for(pngx = 0; pngx <= 100; pngx++)
  pngptr[pngoffset + pngx] = pngcolor;
  
  while(SDL_PollEvent(&event))
  {
   switch(event.type)
   {
	case SDL_QUIT:
	return 0;
	break;
  
   }

  }

  SDL_Flip(Screen);

}
}

Cairo/SDL Z-Ordering Problem ;/

29 September 2012 - 10:09 AM

Hello I'm trying to set my zooming Cairo surface to a different z order then the SDL surface so that the Cairo surface is infront of the SDL surface but its not working.

My guess was just to switch the order of both the Cairo surface and SDL surface but no luck ;/

 if(ZOrderSwitch == false)
  {
   cout << " Z Order Set to False" << endl;
  
   ChocoFrontStorageRect = ChocoFrontRect;
   cairo_paint(Fences);
   cairo_surface_flush(FenceSurf);
   SDL_BlitSurface(CGTextSurf,NULL,Screen,&CrazyRect);
   SDL_BlitSurface(ChocoFrontSurf[ChocoFrontFrameTimer],NULL,Screen,&ChocoFrontStorageRect);
   cairo_surface_mark_dirty(FenceSurf);
  
  }
  else
  {
 
   cout << "Z Order Set to True" << endl;
 
   ChocoFrontStorageRect = ChocoFrontRect;
   cairo_surface_flush(FenceSurf);
   SDL_BlitSurface(CGTextSurf,NULL,Screen,&CrazyRect);
   SDL_BlitSurface(ChocoFrontSurf[ChocoFrontFrameTimer],NULL,Screen,&ChocoFrontStorageRect);
   cairo_surface_mark_dirty(FenceSurf);
  
 
   cairo_paint(Fences);
  }


  if(FenceRect.x <= 40)
  {
   ZOrderSwitch = true;
  }

Cairo & SDL Include / Lib problems ;/

22 September 2012 - 06:08 PM

Hello just ran into a problem I don't understand why it is happening?

I'm trying to use cairo with sdl obviously but having issues with the functions that I'm so posed to use mainly because the header / cpp file naming "cairosdl.h" and "cairosdl.c" are full of errors when included in my main.cpp file so I was hoping someone could tell me what these errors mean to help in my quest of fixing this problem thank you ! I don't really understand them.

here is a pastebin too the cmd shell error outputs -> http://pastebin.com/vEuJNfYs

and here are the functions I used below

cairo_surface_t *cairosurf = cairo_image_surface_create_for_data (
static_cast<unsigned char *>(sdlsurf->pixels),
CAIRO_FORMAT_RGB24,
sdlsurf->w,
sdlsurf->h,
sdlsurf->pitch);

cairo_t *cr = cairosdl_create(sdlsurf);

cairo_set_source_rgba(cr, 1,1,0,0.5);

cairo_rectangle(cr, 25,25,50,50);
cairo_fill(cr);

cairosdl_destroy(cr);

cairo_select_font_face (cr, "serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
cairo_set_font_size (cr, 32.0);
cairo_set_source_rgb (cr, 0.0, 0.0, 1.0);
cairo_move_to (cr, 10.0, 50.0);
cairo_show_text(cr,"Hello, world");

finding information on DirectX 10 is Difficult...?

17 September 2012 - 01:47 PM

Hello I've been programming for almost 3 years and having troubles finding simple and basic information on DirectX 10 for example a simple basic directx 10 window?

I've looked around on Google with results that show me what I don't want to see... like I've never used Classes before in my games I've programmed and having to deciper through someones uses of classes is very agitating.

I looked at the SDK examples and found usefull stuff but no nice descriptions and it would just be nicer if someone had a site or some kind of book that explained how to setup and use DirectX 10 with mingw32 I'm having issues with the makefile setup process includes/lib folders for some reason when I shouldn't be...???


Makefile
all: 3DGameProgramming
3DGameProgramming: main.cpp
mingw32-g++ main.cpp -o 3DGP -lmingw32 -lwinmm -ld3d9 -mwindows -I"C:\\Program Files\\Microsoft DirectX SDK (June 2010)\\Include" -L"C:\\Program Files\\Microsoft DirectX SDK (June 2010)\\Lib"
# this is optional, but it's nice
.PHONY: all


like in SDL you can find a basic SDL window example..

so if anyone knows anything about DirectX 10 and Mingw32 setups or knows where to find simple basic information on DirectX 10 let me know thank you ! ;]

PARTNERS