C++ :: SDL2 - Getting Pixel Value
Nov 5, 2013
I use SDL2. and i was testing some functions i took from some internet and some unwanted results happened.
Code :
Pixel *GetPixel(SDL_Surface *surface, int x, int y) {
Uint8 p8, *buf8;
Uint16 p16, *buf16;
Uint32 p32, *buf32;
switch(surface->format->BitsPerPixel {
[Code] .....
And the output changes time to time.
View 3 Replies
ADVERTISEMENT
Feb 16, 2015
Im using SDL2 but I'm encountering an unexpected error. I have implemented the same method to move as in my old Projects, but the Player appears to be stuck...
The Player is stuck for maybe half a second, and then everything works as it should, but every time I Change direction or i start moving the Player is stuck for a short Moment.
#ifndef _PLAYER_HPP_
#define _PLAYER_HPP_
#include <iostream>
#include <string>
#include "SDLGameObject.hpp"
class CPlayer : public CSDLGameObject
[code]....
View 9 Replies
View Related
Apr 30, 2014
This is a problem I have been having with every program I write since I started using SDL 2. Whenever I compile my code and run my program, everything works perfectly fine until at some point (usually after 3-8 minutes of running), the program will stop responding completely and I will have to exit out of the console to close it. The code I believe is relevant is:
void MainLoop()
{
InitLoop();
while ( !QuitMain )
[Code].....
If I change SDL_PollEvent(&Event) to SDL_WaitEventTimeout(&Event,100), then the problem goes away (I did that and had the program running for about an hour without it stop responding before I decided that it solved the problem), so I believe that the problem has something to do with event handling. Also, it might be noteworthy to mention that when I use SDL_WaitEventTimeout with the second parameter being a small number (because 100 milliseconds is a long time to wait and makes the program run at like 8 FPS), the problem returns.
View 2 Replies
View Related
Jul 16, 2014
Well if you don't know, there are multiple renderers in sdl, and on some don't work on certain computers, so people use a fallback ex: "accelerated renderer -> software renderer". Sadly, I haven't came across an example that I could copy and paste.
View 16 Replies
View Related
Feb 23, 2014
I am trying to load a .bmp file located in the same folder as main.cpp etc. but I'm not sure what to input as the resource path so that it picks it up and, when I distribute it, I want it to be preferably cross platform and run smoothly.
I have tried using:
hello_world.bmp
SDL_Game/hello_world.bmp (SDL_Game is the name of the project)
but it will work if I use the full path. I don't want to do this though, because then it will not work on other computers and platforms.
This is the function I use to load media:
bool loadMedia() {
// Loading success flag
bool success = true;
// Load splash image
gHelloWorld = SDL_LoadBMP("hello_world.bmp");
[Code] ....
I am using XCode 5, SDL2.0.1, OSX 10.9 Mavericks and C++.
View 2 Replies
View Related
Mar 12, 2014
I am working on image processing in C + + and opencv, I treat images in grayscale, ie the pixel values it must be between 0 (black) to 255 (white).
Mat img; img = imread (file, -1);
for ( int i = 0; i < img. rows ; i ++) {
for ( int j = 0; j < img. cols ; j ++) {
val_pixel=img.at < double >(i,j);
printf( "%d ",val_pixel);
}
printf( "
");
}
when displaying the pixel value from two loop, I get values to 0 and it is normal for propablement black areas, but for whites I find the value -2147483648. I don't understand why this value is not 255.Is there an explanation for this has value.
View 4 Replies
View Related
Apr 17, 2012
I have an image of size 640x480 pixels. It's possible to obtain the dimension in mm of one pixel from that image given only that size?I do not have the size of the image in mm,however.
View 5 Replies
View Related
Jul 26, 2014
How can I find each and every pixel in a circle so that I can do some operations on it.
View 6 Replies
View Related
Mar 27, 2013
How can I import a font file and get the pixel information of the letters so I can make my own custom text drawing function?
I basically have a pixel surface (a 2D array) and I want to draw the text to that array.
View 1 Replies
View Related
Apr 21, 2014
I wrote a script that generates n random pixel positions and draws them to the screen. Works well. Now i tried to rotate them. Rotating does work too. But it does not work as i planned it.
paramters 'angle' and 'timestep' work somehow, but not as they should do. the function 'move' is supposed to rotate the pixelfield 'angle' degrees in a given direction, addicted to the 'timestep' parameter. 'timestep' is needed time for drawing in one single game loop.
angle_step = timestep * angle
// x
ppdPoint[i]->x =
pRotationPoint->x + cos(angel_step) * (ppdPoint[i]->x - pRotationPoint->x) - sin(angel_step) * (ppdPoint[i]->y - pRotationPoint->y);
// y
ppdPoint[i]->y =
pRotationPoint->y + sin(angel_step) * (ppdPoint[i]->x - pRotationPoint->x) + cos(angel_step) * (ppdPoint[i]->y - pRotationPoint->y);
rotation point is the middle of the screen. when i set angle to 10 it should rotate 10 degrees / second. Instead it's rotating very very fast and all stars are moving nearer to the center of the screen, so after x rounds there is just 1 pixel left in the middle of the screen. there is a kind of gravition.I'm working with SDL2. What I did find out:
FPS is <= 60, 'cause of the 'SDL_RENDERER_PRESENTVSYNC' flag. When i skip that flag, for any reason the 'gravition' would take more time. FPS is <= 1400 then, 'though i got a natural game loop (i hope):
while(pBuild->getExecuteFlag())
{
pBuild->draw();
pBuild->update(time_dif, pTimeWindow->TimeStampB);
time_dif = (pTimeWindow->TimeStampB - pTimeWindow->TimeStampA);
time_dif *= 0.001;
pTimeWindow->TimeStampA = pTimeWindow->TimeStampB;
pTimeWindow->TimeStampB = SDL_GetTicks();
pBuild->count_fps(pTimeWindow->TimeStampB);
}
So maybe (timestep * angle) isn't the right way?
View 13 Replies
View Related
Mar 27, 2014
Im new to c#. In c++ I have made a window and painted it with dots and concentric circles, like a radar PPI screen. Trying to do this in c#, I can't find how to draw a single pixel on the window.
Also, what should I be drawing on: the form, panel, picturebox...?
View 2 Replies
View Related
May 23, 2013
How can i convert pixel to [-1..1]coordinate in opengl? Which function? I want to write a program that is work with
glutmousefunc(),
When I click on the screen a ball is appear on it where clicked. but mouse work with pixel and circle work with coordinate between -1 and 1 ....
View 4 Replies
View Related
Dec 30, 2014
I would like to subtract one image from another to get something like "differential picture" (i am not sure whether the name is correct). I've managed to read the FILEHEADER and FILEINFOHEADER of bitmap. I will subtract 24-bit bmp files only. However i can't understand the structure of this file. So far my code looks like this. Any example of at least copying one bmp file to a new one? This example would be useful, because subtracting will be simillar, instead of copying the pixel value i will just put abs(value1-value2) in the output.
Code:
// ConsoleApplication1.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;
struct BITMAPfileHEADER {
[Code] .....
View 4 Replies
View Related
Oct 15, 2013
I have the code and it compiles fine but it doesn't work. (i am using the coding made easy sfml 2.0 tutorials)
Code:
#include <SFML/Graphics.hpp>
#include <iostream>
#include <algorithm>
#include <vector>
class Player {
public:
sf::Sprite player;
[Code] ....
View 18 Replies
View Related
Mar 7, 2013
I am using the SDL library, and came across a way to access pixel data.
//A pointer to a surface structure
SDL_Surface *w = SDL_SetVideoMode(800,400,8,SDL_SWSURFACE);
//Casting a void pointer pointing to an array of memory locations(the pixels), to a pointer to an array of Uint8's.
//SDL_MapRGB() Returns an Uint32 containing the color 0,0,255,(0/255, i think it returns the transparency too, or else it would rather return a Uint24,not sure).
Then modifying the memory location, in this case the pixel at the middle of the window.
static_cast<Uint8*>(w->pixels)[(200*w->pitch)+400]=SDL_MapRGB(w->format,0,0,255);
What i seem to not understand is that, i cast pixels to Uint8*, which means I now have a pointer to an array of 8bit numbers, but SDL_MapRGB seemingly returns an Uint32 or Uint24 for a color composed of r,g,b, together without 'a' is 24bits(256=1b,256=1b,256=1b)=3b.
And then i somehow assign that pixel which is of 8bit at chosen location, an Uint24 or 32bit unsigned int.
How does this work?
View 3 Replies
View Related
Jul 21, 2013
I'm currently working with linear VRAM (a buffer with 256KB memory, divided into four 64k planes, so plane 0 at 0x00000, plane 1 at 0x10000, plane 2 at 0x20000, plane 3 at 0x30000). Just add the index of the plane to that for the full address in VRAM.
I'm still wondering how to get a specific pixel from VRAM (x,y coordinate) when doing graphic modes (none color modes work, only the black/white pixels (1-bit) graphic mode works).
how I can get specific pixels from the VGA VRAM (having linear access described above) using Shift Register Interleave mode (VGA modes 4&5), 16-bit planar mode (Most VGA modes) etc.
View 4 Replies
View Related
Apr 7, 2013
I have tried everything and i still can't access pixel RGB values in float format.
I tried vec3b which produces strange characters which i can't covert to float as it says no suitable function exists.
I tried vector<float> RGB;
with RGB = image.at<vector<float>>(row,col);
I get a unhandled exception error.
So whatever i do, if it is syntax correct i get unhandled exception error. If it should work i get this stupid error. I need it for chroma keying.
View 4 Replies
View Related
Jan 27, 2015
I have a bw(grayscale) image and want to calculate the slope for each pixel which returns a value 0 to 255 value.
Pixels are always between 0 and 255. The highest possible difference is 255. The end result would be 0 for no slope and 256 for the highest slope.
Would this formula work?
slopex = pixel[x+1,y] - pixel[x - 1,y];
slopey = pixel[x,y+1] - pixel[x,y - 1];
totalslope = sqrt(slopex * slopex + slopey * slopey)*256;
View 3 Replies
View Related
Jan 18, 2015
I have managed to successfully extracted the BMP file header and file info but ran into troubles with getting the pixel data out into a 2d array.This is my function to read the data while i have another to write the data. The output does not match the input at all.
void BMPProgram::GetPixelData(std::ifstream & inStream) {
std::cout << "Entered function";
if(inStream.fail())
return;
//space allocated to reading in of padding
int paddingSpace = 0;
[Code] ....
PIXEL is a struct of 3 unsigned char containing values of RGB.
View 3 Replies
View Related
Feb 28, 2014
I'm trying to read a jpeg pixel and then compare it if it'x bigger than a number to change it. Either I'm breaking the folder if I start less than 22000 which is very large number shouldn't include the header or I'm getting solid color without any different.
Code:
const char* filename ="Hydrangeas.JPG";
const char* nfilename ="Hydrangeas1.JPG";
FILE *ptr_old, *ptr_new;
errno_t err = 0, err1 = 0;
int a;
[Code] ....
View 5 Replies
View Related
Nov 25, 2014
In this project I need to develop few functions to work with graphics card. I work in minix and this is pretty rubbish.
I'm having an hard time to read a pixel map, or atleast to print it on my main function.
I have a read_xpm function, which is given, therefore, working.
Code:
char *read_xpm(char *map[], int *wd, int *ht)
Then I have a pixmap.h file which gives some examples of pixmap images that I can use as example:
Code:
static char *pic1[] = {
"32 13 4",
". 0",
"x 2",
"o 14",
"+ 4",
[Code] ....
The doubt is. I have a test_xpm function and I need to call this char array but this is so many pointers that I can't even figure out where I'm pointed to (?)
Code: int test_xpm(unsigned short xi, unsigned short yi, char *xpm[])
I tried something like read_xpm(xi, yi, *xpm[0]); but I'm guessing I need to index that array and run all those chars in order to show them.
View 11 Replies
View Related
Nov 2, 2014
creating a bitmap. Our professor wants us to creat a black 100*100 bitmap.
Code:
#include <stdio.h>
#include <stdlib.h>
#pragma pack(push,2)
typedef struct{
[Code].....
I dont even know where to start. I spend the last 7h infront of my computer and i'm so frustrated cause my professor gave us no information what so ever. At the moment its more of a trial and error process than anything else.
How would i set the color of an individual pixel for examplel or how would i save the file ?
View 1 Replies
View Related
Jan 6, 2015
I need to save RGB values of each pixel in a 3D array A[width][height][3]. I found a code online that transfers the bytes into an array but I cant understand how bytes are saved them so i could transfer them into an array. The truth is I dont know much about working with images at all so i have a problem working on them. How to transfer the RGB data from an .jpeg image into a 3D array? This is my code so far:
#include <iostream>
#include <jerror.h>
#include <jpeglib.h>
using namespace std;
int main(){
FILE *pic = fopen( "image.jpeg", "rb+" );
[Code] .....
View 6 Replies
View Related
Oct 6, 2012
i wish to plot a mathematical function on a 2-dimensional grid. The function will be represented by 3 sets of floats, x-values, y-values, and z-values. Obviously, it is impossible to plot 3 such data sets on a 2D grid, so one approach is to use pixel coloration to represent the z-values.
Those examples (and there are many to be found) show something like the function of the complex variable z, f(z) = exp(z). I have attached a exp(z).jpg example of the imaginary part of the plot exp(z).
My question is: How to accomplish such a gradient colorization, assuming one already has the data?
I have experimented with Gdiplus SetPixel, but I have not figured out how to produce a smooth gradient.
Here's my attempt to create a simple gradient:
Code:
CDC * pDC = GetDC();
Graphics graphics(pDC->m_hDC);
CRect r;
GetWindowRect(&r);
ScreenToClient(&r);
[Code] ....
View 1 Replies
View Related
Mar 13, 2014
I'm trying to blur a ppm image by averaging the components of the color(r, g, b) within a certain reach of a specific pixel. This is a picture and description:
In this diagram, we are trying to compute the color for the pixel in the center (the red element). Its neighbors (within a reach of 4) are all of the green elements. The pixels outside of this 9x9 square are not considered in the blurring calculation for this pixel. To compute the color for the center pixel, average the red, green, and blue components (independently) of every pixel in the 9x9 square (including the pixel itself; the red element in this diagram).
I have some code, but it is not working correctly. The function "computed_color" on line 52 is shown in the next block of code.
Code:
#include <stdlib.h>
#include <stdio.h>
#include "blur_calculations.h"
#define NOT_ENOUGH_ARGS 2
#define MIN_ARGS 3
#define PICTURE_FILE 1
#define REACH_NUMBER 4
#define OUTPUT_FILE "blurred.ppm"
#define PPM_NUMBER "P3"
#define MAX_ROWS 500
#define MAX_COLS 500
void solve(FILE *in_picture, FILE *out_picture, char *argv[]) {
[Code] ....
Here is my code to calculate the average, which I use in my "solve" function:
Code:
#include "blur_calculations.h"
struct color create_color(int r, int g, int b) {
struct color colors;
colors.r = r;
colors.g = g;
colors.b = b;
return colors;
[Code] ....
View 4 Replies
View Related