cause i see the need for it hehe...
note the sdl headers are not ported 100% nor are they tested 100% so plz send any problems you have in here, but make sure that it's not your fault, thus read the sdl documentation on
http://www.libsdl.org. i'm willing to help but i only got little time and can't check every sourcecode problem there is. thx
If I call SDL_Init, I cant put pixels on a surface... The program either crash, or freeze.
Tested on 640x480 to 1280x1024 (all 32bit), none worked (I only tested the standard ones)
If I use SDL_Init the program crash here:
Code:
cl = screen->pixels + y * screen->pitch + x * len( integer )
*cl = colkey
Although, WITHOUT SDL_Init, it works fine... plots the pixels, screen = SDL_SetVideoMode(xRes, yRes, 32, SDL_HWSURFACE or SDL_FULLSCREEN) Works fine...
System:
AMD Duron
GeForce 2 GTS
If needed I can post driver specs, I downloaded drivers from nVidia less then two weks ago
Works fine for me:
Code:
''
'' SDL pixel ploting example
''
defint a-z
option explicit
'$include: "sdl\sdl.bi"
const SCR_WIDTH = 320*2
const SCR_HEIGHT = 240*2
declare sub doRender (byval screen as SDL_Surface ptr)
dim result as unsigned integer
dim screen as SDL_Surface ptr
result = SDL_Init(SDL_INIT_EVERYTHING)
if result <> 0 then
end 1
end if
screen = SDL_SetVideoMode( SCR_WIDTH, SCR_HEIGHT, 32, SDL_HWSURFACE or SDL_FULLSCREEN ) ''SDL_DOUBLEBUF
if screen = 0 then
SDL_Quit
end 1
end if
do
doRender screen
SDL_Flip screen
SDL_PumpEvents
result = SDL_GetMouseState( byval 0, byval 0 )
loop while result <> 1
SDL_Quit
sub doRender( byval screen as SDL_Surface ptr )
dim buffer as uinteger ptr
dim x as integer, y as integer
dim c as uinteger
dim i as integer
SDL_LockSurface( screen )
for i = 1 to 1000
x = rnd * (SCR_WIDTH-1)
y = rnd * (SCR_HEIGHT-1)
c = rnd * 2^24
buffer = screen->pixels + y * screen->pitch + x * len( integer )
*buffer = c
next i
SDL_UnlockSurface( screen )
end sub
If you access a single pixel outside the surface it will generate an exception. Doing "y = rnd * SCR_HEIGHT will do that, as y can be equal to SCR_HEIGHT, that is one pixel over the max possible coord (that is 0..SCR_HEIGHT-1).
Or then it could be another Win 9x quirk with SDL, if you are running on it.
V3cz0r he was using my pixle plot demo i was having him try it out to test speed. anyways the demo keeped crashing this lead to 2 hours of tracking down why it was crashing on his computer.
it seems like SDL_MapRBG was causing the crash since. Z!re un Remmed my retro fitted RBG combiner that and got it to work.
(oh ya thanks marzectm for showing me how to pass a pointer to a pointer.)
anyways after the Z!re compared some full screen sdl demo code he had to mying and saw that my code had SDL_init being used after remming out SDL_init the SDL_MapRBG worked.
which to me makes zero sence because my demo works fine here my only guss would be that SDL_init is loading somthing up that screawing with his hardware.
defint a-z
option explicit
'$include: "sdl\sdl.bi"
'$include: "gl\gl.bi"
'$include: "gl\glu.bi
declare sub PSET (screen as SDL_Surface ptr , x as integer , y as integer, R as UBYTE , G as UBYTE, B as UBYTE)
dim screen as SDL_Surface ptr
dim a as string
Dim X as integer
Dim Y as integer
Dim C as UBYTE
dim result as unsigned integer
result = SDL_Init(SDL_INIT_EVERYTHING)
if result <> 0 then
SDL_Quit
end 1
end if
screen = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE or SDL_DOUBLEBUF or SDL_FULLSCREEN)
if screen = 0 then
SDL_Quit
end 1
end if
do
SDL_PumpEvents
result = SDL_GetMouseState( byval 0, byval 0 )
if result > 0 then exit do
SDL_LockSurface (screen)
For X = 1 to 640
for Y = 1 to 480
Pset screen ,X,Y,X/C,C*Y+X,5+RND(250)
next
next
c=c+1
if C > 255 then C = 0
SDL_unlocksurface (screen)
SDL_Flip screen
loop
SDL_Quit
end
sub PSET (screen as SDL_Surface ptr , x as integer , y as integer, R as UBYTE , G as UBYTE, B as UBYTE)
dim cl as uinteger ptr
dim colkey as uinteger
colkey = SDL_MapRGB (*screen->format, R, G, B)
'colptr = @colkey : *colptr = B
'colptr = @colkey + 1 : *colptr = G
'colptr = @colkey + 2 : *colptr = R
'colptr = @colkey + 3 : *colptr = A
cl = screen->pixels + y * screen->pitch + x * len( integer )
*cl = colkey
end sub
that's pretty weird, the only fast thing i could think of is that screen->pixelformat is messed up somehow, but that wouldn't make much sense. v1c what about debugsymbols? working already? can i step? well i'll have a look at it now...
some sdl internals: sdl on win32 does nothing more then setting up a directdraw interface iirc, so this is unlikely to crash, cause if the hardware support is not given it falls back to using the gdi, which must work otherwise you could not see those neat windows on the desktop
. /me is debugging
well it somthing to do with SDL_init and SLD_mapRBG.
my older code with my own RBG combiner works fine on Z!re when SDL_init was there.
but when you go SDL_init and SDL_MapRBG Z!re computer crashes. with SDL_init part of the code rem out everything works fine.
so there must be some relationship between the two which is internal with in the lib.
but this problem seem to be only effecting Z!re because it works on my comp fine and couple other people's as well
Correction: Program crash if I try to plot a pixel, and have called SDL_Init
This code crash:
Code:
defint a-z
option explicit
'$include: "sdl\sdl.bi"
'$include: "gl\gl.bi"
'$include: "gl\glu.bi
declare sub PSET (screen as SDL_Surface ptr , x as integer , y as integer, R as UBYTE , G as UBYTE, B as UBYTE, A as UBYTE)
dim screen as SDL_Surface ptr
dim a as string
Dim X as integer
Dim Y as integer
Dim red as integer
Dim green as integer
Dim blue as integer
Dim alpha as integer
Dim T as UBYTE
Dim counter as integer
dim xRes as integer
dim yRes as integer
dim result as integer
const NULL = 0
xRes = 1280
yRes = 1024
result = SDL_Init(SDL_INIT_EVERYTHING)
screen = SDL_SetVideoMode(xRes, yRes, 32, SDL_HWSURFACE or SDL_FULLSCREEN)
if screen = 0 then
SDL_Quit
end 1
end if
do
SDL_LockSurface (screen)
for counter = 0 to 1000
x = (xRes-1) * rnd
y = (yRes-1) * rnd
red = 255 * rnd
green = 255 * rnd
blue = 255 * rnd
alpha=255*rnd
Pset screen ,x,y,red,green,blue,alpha
next
SDL_unlocksurface (screen)
SDL_PumpEvents
loop until SDL_GetMouseState( byval 0, byval 0 )
Do
SDL_PumpEvents
Loop while SDL_GetMouseState( byval 0, byval 0 )
SDL_LockSurface (screen)
for y=500 To 700
for x=900 To 1100
Pset screen ,x,y,128,128,128,50
next
next
SDL_UnLockSurface (screen)
Do
SDL_PumpEvents
Loop until SDL_GetMouseState( byval 0, byval 0 )
SDL_Quit
end
sub PSET (screen as SDL_Surface ptr , x as integer , y as integer, R as UBYTE , G as UBYTE, B as UBYTE, A as UBYTE)
dim cl as uinteger ptr
dim colkey as uinteger
dim Colptr as UBYTE ptr
colptr = @colkey : *colptr = B
colptr = @colkey + 1 : *colptr = G
colptr = @colkey +2 : *colptr = R
colptr = @colkey + 3 : *colptr = A
cl = screen->pixels + y * screen->pitch + x * len( integer )
*cl = colkey
end sub
This does not:
Code:
defint a-z
option explicit
'$include: "sdl\sdl.bi"
'$include: "gl\gl.bi"
'$include: "gl\glu.bi
declare sub PSET (screen as SDL_Surface ptr , x as integer , y as integer, R as UBYTE , G as UBYTE, B as UBYTE, A as UBYTE)
dim screen as SDL_Surface ptr
dim a as string
Dim X as integer
Dim Y as integer
Dim red as integer
Dim green as integer
Dim blue as integer
Dim alpha as integer
Dim T as UBYTE
Dim counter as integer
dim xRes as integer
dim yRes as integer
dim result as integer
const NULL = 0
xRes = 1280
yRes = 1024
screen = SDL_SetVideoMode(xRes, yRes, 32, SDL_HWSURFACE or SDL_FULLSCREEN)
if screen = 0 then
SDL_Quit
end 1
end if
do
SDL_LockSurface (screen)
for counter = 0 to 1000
x = (xRes-1) * rnd
y = (yRes-1) * rnd
red = 255 * rnd
green = 255 * rnd
blue = 255 * rnd
alpha=255*rnd
Pset screen ,x,y,red,green,blue,alpha
next
SDL_unlocksurface (screen)
SDL_PumpEvents
loop until SDL_GetMouseState( byval 0, byval 0 )
Do
SDL_PumpEvents
Loop while SDL_GetMouseState( byval 0, byval 0 )
SDL_LockSurface (screen)
for y=500 To 700
for x=900 To 1100
Pset screen ,x,y,128,128,128,50
next
next
SDL_UnLockSurface (screen)
Do
SDL_PumpEvents
Loop until SDL_GetMouseState( byval 0, byval 0 )
SDL_Quit
end
sub PSET (screen as SDL_Surface ptr , x as integer , y as integer, R as UBYTE , G as UBYTE, B as UBYTE, A as UBYTE)
dim cl as uinteger ptr
dim colkey as uinteger
dim Colptr as UBYTE ptr
colptr = @colkey : *colptr = B
colptr = @colkey + 1 : *colptr = G
colptr = @colkey +2 : *colptr = R
colptr = @colkey + 3 : *colptr = A
cl = screen->pixels + y * screen->pitch + x * len( integer )
*cl = colkey
end sub
And it could be a win98 problem, anyone able to test it?
Like i said, win98, GeForce 2 GTS, AMD Duron, new drivers.. I'm going to dl them again later.. just in case..
Downloald the lastest version:
http://prdownloads.sourceforge.net/fbc/f...p?download
The SDL hearders were updated, there's no more BYREF arguments, to map better the C version. If you must pass a pointer of a structure, use @ or varptr( ) on it (so surface.pixelformat is passed as it should be, surface->pixelformat, no hacks).
First error i saw was, well, you (Shadow) were/are accessing the surface out bounds:
For X = 1 to 640
for Y = 1 to 480
It should be For X = 0 to 640-1 and for Y = 0 to 480-1
One more hint: always declare the function/sub arguments as BYVAL, passing a pointer like surface by reference makes the compiler do 2 dereferences, what isn't need and slows down things (a byref arg is equal an implicity pointer, a ptr passed byref means a pointer to pointer).