Sign in to follow this  
meselfs

Accessing the pixles: A simple problem made complicated?

Recommended Posts

Hi, I've been feeding off of NeHe's gl tutorials for about 2 years now, and I've noticed something rather interesting: I'm stuck in 2D. I just don't care for 3D, and I don't think I ever will. Each 2d app I write gest more and more basic, I've recently begun working with just the raster stuff, eg glDrawPixels. I'm thinking: what is the lowest level method to access the pixels in a window? Suppose I don't care for DrawLine finctions or anything like that, I just want to set the colors in a bitmap array and draw that array to a window (or fullscreen). What's the lowest level (in C, mind you, not ASM) way to do that? I want no APIs or anything like that, just the ability to push pixels. I've been trying WinGDI, and it already seems better for me, but I want to go even lower. I don't truest WinGDI, all those structures & pens & brushes and stuff seem stupid too me. Any advice?

Share this post


Link to post
Share on other sites
Problem is, cards work at the vertex and texture level. A solution might be altering the pixels of a texture and then rendering it to a quad.
Why is win32 programming not ok? I've seen good fast 2d games purely written in win32 api. Another solution might be : buying an old graphic card and returning to DOS.

Share this post


Link to post
Share on other sites
I wrote something similar when i did a raytracer a while ago.

The viewport was set up like this.
glOrtho(0.0f,width,height,0.0f,-1.0f,1.0f); // Create Ortho 640x480 View (0,0 At Top Left)


float image[640][480][3];


void putPixel(int x,int y, float s, float r, float g,float b)
{
glPointSize(s);
glBegin( GL_POINTS);
glColor3f(r,g,b);
glVertex2i(x,y);
glEnd();

}


void render(HDC hDC,float rotate)
{

int i,j;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix

i=0;
j=0;

while(i<480){
while(j<640){
putPixel(j,i,1,image[j][i][0],image[j][i][1],image[j][i][2]);
j++;
}
j=0;
i++;
}


glFlush();
SwapBuffers( hDC );

}


the speed is not something i paid close attention to, but it works and you have full access to both reading and writing into the image.
But drawing textured triangles in a 2d space could prove to be easier, faster and look better.

Share this post


Link to post
Share on other sites
lc_overlord, I've tried that already and I think it's much too slow.

Ok, it's become obvious to me that some sort of direct access is impossible, or at least incompatible. I've turned my attnetion to DDraw, it seems to contain the most efficient method for putting pixels on the screen. Unfortunatley, the coding is alot more complicated then OGL, and it works poorly windowed. Oh well...

Thanks anyways, folks.

Share this post


Link to post
Share on other sites
Quote:
Original post by meselfs
lc_overlord, I've tried that already and I think it's much too slow.

Ok, it's become obvious to me that some sort of direct access is impossible, or at least incompatible. I've turned my attnetion to DDraw, it seems to contain the most efficient method for putting pixels on the screen. Unfortunatley, the coding is alot more complicated then OGL, and it works poorly windowed. Oh well...

Thanks anyways, folks.


I know it's slow, but it works ok if you use it for displaying the renderd result of an raytracer.

Open gl does provide good ways of doing good ultrafast 2d, but you do have to adapt your code to fit this.
Direct fragment access is sort of semi posible, but it's generaly really slow because of how the framebuffer is hardwired inside the graphics card, not to mention that you probobly will end up stalling the gpu way to many times.
There are ways around this though, if you use the blob of gray matter in your head you might find ways of doing the same, but in another way.

Share this post


Link to post
Share on other sites
There's a grey squishy thing in my head? ACK!!!

The problem is that I'm not much of a programmer... only recently have I begun understanding, for example, how NeHe's fantastic CreateGLWindow function works.

My grey sqiushy thing is better at some other stuff...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this