Can't Plot Pixels using the PR_SURFACE Functions

Started by
2 comments, last by Sovereign 22 years, 6 months ago
Ok what I am trying to do is plot pixels directly to the Video memory using the PR_SURFACE Functions. For some reason I can't get any pixel(s) to display on my screen. Heres what I have set up so far: I declare my varibles as this: PR_SURFACE mysurface; PR_DWORD pitch = 0; PR_UCHAR *surface_bits; //I allocate my surface here mysurface = PR_AllocateSurface (640, 480, D3DFMT_R8G8B8); /* main program loop */ while (!kbdon[KEY_ESC]) { UpdateMessages (); PR_OpenScreen (PR_BACKBUFFER); PR_NewFrame (); /* Begin a new frame */ PRGFX_SetColor (BLACK); PRGFX_ClearScreen (); /* Clear the last frame */ PR_TransformLights (&userlights); move_count = PR_GetTicks (); PR_RotateEntity (entity, //0.1f, 1.2f, 0.3f); 0.1f * move_count, 1.2f * move_count, 0.3f * move_count); PR_TransformEntity (entity); //PR_RenderEntity (entity); //Start drawing points //Returns Address of start of Video Memory after surface locked surface_bits = (PR_UCHAR *) PR_LockSurface (mysurface, &pitch); if (surface_bits == NULL) return; //Start drawing points for(i = 0; i < 1000; i++) { x = rand() % 640; y = rand() % 480; surface_bits[x + y*pitch] = PRGFX_MakeColor(255,255,255); } PR_UnlockSurface (mysurface); PR_RenderFrame (); /* Draw the scene */ PR_Flip (1); /* Show the background page */ } I wonder what I am doing wrong. Chris or anyone no what I am doing wrong. Thanks Doug Edited by - sovereign on October 15, 2001 12:18:47 AM
Advertisement
Where do you draw the surface? You write some stuff to it but don''t do anything with it afterwards.

Also if surface_bits is a PR_UCHAR *, you shouldn''t be writing dwords into the pointer. You''ll have to write the R,G,B values individually since the pixel format is 24 bit.

Chris





Author of Power Render (http:/www.powerrender.com)
Author of Power Render (http:/www.powerrender.com)

"Where do you draw the surface?"
I''m using this to write to the surface since this is supposed be the address for the video after the Surface is locked
surface_bits[x + y*pitch] = PRGFX_MakeColor(255,255,255) or what ever value I need to write based on some format;

"You write some stuff to it but don''t do anything with it afterwards."

So what else do I need to do to make this work? Am I missing a step?

All I want to do is Plot some pixels much like the
PRGFX_Line , but is inefficient because of excessive locking and unlocking of the surface just to draw one pixel.

So I figure it is alot faster to lock the surface then plot a bunch of pixels and unlock the surface after I am done. I figure this would be a lot quicker than the PRGFX functions.

You did suggest that I look into using the DrawPrimitive function using Point list but I am not to knowlegable with Direct 3D stuff so bear with me. I did read the DX8 Doc trying to understand this stuff but I am sort of winging it.

I did a search on my hardrive for examples of you using the PR_Surface Functions and found some files that you use these functions in. My program was sort of based on what I saw in seting up the varibles and functions. I am not sure what the correct D3DFORMAT just to plot piexls using the red, green, blue values in the range of 0 to 255.

Is there any way you can provide a working example such as ploting pixels to video memory?

Doug
If you want to show the pixels you plotted:

1) Copy the surface to the back buffer (will overwrite what is there already)
OR
2) Use the surface of a texture and draw that as an overlay
OR
3) Lock the back buffer after drawing

It sound like you want #3. Instead of making a new surface, lock the back buffer and write pixels. You''ll need to write pixels in the appropriate format (16/32 bit, byte order, etc).

I''ll see if I can get an example made up, but I don''t know when because I''m pretty busy for the release of PR4 this week.





Author of Power Render (http:/www.powerrender.com)
Author of Power Render (http:/www.powerrender.com)

This topic is closed to new replies.

Advertisement