• Advertisement
Sign in to follow this  

Creating point in OpenGL without glVertex

This topic is 1925 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post

Link to post
Share on other sites
[sup]not sure what that means sad.png [/sup]
[sup]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.[/sup]

[sup]the code in question, the linebres just uses a line algorithm that calls setPixel however many times needed to draw the line: [/sup]
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);
lineBres(100, 100, 600, 600);
glDrawPixels(window_width, window_height, GL_RGB, GL_FLOAT, pixel_buffer);
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);
glLoadIdentity( );
glLoadIdentity( );
gluOrtho2D(0.0, 800.0, 0.0, 1200.0);

return 0;
[/sup] Edited by Kevn

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement