• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Creating point in OpenGL without glVertex

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

2 replies to this topic

### #1Kevn  Members

Posted 13 October 2012 - 05:21 PM

I am doing a homework where I can't use glVertex or gluOrtho to create points on a screen. I am suppose to be using certain algorithms to draw lines, boxes, etc on the screen with points but I can't make a point..lol. Can someone please point me in the right direction? I know I need to use glDrawPixels but how do I set up the pixel buffer that DrawPixels uses? Would I make like a 2D int matrix with a width and height equal to my screen size, then put like a 1 in pixels i want on and 0 in pixels i want off? Also instead of gluOrtho, would I use glRasterPos and glWindowPos?

- Edit: Can someone please move this post to the OpenGL section of the forums if they think it is better off there.

Edited by Kevn, 13 October 2012 - 07:32 PM.

### #2MrDaaark  Members

Posted 13 October 2012 - 08:25 PM

### #3Kevn  Members

Posted 13 October 2012 - 09:01 PM

not sure what that means
Well, I got my program to draw a line one pixel at a time using glDrawPixels. Only it repeats the same line over and over to the right and left of the line I told it to draw. So like if I told it to draw a line from position (100,100) to (600,600). there will be a line there but then another like from (300,100) to (900, 600). and another so many pixels to the right and left in the x direction over.

the code in question, the linebres just uses a line algorithm that calls setPixel however many times needed to draw the line:
struct RGBType {
float r;
float g;
float b;
};
RGBType *pixel_buffer = new RGBType[800 * 1200];
using namespace std;
int window_height = 800;
int window_width = 1200;
void setPixel(int x, int y)
{
pixel_buffer[800*y + x].r=0.5;
pixel_buffer[800*y + x].g=0.5;
pixel_buffer[800*y + x].b=0.5;
}

void display(void) {
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
lineBres(100, 100, 600, 600);
glDrawPixels(window_width, window_height, GL_RGB, GL_FLOAT, pixel_buffer);
glutSwapBuffers();
delete[] pixel_buffer;
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitWindowSize (window_width, window_height);
glutInitWindowPosition (100,100);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutCreateWindow ("Project 1");
glViewport(0, 0, 800, 1200);
glMatrixMode(GL_MODELVIEW);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0, 800.0, 0.0, 1200.0);
glutDisplayFunc(display);
glutMainLoop();

return 0;
}


Edited by Kevn, 13 October 2012 - 09:53 PM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.