Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

122 Neutral

About carleton

  • Rank
  1. I am having a strange problem. I am developing the application with Qt, so I am using their container, but I am drawing the image with standard OpenGL function, glDrawPixels. Depending on the size of the window, sometimes there is a horizontal line through the image. At first I though it might be my logic in generating the image, but when I changed the background color, the line changed colors, too. I am guessing that I am not setting up the glDrawPixels() correct which is why it skips a line sometimes. Initially I thought the problem might be that I was rounding thing off to integers, but I have rectified that so that everything uses floats, but the problem persists. Here is what I am doing: // Setting the zoom factor glPixelZoom( zoomFactor, zoomFactor); // Set the coord of where to start drawing the image on the screen glRasterPos2f( screenViewRect.x(), screenViewRect.y()); // ??Tell OpenGL how wide the view port is on the screen?? glPixelStoref(GL_UNPACK_SKIP_PIXELS, imgViewRect.x()); // ??Tell OpenGL how tall the view port is on the screen?? glPixelStoref(GL_UNPACK_SKIP_ROWS, imgViewRect.y()); // ??Set the scan line length of the original image?? glPixelStorei(GL_UNPACK_ROW_LENGTH, pDisplayImage->width()); // Draw the image glDrawPixels(imgViewRect.width(), imgViewRect.height(), GL_RGB, GL_UNSIGNED_BYTE, pDisplayImage->GetImagePtrConst()); Is my understanding of the process to drawing the image correct? Carleton
  2. carleton

    Positioning display lists in 2D

    I tweaked some things and it started working. I don't really know what the fix was, but I am good!
  3. I am still trying to figure out all the coordinate system in OpenGL. From everything else I am doing, I believe I have the corrdinate system setup to simply be each unit is one pixel: glViewport(0, 0, (GLint)width, (GLint)height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0, (GLdouble) width, 0.0, (GLdouble) height); glMatrixMode(GL_MODELVIEW); What I am trying to do is create a display list that is a circle and then use the display list to draw it in two different locations. Here is the code to create the display circle: GLfloat increments = (PI*2) / 360; glNewList(circleId, GL_COMPILE); glBegin(GL_LINE_LOOP); for(float i = 0; i < PI*2; i += increments) { GLfloat x = radius * sin(i); GLfloat y = radius * cos(i); glVertex3f( x, y, 1.0f); } glEnd(); glEndList(); And then here is the code I am trying to use to actually draw it: glLoadIdentity(); glColor3f(...); glTranslated( xmid, ymid, 0); glCallList(openGLListMgr().circleId()); glTranslated( 0, 0, 0); But no circle is showing up. What am I doing wrong? Carleton
  4. carleton

    Learning the basics of 2D OpenGL

    I understand your logic. I guess I did not ask the right question originally and I did not provide enough detail;) What happens is this: As the mouse moves over the images, a new image is computed and displayed. I have spent the last month on this project figuring out how to improve the computation code as to improve the "frame rate" of how many images can be computed and displayed a second. Now I am wondering if I can tweak it even further with some OpenGL optimization. Right now I am clearing the whole screen before drawing the images which cover most of the screen. It seems a little silly to me to clear the whole screen before covering it with the new images. I do have the 5th edition of "OpenGL Programming Guild" and I am simply trying to make the "model" I have developed fit into OpenGL. Basically what I have is this: Screen --> The complete OpenGL screen area Canvas --> the screen is divided up into equal parts called canvas that both the cirle and the image is drawn on View --> the view is the area within the canvas to display the image with the correct aspect ratio. My whole though is that I can leverage the whole concept of the Stencil Buffer or maybe the Mask Buffer as to only need to update the my "View" as the mouse moves over the images and to only repaint the whole screen on a resize or when the user toggles the circle on and off. I am just trying to figure out the correct OpenGL way to do this. Right now, before drawing the images I am always doing the following: // The beginning painting glClear(GL_DEPTH_BUFFER_BIT); glRasterPos2i(0, 0); glClearColor(...); glClear(GL_COLOR_BUFFER_BIT); // drawing of each the image: glPixelZoom( zoomFactor, zoomFactor); glRasterPos2i( x, y); glDrawPixels(width, height, GL_RGB, GL_UNSIGNED_BYTE, pImage); Is there something I can do so that I don't need to do all the beginning painting clears? Carleton
  5. I am working on a project that is using OpenGL to draw 2D images. OpenGL is being used because of speed issues. I have looked at ALL other alteratives and OpenGL is the only viable one (maybe DirectX, but I am not going to go there). Now I need to really get my teeth into some basics of OpenGL 2D drawing. What I need to learn more about is layers (I believe they are called slices in OpenGL) and creating objects... What the application is doing specifically is this: One or more images are drawn on the screen. In one mode there is a circle overlayed each image. When in this mode, the image can change. What I am doing now is treating each paint (of the new image) as a complete repaint of the whole screen. I am under the impression that there is a way I can simply update the image without clearing the background again and redrawing the circle. I am also under the impression that there is a way I can simply turn off a layer to make the circle go away. What sources would folks recommend I look to as to learn more of these basic concepts? Carleton
  6. Ok, I have totally chunked the old cropping code and doing it myself. I am stumped on how to do the math... The cropping tool is locked to the aspect ratio of the original image. Considering there is already "zooming" going on to display the whole image, the values being given to the OpenGL code to display the crop is percentages from the left/bottom. Image: 3200x2400 Display: 1600x1200 full image zoom factor of .5 (fiZF) crop marks: {200,150} to { 1400, 1050} (screen relative) So the percentages are: { 12.5%, 12.5%} to {87.5%, 87.5%} With that, I find the percentage of the image that will be visible ( 85.5% - 12.5%) and get 75%. To get the actual zoom factor I divided the full image zoom factor by the visible percentage: .5 / 75% = 66.7% (.667) And to calculate the offset's I simply take the first crop mark points percentage and multiply them by the image size: - (12.5% * 3200) = -400 = xpan - (12.5% * 2400) = -300 = ypan And it does not work, I get a black box! What am I doing wrong? Carleton
  7. I am having problems understanding how the other developer was calculating the offset and I figured that I should first make sure I understand exactly how the coordinate system works;) Here is an example of what I simply don't understand. Right now the viewing window can be of a different dimensions then the image, so the first thing determined the smaller zoom factor. Lets say we have this: xZF of .65 yZF of .67 so the min ZF is .65 Then the code has this: float ypan = 0.5 - 0.5/( zoom_factor / yZF); I know that the ypan is on a scale of 0 to 1, 0 being bottom and 1 being top, but I simply don't understand what is going on here. Later we have this: float desiredypan = - ypan * zoom_factor * imageHeight; This looks to me like he is simply converting the 0 to 1 into the correct scale based on the zoom factor. It all works fine, the problem comes in when I try to make the code zoom to a specific crop zone, it is always off. I figure the problem is, I don't understand what the initial developer was doing so my code isn't working.
  8. I am working on a program that someone else wrote initially. It displays an image on the screen. Often the image is much larger then the screen so the image needs to be zoomed out. There are times when only a piece of the image should be displayed so the image is zoomed in to some degree. For the sake of discussion, lets assume that the original image is 3200x2400 and the screen size is 1600x1200. It is my understanding that I would set the x & y zoom factor to .5 and set the raster position to {0, 0} to display the whole image (full screen). With a x/y zoom factor of 1 and the raster position to {0, 0}, then the lower left quadrant of the image would be displayed. To see the center at full resolution (zoom factor of 1), is the correct raster position {-800, -600}? If so, with a zoom factor of .75, the raster position should be set to {-400, -300}, correct? Carleton
  9. Thank you. I switch to using the glVertex3f() and setting the z to 1 and now the circle is on top, but... When I change the flag to stop drawing the circle, there is still a circle cut out of the image. I have a feeling that I need to clear the scissor buffer or something to eliminate the circle. How is that done? Carleton
  10. I would like to prefix this by saying I don't know a great deal about OpenGL programming. But I am neck deep in it, so I must move forward;) I am working on an application that draws images on the screen. Two to be exact. They live side by side so the user can do a comparison. I need to draw a circle on top of both images. When I draw that circle (either before or after the glDrawPixels() to draw the images), the circle always shows up behind the image. I can see only part of the circle, the part that is being drawn outside of the images. Before calling the code to display the image or the circle: CRect rect; GetClientRect(rect); glViewport( 0, 0, rect.Width(), rect.Height()); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0, (GLdouble) rect.Width(), 0.0, (GLdouble) rect.Height()); glMatrixMode(GL_MODELVIEW); glRasterPos2i(0, 0); glClearColor(0.5, 0.5, 0.5, 1.0); glClear(GL_COLOR_BUFFER_BIT); When I am displaying the image I am doing this, basically: glPixelTransferf(GL_RED_SCALE, 1.0); glPixelTransferf(GL_GREEN_SCALE, 1.0); glPixelTransferf(GL_BLUE_SCALE, 1.0); glDisable(GL_BLEND); glRasterPos2i(xOffset, 2); glDrawPixels(x, y, GL_RGB, GL_UNSIGNED_BYTE, image); And this is how I am drawing the circle: glBegin(GL_LINE_LOOP); for(float i = 0; i < PI*2; i += increments) { x = radius * sin(i) + xmid; y = radius * cos(i) + ymid; glVertex2f( x, y); } glEnd(); Carleton
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!